Harshil Bodara
Harshil Bodara
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
yes, i got it
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
Thank you So much! @omar
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
Thank you, @omar , It was a very exciting good solution now schedule is working fine
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
yes, let me know
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
No description
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
for example:- first-time call schedule: alarm calling 2s: alarm calling 4s: alarm calling 6s: alarm calling when I recall the API, it is already scheduled already doing 8s: alarm calling 10s: alarm calling continue OR first time call schudle: alarm calling 2s: alarm calling 4s: alarm calling 6s: alarm calling
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
main.ts -------------------------- import { ThrowableRouter } from 'itty-router-extras'; import { Env } from '../types'; import { withDurables } from 'itty-durable'; export { Water } from './crons/water'; const router = ThrowableRouter(); router.all("", withDurables()); router.get('/water', async (request: Request, env: Env) => { const doId = env.WATER.newUniqueId(); const WaterInstance = env.WATER.get(doId); return WaterInstance.fetch(request, env); }); router.all("", ()=> { return new Response("Route not Found!") }); export default { fetch: router.handle, }; crons/water/index.ts --------------------------------- export class Water { 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() { const alarmTime = await this.storage.get("alarmTime"); console.log("alarmTime",alarmTime) if (!alarmTime) { await this.scheduleAlarm(); } else { return new Response("Water alarm is already scheduled."); } return new Response("Water schedule Successfully!"); } async alarm() { console.log("Water Alarm Doing"); await this.storage.delete("alarmTime"); } async scheduleAlarm() { let scheduledTime: number = Date.now() + this.doEverySeconds * 1000; await this.storage.put("alarmTime", scheduledTime.toString()); this.storage.setAlarm(scheduledTime); } }
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
but I want to when re-calling the schedule so before, schedule is clear(restart) and then the alarm calling
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
yes, like this
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
not every 2 secondse
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
No description
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
No description
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
for exmaple alaram calling First time call = schudle call every 2 second (working fine) second time call = 2 time schudle call every 2 second third time call = 3 time schudle call every 2 second but i want to do ------------------------------------- First time call = schudle call every 2 second (working fine) second time call = 1 time schudle call every 2 second third time call = 1 time schudle call every 2 second
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
yes, exactly
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
No description
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
export class Water { 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() { const alarmTime = await this.storage.get("alarmTime"); console.log("alarmTime",alarmTime) if (!alarmTime) { await this.scheduleAlarm(); } else { return new Response("Water alarm is already scheduled."); } return new Response("Water schedule Successfully!"); }
async alarm() { console.log("Water Alarm Doing"); await this.scheduleAlarm(); }
async scheduleAlarm() { let scheduledTime: number = Date.now() + this.doEverySeconds * 1000; await this.storage.put("alarmTime", scheduledTime.toString()); this.storage.setAlarm(scheduledTime); } }
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
But whenever I call the schedule, I want to call the alarm only once
41 replies
CDCloudflare Developers
Created by Harshil Bodara on 10/27/2023 in #durable-objects
@omar#4289 same as, I am getting the
the first time, it is working correctly, when re-call the water Schedule a second time does the calling schedule 2 times every 2 seconds, same as the next
41 replies