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
41 changes: 39 additions & 2 deletions packages/worker/src/jobs/manager-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type McpCallerContext } from '@kody-internal/shared/chat.ts'
import {
logJobSchedulerError,
logJobSchedulerEvent,
schedulerErrorFields,
} from './scheduler-logging.ts'
import {
type JobExecutionResult,
type JobRepoCheckPolicy,
Expand All @@ -22,7 +27,10 @@ export type JobManagerDebugState = {
}

type JobManagerRpc = {
syncAlarm: (payload: { userId: string }) => Promise<{
syncAlarm: (payload: {
userId: string
source?: 'alarm' | 'rpc' | 'run_now'
}) => Promise<{
ok: true
userId: string
nextRunAt: string | null
Expand Down Expand Up @@ -50,15 +58,44 @@ export function jobManagerRpc(env: Env, userId: string): JobManagerRpc | null {
export async function syncJobManagerAlarm(input: { env: Env; userId: string }) {
const rpc = jobManagerRpc(input.env, input.userId)
if (!rpc) {
logJobSchedulerEvent({
event: 'sync_alarm_skipped_missing_binding',
userId: input.userId,
reason: 'missing_job_manager_binding',
})
return {
ok: true as const,
userId: input.userId,
nextRunAt: null,
}
}
return rpc.syncAlarm({
logJobSchedulerEvent({
event: 'sync_alarm_requested',
userId: input.userId,
})
try {
const result = await rpc.syncAlarm({
userId: input.userId,
source: 'rpc',
})
logJobSchedulerEvent({
event: 'sync_alarm_completed',
userId: result.userId,
nextRunAt: result.nextRunAt,
reason:
result.nextRunAt == null
? 'no_runnable_job_found'
: 'alarm_state_updated',
})
return result
} catch (error) {
logJobSchedulerError({
event: 'sync_alarm_request_failed',
userId: input.userId,
...schedulerErrorFields(error),
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
throw error
}
}

export async function getJobManagerDebugState(input: {
Expand Down
Loading
Loading