@ultimat3/jobs 22.8.2 → 22.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/jobs",
3
- "version": "22.8.2",
3
+ "version": "22.9.1",
4
4
  "description": "Durable background work: steps, transactional outbox, cron tasks, one driver interface",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,10 +32,10 @@
32
32
  "test": "bun test"
33
33
  },
34
34
  "dependencies": {
35
- "@ultimat3/core": "22.8.2",
36
- "@ultimat3/db": "22.8.2",
37
- "@ultimat3/entity": "22.8.2",
38
- "@ultimat3/schema": "22.8.2",
39
- "@ultimat3/time": "22.8.2"
35
+ "@ultimat3/core": "22.9.1",
36
+ "@ultimat3/db": "22.9.1",
37
+ "@ultimat3/entity": "22.9.1",
38
+ "@ultimat3/schema": "22.9.1",
39
+ "@ultimat3/time": "22.9.1"
40
40
  }
41
41
  }
package/src/job.ts CHANGED
@@ -163,6 +163,7 @@ export interface JobHandle<I = unknown> {
163
163
  export type AnyJobHandle = JobHandle<unknown>;
164
164
 
165
165
  const registry = new Map<string, AnyJobHandle>();
166
+ /** Process-monotonic — `resetJobs()` deliberately leaves it alone. */
166
167
  let anonymous = 0;
167
168
 
168
169
  /**
@@ -396,9 +397,12 @@ export function registeredJobs(): readonly AnyJobHandle[] {
396
397
  return [...registry.values()].sort((a, b) => byName(a.name, b.name));
397
398
  }
398
399
 
400
+ /**
401
+ * Clears the registry and NOT the counter, for `resetTasks`'s reason: an `anonymous-job-<n>`
402
+ * re-minted after a reset shares its name with a handle an earlier test file still holds.
403
+ */
399
404
  export function resetJobs(): void {
400
405
  registry.clear();
401
- anonymous = 0;
402
406
  }
403
407
 
404
408
  /**
package/src/task.ts CHANGED
@@ -97,6 +97,7 @@ export interface TaskHandle {
97
97
  }
98
98
 
99
99
  const registry = new Map<string, TaskHandle>();
100
+ /** Process-monotonic — see `resetTasks`, which deliberately leaves it alone. */
100
101
  let anonymous = 0;
101
102
 
102
103
  /** Occurrences one round may fire when neither the declaration nor a catch-up says otherwise. */
@@ -186,7 +187,8 @@ export function task(definition: TaskDefinition): TaskHandle {
186
187
  origin.set(handle, { declaredName: definition.name !== undefined });
187
188
  // Refused here, not at `registerTask`: a second `task({ name: 'nightly' })` would otherwise
188
189
  // replace the seated handle, and the scheduler's persisted `lastFiredAt` — keyed by that name —
189
- // would silently start driving a different cron. The anonymous names cannot collide.
190
+ // would silently start driving a different cron. The anonymous names cannot collide — the
191
+ // counter only ever grows, `resetTasks()` included.
190
192
  if (registry.has(name)) throw new JobNameTakenError({ kind: 'task', name });
191
193
  registry.set(name, handle);
192
194
  return handle;
@@ -255,9 +257,15 @@ export function getTask(name: string): TaskHandle | undefined {
255
257
  return registry.get(name);
256
258
  }
257
259
 
260
+ /**
261
+ * Clears the registry and NOT the counter. `anonymous-task-<n>` is unique per PROCESS, never per
262
+ * reset: `@ultimat3/testing` hands a worker's earlier handles back after a file (`restoreTasks`),
263
+ * and a counter rewound here re-minted `anonymous-task-1` for the next file's task — the restored
264
+ * handle and the new one then shared a name, so `task()` refused it as taken or the name-keyed
265
+ * snapshot merge dropped one, depending on which file ran first.
266
+ */
258
267
  export function resetTasks(): void {
259
268
  registry.clear();
260
- anonymous = 0;
261
269
  }
262
270
 
263
271
  /**