MCPcopy Index your code
hub / github.com/coder/mux / runInBackground

Method runInBackground

src/node/services/workflows/WorkflowService.ts:705–778  ·  view source on GitHub ↗
(
    runId: string,
    failureMessage: string,
    runnerOptions: Pick<
      WorkflowRunnerRunOptions,
      "allowResumeFromInterrupted" | "allowRetryFromFailedCheckpoint"
    > & {
      projectTrusted: boolean;
    }
  )

Source from the content-addressed store, hash-verified

703 }
704
705 private async runInBackground(
706 runId: string,
707 failureMessage: string,
708 runnerOptions: Pick<
709 WorkflowRunnerRunOptions,
710 "allowResumeFromInterrupted" | "allowRetryFromFailedCheckpoint"
711 > & {
712 projectTrusted: boolean;
713 }
714 ): Promise<void> {
715 const runStatus = await this.runStore.getRunStatusSnapshot(runId);
716 const runner = await this.createRunner(runId);
717 const runnerAbortController = new AbortController();
718 let unregisterRunnerAbort: () => void = () => undefined;
719 let startedSettled = false;
720 let resolveStarted: (() => void) | null = null;
721 let rejectStarted: ((error: unknown) => void) | null = null;
722 const started = new Promise<void>((resolve, reject) => {
723 resolveStarted = resolve;
724 rejectStarted = reject;
725 });
726 const markStarted = () => {
727 if (startedSettled) {
728 return;
729 }
730 startedSettled = true;
731 assert(resolveStarted != null, "WorkflowService.runInBackground: resolveStarted missing");
732 resolveStarted();
733 };
734 const markStartFailed = (error: unknown) => {
735 if (startedSettled) {
736 return;
737 }
738 startedSettled = true;
739 assert(rejectStarted != null, "WorkflowService.runInBackground: rejectStarted missing");
740 rejectStarted(error);
741 };
742 const markLeaseAcquired = () => {
743 unregisterRunnerAbort = this.registerActiveRunnerAbortController(
744 runId,
745 runnerAbortController
746 );
747 markStarted();
748 };
749 const runPromise = runner
750 .run(runId, {
751 abortSignal: runnerAbortController.signal,
752 onLeaseAcquired: markLeaseAcquired,
753 backgroundOnMessageQueued: false,
754 ...runnerOptions,
755 })
756 .then(async (result) => {
757 await this.notifyRunStatusChanged(runStatus, "completed");
758 await this.notifyBackgroundRunTerminal(runId, result);
759 })
760 .catch(async (error: unknown) => {
761 const hadStarted = startedSettled;
762 markStartFailed(error);

Calls 10

createRunnerMethod · 0.95
notifyLatestRunStatusMethod · 0.95
getRunStatusSnapshotMethod · 0.80
addMethod · 0.80
runMethod · 0.65
deleteMethod · 0.45

Tested by

no test coverage detected