async processJob()

in app/lib/server/jobProcessor.ts [28:84]


  async processJob(jobId: string, jobStore: JobStore, credentials: any) {
    try {
      // Update status to running
      await jobStore.updateJobStatus(jobId, "running");

      // Get job data for context
      const job = await jobStore.getJob(jobId);

      // Execute the job using the API executor with credentials
      const result = await this.executor.execute(jobId, job, credentials);

      // Store the environment and secrets used for this job
      if (result.environment || result.secrets || result.apiJobId) {
        await jobStore.updateJobEnvironment(
          jobId,
          result.environment || {},
          result.secrets
            ? Object.keys(result.secrets).reduce(
                (acc, key) => {
                  acc[key] = "***"; // Mask secret values for security
                  return acc;
                },
                {} as Record<string, string>
              )
            : {},
          result.apiJobId
        );
      }

      // Store the full output logs (before extracting diff)
      if (result.output) {
        await jobStore.setJobLogs(jobId, result.output);
      }

      // Store the diff
      await jobStore.setJobDiff(jobId, result.diff);

      // Update status to completed with changes
      await jobStore.updateJobStatus(jobId, "completed", {
        additions: result.diff.summary.totalAdditions,
        deletions: result.diff.summary.totalDeletions,
        files: result.diff.summary.totalFiles,
      });

      console.log(
        `✅ Job ${jobId} completed successfully via ${this.currentMode}`
      );
      return result;
    } catch (error) {
      console.error(
        `❌ Job ${jobId} failed in ${this.currentMode} mode:`,
        error
      );
      await jobStore.updateJobStatus(jobId, "failed");
      throw error;
    }
  }