opencode-supertask 0.1.40 → 0.1.41

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.
@@ -27155,13 +27155,23 @@ var TaskService = class {
27155
27155
  });
27156
27156
  const maxRetries = normalizedData.maxRetries ?? task.maxRetries ?? 3;
27157
27157
  const exhausted = task.status === "failed" && (task.retryCount ?? 0) > maxRetries;
27158
- return tx.update(tasks2).set({
27158
+ const updated = tx.update(tasks2).set({
27159
27159
  ...normalizedData,
27160
27160
  ...exhausted ? {
27161
27161
  status: "dead_letter",
27162
27162
  retryAfter: null
27163
27163
  } : {}
27164
27164
  }).where(eq(tasks2.id, id)).returning().get() ?? null;
27165
+ if (exhausted && updated) {
27166
+ const finishedAt = /* @__PURE__ */ new Date();
27167
+ tx.update(tasks2).set({
27168
+ status: "dead_letter",
27169
+ finishedAt,
27170
+ retryAfter: null,
27171
+ resultLog: `\u4F9D\u8D56\u4EFB\u52A1 #${id} \u5DF2\u8FDB\u5165\u4E0D\u53EF\u6062\u590D\u7EC8\u6001`
27172
+ }).where(blockedDependentsOf(id)).run();
27173
+ }
27174
+ return updated;
27165
27175
  }, { behavior: "immediate" });
27166
27176
  }
27167
27177
  static validateNewTask(data) {
@@ -27182,7 +27192,7 @@ var TaskService = class {
27182
27192
  throw new Error(`${name} \u5FC5\u987B\u662F ${min} \u5230 ${max} \u4E4B\u95F4\u7684\u6574\u6570`);
27183
27193
  }
27184
27194
  }
27185
- static async next(scope = {}) {
27195
+ static buildRunnableTaskWhere(scope) {
27186
27196
  const baseConditions = [...this.buildScopeWhere(scope)];
27187
27197
  const nowMs = Date.now();
27188
27198
  const retryAfterFilter = or(
@@ -27217,40 +27227,43 @@ var TaskService = class {
27217
27227
  if (batchFilter) {
27218
27228
  conditions.push(batchFilter);
27219
27229
  }
27220
- const result = await db.select().from(tasks2).where(and(
27230
+ return and(
27221
27231
  ...conditions,
27222
27232
  or(
27223
27233
  isNull(tasks2.dependsOn),
27224
27234
  sql`EXISTS (
27225
- SELECT 1 FROM tasks AS dependency_task
27226
- WHERE dependency_task.id = ${tasks2.dependsOn}
27227
- AND dependency_task.status = 'done'
27228
- AND dependency_task.cwd IS ${tasks2.cwd}
27229
- )`
27235
+ SELECT 1 FROM tasks AS dependency_task
27236
+ WHERE dependency_task.id = ${tasks2.dependsOn}
27237
+ AND dependency_task.status = 'done'
27238
+ AND dependency_task.cwd IS ${tasks2.cwd}
27239
+ )`
27230
27240
  ),
27231
27241
  or(
27232
27242
  isNull(tasks2.batchId),
27233
27243
  sql`trim(${tasks2.batchId}, ${TASK_BATCH_TRIM_CHARACTERS}) = ''`,
27234
27244
  sql`NOT EXISTS (
27235
- SELECT 1 FROM tasks AS running_batch_task
27236
- WHERE trim(running_batch_task.batch_id, ${TASK_BATCH_TRIM_CHARACTERS})
27237
- = trim(${tasks2.batchId}, ${TASK_BATCH_TRIM_CHARACTERS})
27238
- AND (
27239
- running_batch_task.status = 'running'
27240
- OR EXISTS (
27241
- SELECT 1 FROM task_runs AS running_batch_run
27242
- WHERE running_batch_run.task_id = running_batch_task.id
27243
- AND running_batch_run.status = 'running'
27244
- )
27245
+ SELECT 1 FROM tasks AS running_batch_task
27246
+ WHERE trim(running_batch_task.batch_id, ${TASK_BATCH_TRIM_CHARACTERS})
27247
+ = trim(${tasks2.batchId}, ${TASK_BATCH_TRIM_CHARACTERS})
27248
+ AND (
27249
+ running_batch_task.status = 'running'
27250
+ OR EXISTS (
27251
+ SELECT 1 FROM task_runs AS running_batch_run
27252
+ WHERE running_batch_run.task_id = running_batch_task.id
27253
+ AND running_batch_run.status = 'running'
27245
27254
  )
27246
- )`
27255
+ )
27256
+ )`
27247
27257
  ),
27248
27258
  sql`NOT EXISTS (
27249
- SELECT 1 FROM task_runs AS candidate_active_run
27250
- WHERE candidate_active_run.task_id = ${tasks2.id}
27251
- AND candidate_active_run.status = 'running'
27252
- )`
27253
- )).orderBy(
27259
+ SELECT 1 FROM task_runs AS candidate_active_run
27260
+ WHERE candidate_active_run.task_id = ${tasks2.id}
27261
+ AND candidate_active_run.status = 'running'
27262
+ )`
27263
+ );
27264
+ }
27265
+ static async next(scope = {}) {
27266
+ const result = await db.select().from(tasks2).where(this.buildRunnableTaskWhere(scope)).orderBy(
27254
27267
  desc(tasks2.urgency),
27255
27268
  desc(tasks2.importance),
27256
27269
  asc(tasks2.createdAt),
@@ -27258,6 +27271,22 @@ var TaskService = class {
27258
27271
  ).limit(1);
27259
27272
  return result[0] ?? null;
27260
27273
  }
27274
+ static async claimNext(scope = {}) {
27275
+ return db.transaction((tx) => {
27276
+ const candidate = tx.select().from(tasks2).where(this.buildRunnableTaskWhere(scope)).orderBy(
27277
+ desc(tasks2.urgency),
27278
+ desc(tasks2.importance),
27279
+ asc(tasks2.createdAt),
27280
+ asc(tasks2.id)
27281
+ ).limit(1).get();
27282
+ if (!candidate) return null;
27283
+ return tx.update(tasks2).set({
27284
+ status: "running",
27285
+ startedAt: /* @__PURE__ */ new Date(),
27286
+ finishedAt: null
27287
+ }).where(eq(tasks2.id, candidate.id)).returning().get() ?? null;
27288
+ }, { behavior: "immediate" });
27289
+ }
27261
27290
  static async countRunning(scope = {}) {
27262
27291
  const scopeConditions = scope.legacyCwd ? [sql`${tasks2.cwd} IS NULL OR trim(${tasks2.cwd}) = ''`] : this.buildScopeWhere(scope);
27263
27292
  if (scope.batchId !== void 0) {