Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/worker/src/jobs/service.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ function createDatabase() {
row['id'] === params[0] && row['user_id'] === params[1],
) as T | null
}
if (
query.includes(
'SELECT * FROM entity_sources WHERE id = ? AND user_id = ?',
)
) {
return selectOne(
'entity_sources',
(row) =>
row['id'] === params[0] && row['user_id'] === params[1],
) as T | null
}
if (query.includes('SELECT * FROM entity_sources WHERE id = ?')) {
return selectOne(
'entity_sources',
Expand Down Expand Up @@ -1622,6 +1633,7 @@ test('getJobInspection returns persisted params after a job update', async () =>
},
})

repoMockModule.syncArtifactSourceSnapshot.mockClear()
const updated = await updateJob({
env,
callerContext,
Expand All @@ -1640,6 +1652,7 @@ test('getJobInspection returns persisted params after a job update', async () =>

expect(updated.params).toEqual({ bridgeId: 'ZPGI01117' })
expect(inspected.job.params).toEqual({ bridgeId: 'ZPGI01117' })
expect(repoMockModule.syncArtifactSourceSnapshot).not.toHaveBeenCalled()
})

test('executeJobOnce binds scheduled jobs to writable storage', async () => {
Expand Down
46 changes: 31 additions & 15 deletions packages/worker/src/jobs/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { runBundledModuleWithRegistry } from '#mcp/run-codemode-registry.ts'
import {
deleteEntitySource,
getEntitySourceById,
getEntitySourceByIdForUser,
} from '#worker/repo/entity-sources.ts'
import { cleanupArtifactReposForSource } from '#worker/repo/artifact-repo-cleanup.ts'
import { repoSessionRpc } from '#worker/repo/repo-session-do.ts'
Expand Down Expand Up @@ -697,10 +698,12 @@ async function cleanupAdHocJobSource(input: {
if (!input.sourceId) {
return
}
const source = await getEntitySourceById(input.env.APP_DB, input.sourceId)
const source = await getEntitySourceByIdForUser(input.env.APP_DB, {
id: input.sourceId,
userId: input.userId,
})
if (
!source ||
source.user_id !== input.userId ||
source.entity_kind !== 'job' ||
source.entity_id !== input.jobId
) {
Expand Down Expand Up @@ -922,6 +925,17 @@ function resolveUpdatedShape(input: {
}
}

function shouldSyncJobSourceForUpdate(body: JobUpdateInput) {
return (
body.code !== undefined ||
body.name !== undefined ||
body.schedule !== undefined ||
body.timezone !== undefined ||
body.sourceId !== undefined ||
body.publishedCommit !== undefined
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

export async function createJob(input: {
env: Env
callerContext: McpCallerContext
Expand Down Expand Up @@ -1131,19 +1145,21 @@ export async function updateJob(input: {
})
: existing.nextRunAt,
}
const syncedPublishedCommit = await syncArtifactSourceSnapshot({
env: input.env,
userId: callerContext.user.userId,
baseUrl: callerContext.baseUrl,
sourceId: updated.sourceId,
bootstrapAccess: null,
files: buildJobSourceFiles({
job: toJobView(updated),
moduleSource: shape.moduleSource ?? null,
}),
})
if (syncedPublishedCommit) {
updated.publishedCommit = syncedPublishedCommit
if (shouldSyncJobSourceForUpdate(input.body)) {
const syncedPublishedCommit = await syncArtifactSourceSnapshot({
env: input.env,
userId: callerContext.user.userId,
baseUrl: callerContext.baseUrl,
sourceId: updated.sourceId,
bootstrapAccess: null,
files: buildJobSourceFiles({
job: toJobView(updated),
moduleSource: shape.moduleSource ?? null,
}),
})
if (syncedPublishedCommit) {
updated.publishedCommit = syncedPublishedCommit
}
}
const nextCallerContextJson = serializeCallerContext(callerContext)
const didUpdate = await updateJobRow({
Expand Down
Loading
Loading