rename background job manager to background job service
This commit is contained in:
parent
001e553722
commit
1d2cba889c
6 changed files with 22 additions and 26 deletions
|
|
@ -23,7 +23,11 @@ export interface BackgroundJob {
|
|||
const MAX_CONCURRENT_JOBS = 5;
|
||||
const MAX_OUTPUT_LINES = 1000;
|
||||
|
||||
export class BackgroundJobManager {
|
||||
/**
|
||||
* Service for managing background job execution and lifecycle
|
||||
* Handles spawning, tracking, and cleanup of background processes
|
||||
*/
|
||||
export class BackgroundJobService {
|
||||
private jobs: Map<string, BackgroundJob> = new Map();
|
||||
private processes: Map<string, ChildProcess> = new Map();
|
||||
private jobCounter = 0;
|
||||
|
|
@ -209,12 +213,6 @@ export class BackgroundJobManager {
|
|||
}
|
||||
this.processes.clear();
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.killAllJobs();
|
||||
this.jobs.clear();
|
||||
this.jobCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export const backgroundJobManager = new BackgroundJobManager();
|
||||
export const backgroundJobService = new BackgroundJobService();
|
||||
|
|
@ -10,7 +10,6 @@ import { AgentFileService } from "./AgentFileService.js";
|
|||
import { ApiClientService } from "./ApiClientService.js";
|
||||
import { ArtifactUploadService } from "./ArtifactUploadService.js";
|
||||
import { AuthService } from "./AuthService.js";
|
||||
import { backgroundJobManager } from "./BackgroundJobManager.js";
|
||||
import { ChatHistoryService } from "./ChatHistoryService.js";
|
||||
import { ConfigService } from "./ConfigService.js";
|
||||
import { FileIndexService } from "./FileIndexService.js";
|
||||
|
|
@ -388,7 +387,7 @@ export const services = {
|
|||
toolPermissions: toolPermissionService,
|
||||
artifactUpload: artifactUploadService,
|
||||
gitAiIntegration: gitAiIntegrationService,
|
||||
backgroundJobs: backgroundJobManager,
|
||||
backgroundJobs: backgroundJobService,
|
||||
} as const;
|
||||
|
||||
export type ServicesType = typeof services;
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ export interface ArtifactUploadServiceState {
|
|||
export type {
|
||||
BackgroundJob,
|
||||
BackgroundJobStatus,
|
||||
} from "./BackgroundJobManager.js";
|
||||
} from "./BackgroundJobService.js";
|
||||
export type { ChatHistoryState } from "./ChatHistoryService.js";
|
||||
export type { FileIndexServiceState } from "./FileIndexService.js";
|
||||
export type { GitAiIntegrationServiceState } from "./GitAiIntegrationService.js";
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
type ToolPolicy,
|
||||
} from "@continuedev/terminal-security";
|
||||
|
||||
import { backgroundJobManager } from "../services/BackgroundJobManager.js";
|
||||
import { backgroundJobService } from "../services/BackgroundJobService.js";
|
||||
import { services } from "../services/index.js";
|
||||
import { telemetryService } from "../telemetry/telemetryService.js";
|
||||
import {
|
||||
|
|
@ -91,7 +91,7 @@ export function runCommandInBackground(command: string): {
|
|||
jobId?: string;
|
||||
error?: string;
|
||||
} {
|
||||
const job = backgroundJobManager.createJob(command);
|
||||
const job = backgroundJobService.createJob(command);
|
||||
if (!job) {
|
||||
return {
|
||||
success: false,
|
||||
|
|
@ -100,7 +100,7 @@ export function runCommandInBackground(command: string): {
|
|||
}
|
||||
|
||||
const { shell, args } = getShellCommand(command);
|
||||
const child = backgroundJobManager.startJob(job.id, shell, args);
|
||||
const child = backgroundJobService.startJob(job.id, shell, args);
|
||||
|
||||
if (!child) {
|
||||
return {
|
||||
|
|
@ -231,7 +231,7 @@ IMPORTANT: To edit files, use Edit/MultiEdit tools instead of bash commands (sed
|
|||
}
|
||||
backgroundSignalManager.off("backgroundRequested", moveToBackground);
|
||||
|
||||
const job = backgroundJobManager.createJobWithProcess(
|
||||
const job = backgroundJobService.createJobWithProcess(
|
||||
command,
|
||||
child as ChildProcess,
|
||||
stdout,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import React, { useEffect, useState } from "react";
|
|||
|
||||
import {
|
||||
BackgroundJob,
|
||||
backgroundJobManager,
|
||||
} from "../services/BackgroundJobManager.js";
|
||||
backgroundJobService,
|
||||
} from "../services/BackgroundJobService.js";
|
||||
import { truncateOutputFromStart } from "../util/truncateOutput.js";
|
||||
|
||||
import { defaultBoxStyles } from "./styles.js";
|
||||
|
|
@ -30,18 +30,18 @@ export function JobsSelector({ onCancel }: JobsSelectorProps) {
|
|||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
const [viewMode, setViewMode] = useState<ViewMode>("list");
|
||||
const [selectedJob, setSelectedJob] = useState<BackgroundJob | null>(null);
|
||||
const [jobs, setJobs] = useState(() => backgroundJobManager.getAllJobs());
|
||||
const [jobs, setJobs] = useState(() => backgroundJobService.getAllJobs());
|
||||
|
||||
// Refetch the job details every 1 second
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
if (viewMode === "detail" && selectedJob) {
|
||||
const freshJob = backgroundJobManager.getJob(selectedJob.id);
|
||||
const freshJob = backgroundJobService.getJob(selectedJob.id);
|
||||
if (freshJob) {
|
||||
setSelectedJob(freshJob);
|
||||
}
|
||||
} else {
|
||||
setJobs(backgroundJobManager.getAllJobs());
|
||||
setJobs(backgroundJobService.getAllJobs());
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
|
|
@ -59,9 +59,9 @@ export function JobsSelector({ onCancel }: JobsSelectorProps) {
|
|||
}
|
||||
// Cancel the selected job if it's still active
|
||||
if (input === "x" && selectedJob) {
|
||||
const job = backgroundJobManager.getJob(selectedJob.id);
|
||||
const job = backgroundJobService.getJob(selectedJob.id);
|
||||
if (job && (job.status === "running" || job.status === "pending")) {
|
||||
backgroundJobManager.cancelJob(selectedJob.id);
|
||||
backgroundJobService.cancelJob(selectedJob.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { ChatHistoryItem } from "core/index.js";
|
||||
|
||||
import { sentryService } from "../sentry.js";
|
||||
import { backgroundJobManager } from "../services/BackgroundJobManager.js";
|
||||
import { backgroundJobService } from "../services/BackgroundJobService.js";
|
||||
import { getSessionUsage } from "../session.js";
|
||||
import { telemetryService } from "../telemetry/telemetryService.js";
|
||||
|
||||
|
|
@ -196,11 +196,10 @@ export async function gracefulExit(code: number = 0): Promise<void> {
|
|||
displaySessionUsage();
|
||||
|
||||
try {
|
||||
// todo: rename backgroundJobManager to backgroundCommandService
|
||||
const runningJobs = backgroundJobManager.getRunningJobCount();
|
||||
const runningJobs = backgroundJobService.getRunningJobCount();
|
||||
if (runningJobs > 0) {
|
||||
logger.debug(`Killing ${runningJobs} background job(s) on exit`);
|
||||
backgroundJobManager.killAllJobs();
|
||||
backgroundJobService.killAllJobs();
|
||||
}
|
||||
} catch (err) {
|
||||
logger.debug("Background job cleanup error (ignored)", err as any);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue