@semiont/jobs 0.5.36 → 0.5.37

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.
@@ -9236,17 +9236,19 @@ function createJobClaimAdapter(options) {
9236
9236
  let lastActivityAt = null;
9237
9237
  let activeSince = null;
9238
9238
  const iso = (t) => t === null ? null : new Date(t).toISOString();
9239
- const claimJob = async (assignment) => {
9239
+ const claimNext = async () => {
9240
9240
  try {
9241
- const job = await busRequest(requestBus, "job:claim", { jobId: assignment.jobId }, 1e4);
9241
+ const job = await busRequest(requestBus, "job:claim", { types: jobTypes }, 1e4);
9242
+ if (!isString(job.metadata?.id) || !isString(job.metadata?.type)) return null;
9242
9243
  const completedUnits = isArray(job.metadata?.completedUnits) ? job.metadata.completedUnits.filter(isString) : [];
9243
9244
  const unitCursors = readUnitCursors(job.metadata?.unitCursors, completedUnits);
9245
+ const params = job.params ?? {};
9244
9246
  return {
9245
- jobId: assignment.jobId,
9246
- type: assignment.type,
9247
- resourceId: assignment.resourceId,
9247
+ jobId: job.metadata.id,
9248
+ type: job.metadata.type,
9249
+ resourceId: isString(params.resourceId) ? params.resourceId : "",
9248
9250
  userId: job.metadata?.userId ?? "",
9249
- params: job.params ?? {},
9251
+ params,
9250
9252
  completedUnits,
9251
9253
  unitCursors,
9252
9254
  // Absent or malformed metadata reads as "no budget left" — a worker
@@ -9273,7 +9275,7 @@ function createJobClaimAdapter(options) {
9273
9275
  if (jobTypes.length > 0 && !jobTypes.includes(jobType)) return;
9274
9276
  if (isProcessing$.getValue()) return;
9275
9277
  isProcessing$.next(true);
9276
- claimJob({ jobId: event.jobId, type: jobType, resourceId: event.resourceId }).then((job) => {
9278
+ claimNext().then((job) => {
9277
9279
  if (job) {
9278
9280
  const now = Date.now();
9279
9281
  lastClaimAt = now;