mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(schedules): run scheduled jobs in a per-job sandbox microVM
This commit is contained in:
1 parent
11a2661cc6
commit
070cb2f729
28 files changed
+1069
-83
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import type { Migration } from '../migration-runner'
|
||||
|
||||
interface ColumnInfo {
|
||||
name: string
|
||||
}
|
||||
|
||||
const migration: Migration = {
|
||||
id: '202610251900-schedule-sandbox-config',
|
||||
|
||||
up(db) {
|
||||
const columns = db.prepare('PRAGMA table_info(schedule_jobs)').all() as ColumnInfo[]
|
||||
if (!columns.some((column) => column.name === 'sandbox_config')) {
|
||||
db.run('ALTER TABLE schedule_jobs ADD COLUMN sandbox_config TEXT')
|
||||
}
|
||||
},
|
||||
|
||||
down(db) {
|
||||
db.run('ALTER TABLE schedule_jobs DROP COLUMN sandbox_config')
|
||||
},
|
||||
}
|
||||
|
||||
export default migration
|
||||
@@ -41,6 +41,7 @@ import migration202610181400 from './202610181400-secrets'
|
||||
import { secretsGlobalScopeIndexMigration } from './202610181410-secrets-global-scope-index'
|
||||
import migration202610221800 from './202610221800-session-device-name'
|
||||
import migration202610231200 from './202610231200-push-subscription-session-id'
|
||||
import migration202610251900 from './202610251900-schedule-sandbox-config'
|
||||
|
||||
export const allMigrations: Migration[] = [
|
||||
migration001,
|
||||
@@ -85,4 +86,5 @@ export const allMigrations: Migration[] = [
|
||||
secretsGlobalScopeIndexMigration,
|
||||
migration202610221800,
|
||||
migration202610231200,
|
||||
migration202610251900,
|
||||
]
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
ScheduleMcpServersSchema,
|
||||
SchedulePermissionConfigSchema,
|
||||
ScheduleRunSchema,
|
||||
ScheduleSandboxConfigSchema,
|
||||
ScheduleSkillMetadataSchema,
|
||||
ScheduleWorkspaceModeSchema,
|
||||
type ScheduleJob,
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
type ScheduleRun,
|
||||
type ScheduleRunStatus,
|
||||
type ScheduleRunTriggerSource,
|
||||
type ScheduleSandboxConfig,
|
||||
type ScheduleWorkspaceMode,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { ASSISTANT_REPO_ID, ASSISTANT_REPO_NAME, ASSISTANT_REPO_PATH, getRepoDisplayName } from '@opencode-manager/shared/utils'
|
||||
@@ -39,6 +41,7 @@ interface ScheduleJobRow {
|
||||
mcp_servers: string | null
|
||||
branch: string | null
|
||||
workspace_mode: ScheduleWorkspaceMode | null
|
||||
sandbox_config: string | null
|
||||
created_at: number
|
||||
updated_at: number
|
||||
last_run_at: number | null
|
||||
@@ -107,6 +110,19 @@ function parseMcpServers(raw: string | null): ScheduleMcpServer[] {
|
||||
}
|
||||
}
|
||||
|
||||
function parseSandboxConfig(raw: string | null): ScheduleSandboxConfig | null {
|
||||
if (!raw) {
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
const result = ScheduleSandboxConfigSchema.safeParse(JSON.parse(raw))
|
||||
return result.success ? result.data : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeWorkspaceMode(raw: string | null): ScheduleWorkspaceMode {
|
||||
const result = ScheduleWorkspaceModeSchema.safeParse(raw)
|
||||
return result.success ? result.data : 'worktree'
|
||||
@@ -133,6 +149,7 @@ function rowToScheduleJob(row: ScheduleJobRow): ScheduleJob {
|
||||
mcpServers: parseMcpServers(row.mcp_servers),
|
||||
branch: row.branch,
|
||||
workspaceMode: normalizeWorkspaceMode(row.workspace_mode),
|
||||
sandbox: parseSandboxConfig(row.sandbox_config),
|
||||
createdAt: row.created_at,
|
||||
updatedAt: row.updated_at,
|
||||
lastRunAt: row.last_run_at,
|
||||
@@ -183,6 +200,10 @@ function serializeMcpServers(mcpServers: ScheduleJobPersistenceInput['mcpServers
|
||||
return mcpServers.length > 0 ? JSON.stringify(mcpServers) : null
|
||||
}
|
||||
|
||||
function serializeSandboxConfig(sandbox: ScheduleJobPersistenceInput['sandbox']): string | null {
|
||||
return sandbox ? JSON.stringify(sandbox) : null
|
||||
}
|
||||
|
||||
export function listScheduleJobsByRepo(db: Database, repoId: number): ScheduleJob[] {
|
||||
const stmt = db.prepare('SELECT * FROM schedule_jobs WHERE repo_id IS ? ORDER BY created_at DESC')
|
||||
const rows = stmt.all(repoId) as ScheduleJobRow[]
|
||||
@@ -227,9 +248,10 @@ export function createScheduleJob(
|
||||
mcp_servers,
|
||||
branch,
|
||||
workspace_mode,
|
||||
sandbox_config,
|
||||
created_at, updated_at, last_run_at, next_run_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`)
|
||||
|
||||
const result = stmt.run(
|
||||
@@ -251,6 +273,7 @@ export function createScheduleJob(
|
||||
serializeMcpServers(input.mcpServers),
|
||||
input.branch,
|
||||
input.workspaceMode,
|
||||
serializeSandboxConfig(input.sandbox),
|
||||
now,
|
||||
now,
|
||||
null,
|
||||
@@ -275,7 +298,7 @@ export function updateScheduleJob(db: Database, repoId: number | null, jobId: nu
|
||||
const stmt = db.prepare(`
|
||||
UPDATE schedule_jobs
|
||||
SET name = ?, description = ?, enabled = ?, schedule_mode = ?, interval_minutes = ?, cron_expression = ?, timezone = ?,
|
||||
agent_slug = ?, prompt = ?, model = ?, skill_metadata = ?, permission_config = ?, mcp_servers = ?, branch = ?, workspace_mode = ?, directory = ?, updated_at = ?, next_run_at = ?
|
||||
agent_slug = ?, prompt = ?, model = ?, skill_metadata = ?, permission_config = ?, mcp_servers = ?, branch = ?, workspace_mode = ?, sandbox_config = ?, directory = ?, updated_at = ?, next_run_at = ?
|
||||
WHERE repo_id IS ? AND id = ?
|
||||
`)
|
||||
|
||||
@@ -295,6 +318,7 @@ export function updateScheduleJob(db: Database, repoId: number | null, jobId: nu
|
||||
serializeMcpServers(input.mcpServers),
|
||||
input.branch,
|
||||
input.workspaceMode,
|
||||
serializeSandboxConfig(input.sandbox),
|
||||
input.directory ?? null,
|
||||
now,
|
||||
input.nextRunAt,
|
||||
|
||||
Reference in new issue
Block a user