MCPcopy Create free account
hub / github.com/electric-sql/electric / executeTask

Method executeTask

packages/agents-server/src/scheduler.ts:582–623  ·  view source on GitHub ↗
(
    task: ReturnType<typeof normalizeTask>
  )

Source from the content-addressed store, hash-verified

580 }
581
582 private async executeTask(
583 task: ReturnType<typeof normalizeTask>
584 ): Promise<void> {
585 try {
586 if (task.kind === `delayed_send`) {
587 await this.options.executors.delayed_send(
588 task.payload as DelayedSendPayload,
589 task.id,
590 task.tenantId
591 )
592 await this.markTaskComplete(task.id, task.tenantId)
593 return
594 }
595
596 const tickNumber = task.cronTickNumber
597 if (tickNumber == null || !task.cronExpression || !task.cronTimezone) {
598 throw new Error(`cron task ${task.id} is missing cron metadata`)
599 }
600
601 await this.options.executors.cron_tick(
602 task.payload as CronTickPayload,
603 tickNumber,
604 task.id,
605 task.tenantId
606 )
607 await this.completeAndRescheduleCron(task)
608 } catch (err) {
609 const message = err instanceof Error ? err.message : String(err)
610 if (isUnregisteredTenantError(err)) {
611 await this.releaseClaim(task.id, message, task.tenantId)
612 serverLog.warn(
613 `[scheduler] skipped ${task.kind} task ${task.id} for unregistered tenant "${task.tenantId}": ${message}`
614 )
615 return
616 }
617 if (isPermanentElectricAgentsError(err)) {
618 await this.markTaskPermanentFailure(task.id, message, task.tenantId)
619 return
620 }
621 await this.releaseClaim(task.id, message, task.tenantId)
622 }
623 }
624
625 private async markTaskComplete(
626 taskId: number,

Callers 2

fireReadyTasksMethod · 0.95
scheduler.test.tsFile · 0.80

Calls 6

markTaskCompleteMethod · 0.95
releaseClaimMethod · 0.95

Tested by

no test coverage detected