@axiom-lattice/local-stores 5.5.3 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -6531,6 +6531,9 @@ function mapRowToSkill(row) {
6531
6531
  }
6532
6532
 
6533
6533
  // src/stores/LocalScheduleStorage.ts
6534
+ import {
6535
+ ScheduleExecutionType
6536
+ } from "@axiom-lattice/protocols";
6534
6537
  var DDL30 = `
6535
6538
  CREATE TABLE IF NOT EXISTS lt_scheduled_tasks (
6536
6539
  task_id TEXT PRIMARY KEY,
@@ -6709,10 +6712,27 @@ var LocalScheduleStorage = class {
6709
6712
  `UPDATE lt_scheduled_tasks SET ${setClauses.join(", ")} WHERE task_id = ?`
6710
6713
  ).run(...values);
6711
6714
  }
6712
- async claimScheduledRun(taskId) {
6715
+ async claimScheduledRun(taskId, expectedFireAt) {
6716
+ const now = (/* @__PURE__ */ new Date()).toISOString();
6717
+ const expected = new Date(expectedFireAt).toISOString();
6713
6718
  const result = this.db.prepare(
6714
- `UPDATE lt_scheduled_tasks SET status = 'running', updated_at = ? WHERE task_id = ? AND status = 'pending'`
6715
- ).run((/* @__PURE__ */ new Date()).toISOString(), taskId);
6719
+ `UPDATE lt_scheduled_tasks
6720
+ SET status = 'running', updated_at = ?
6721
+ WHERE task_id = ? AND status = 'pending'
6722
+ AND (
6723
+ (execution_type = ? AND execute_at = ? AND execute_at <= ?)
6724
+ OR (execution_type = ? AND next_run_at = ? AND next_run_at <= ?)
6725
+ )`
6726
+ ).run(
6727
+ now,
6728
+ taskId,
6729
+ ScheduleExecutionType.ONCE,
6730
+ expected,
6731
+ now,
6732
+ ScheduleExecutionType.CRON,
6733
+ expected,
6734
+ now
6735
+ );
6716
6736
  return result.changes > 0;
6717
6737
  }
6718
6738
  /**