@teamkeel/functions-runtime 0.456.0 → 0.457.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.cjs CHANGED
@@ -4304,15 +4304,18 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4304
4304
  const failedSteps = past.filter(
4305
4305
  (step) => step.status === "FAILED" /* FAILED */
4306
4306
  );
4307
+ const runningSteps = past.filter(
4308
+ (step) => step.status === "RUNNING" /* RUNNING */
4309
+ );
4307
4310
  if (newSteps.length > 1) {
4308
4311
  throw new Error("Multiple NEW steps found for the same step");
4309
4312
  }
4310
4313
  if (completedSteps.length > 1) {
4311
4314
  throw new Error("Multiple completed steps found for the same step");
4312
4315
  }
4313
- if (completedSteps.length > 1 && newSteps.length > 1) {
4316
+ if (completedSteps.length === 1 && newSteps.length === 1) {
4314
4317
  throw new Error(
4315
- "Multiple completed and new steps found for the same step"
4318
+ "Found both a completed and a pending NEW step for the same step"
4316
4319
  );
4317
4320
  }
4318
4321
  if (completedSteps.length === 1) {
@@ -4322,9 +4325,15 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4322
4325
  }
4323
4326
  if (newSteps.length === 1) {
4324
4327
  let result = null;
4325
- await db.updateTable("keel.flow_step").set({
4328
+ const claimed = await db.updateTable("keel.flow_step").set({
4329
+ status: "RUNNING" /* RUNNING */,
4326
4330
  startTime: /* @__PURE__ */ new Date()
4327
- }).where("id", "=", newSteps[0].id).returningAll().executeTakeFirst();
4331
+ }).where("id", "=", newSteps[0].id).where("status", "=", "NEW" /* NEW */).returning("id").executeTakeFirst();
4332
+ if (!claimed) {
4333
+ span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4334
+ span.setAttribute("step.status", "RUNNING" /* RUNNING */);
4335
+ throw new StepCreatedDisrupt();
4336
+ }
4328
4337
  try {
4329
4338
  const stepArgs = {
4330
4339
  attempt: failedSteps.length + 1,
@@ -4362,6 +4371,11 @@ function createFlowContext(runId, data, action, callback, element, spanId, ctx)
4362
4371
  span.setAttribute("step.status", "COMPLETED" /* COMPLETED */);
4363
4372
  return result;
4364
4373
  }
4374
+ if (runningSteps.length >= 1) {
4375
+ span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4376
+ span.setAttribute("step.status", "RUNNING" /* RUNNING */);
4377
+ throw new StepCreatedDisrupt();
4378
+ }
4365
4379
  await insertNewStep(db, runId, name, options.stage);
4366
4380
  span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4367
4381
  span.setAttribute("step.status", "NEW" /* NEW */);