Select the types of activity you want to include in your feed.
flora is a fast and secure runtime that lets you write discord bots for your servers, with a rich TypeScript SDK, without worrying about running infrastructure. [mirror]
···539539 for (_gid, jobs) in reg.jobs.iter_mut() {
540540 for job in jobs.iter_mut() {
541541 if job.next_run <= now {
542542+ if job.skip_if_running && job.is_running {
543543+ info!(target: "flora:runtime", worker_id, name = job.name, "skipping cron job (still running)");
544544+ if let Ok(next) = job.schedule.find_next_occurrence(&now, false) {
545545+ job.next_run = next;
546546+ }
547547+ continue;
548548+ }
549549+ job.is_running = true;
542550 due_jobs.push((
543551 job.guild_id.clone(),
544552 job.event_name.clone(),
···564572 };
565573566574 let Some(runtime) = runtime else {
575575+ mark_cron_not_running(cron_registry, &guild_id, &cron_name);
567576 continue;
568577 };
569578570579 let result =
571580 dispatch_cron_into_runtime(runtime, event_name.clone(), payload, worker_id, limits)
572581 .await;
582582+583583+ mark_cron_not_running(cron_registry, &guild_id, &cron_name);
584584+573585 if let Err(ref err) = result {
574586 error!(target: "flora:runtime", worker_id, ?guild_id, cron_name, ?err, "cron dispatch failed");
587587+ }
588588+ }
589589+}
590590+591591+fn mark_cron_not_running(
592592+ cron_registry: &SharedCronRegistry,
593593+ guild_id: &Option<String>,
594594+ cron_name: &str,
595595+) {
596596+ let mut reg = cron_registry.lock();
597597+ let Some(jobs) = reg.jobs.get_mut(guild_id) else {
598598+ return;
599599+ };
600600+ for job in jobs.iter_mut() {
601601+ if job.name == cron_name {
602602+ job.is_running = false;
603603+ break;
575604 }
576605 }
577606}
+11
apps/www/sdk.md
···210210- `name`: The cron job name you specified
211211- `scheduledAt`: ISO 8601 timestamp of when the job was scheduled to run
212212213213+### Options
214214+215215+```ts
216216+// Skip execution if previous run is still active
217217+cron('long-task', '*/5 * * * *', async (ctx) => {
218218+ await someLongRunningTask()
219219+}, { skipIfRunning: true })
220220+```
221221+222222+- `skipIfRunning`: If `true`, the job won't start a new execution if the previous one is still running. Default: `false`.
223223+213224Cron expressions follow standard 5-field format: `minute hour day-of-month month day-of-week`.
214225215226Limits: