Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alarms to feed stats #35

Open
whoabuddy opened this issue Dec 19, 2024 · 0 comments
Open

Use alarms to feed stats #35

whoabuddy opened this issue Dec 19, 2024 · 0 comments

Comments

@whoabuddy
Copy link
Contributor

whoabuddy commented Dec 19, 2024

We can have alarms that run on an interval and update internal application stats.

Example alarm:

async alarm(): Promise<void> {
  try {
    console.log(`ContextDO: alarm activated`);
  } catch (error) {
    console.error(`ContextDO: alarm execution failed: ${error instanceof Error ? error.message : tring(error)}`);
  } finally {
    // Always schedule next alarm if one isn't set
    const currentAlarm = await this.ctx.storage.getAlarm();
    if (currentAlarm === null) {
      this.ctx.storage.setAlarm(Date.now() + this.ALARM_INTERVAL_MS);
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant