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

the alarm doesn't work properly, The number of times a request call is made, the number of times an alarm is call , it should be calls one time every 2 seconds #43

Open
harshil-bodara opened this issue Oct 12, 2023 · 0 comments

Comments

@harshil-bodara
Copy link

I am facing an issue with the alarm

  • when we call the schedule first time, it works fine every 2 seconds
  • when we call the schedule a second time it calls 2 times every 2 seconds
  • when we call the schedule a third time it is calling 3 times every 2 second
  • continue

every time, it should call at one time every 2 seconds

export class Schedule {
id: string | DurableObjectId;
storage: DurableObjectStorage;
doEverySeconds: number;
env: Env;

constructor(state: DurableObjectState, env: Env) {
	this.storage = state.storage;
	this.id = state.id;
	this.doEverySeconds = 2;
	this.env = env;
}

async fetch() {
	this.scheduleAlarm();
	return new Response("schedule Successfully!");
}

async alarm() {
	console.log("Schedule Alaram Doing");
	this.scheduleAlarm();
}

async scheduleAlarm() {
	let scheduledTime: number = Date.now();
	scheduledTime += this.doEverySeconds * 1000;
	this.storage.setAlarm(scheduledTime);
}

}

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