Kaizen
Browse modulesInsightsinsights/schedulingClasses

Class: ReportScheduleService

Defined in: server/insights/scheduling/report-schedule-service.ts:138

The request-path orchestrator for scheduled deliveries. Its whole reason to exist is to keep TWO stores in lockstep: the saved_report_schedules row (the durable record) and the BullMQ job scheduler in Redis (what actually fires). Every write goes through here so the two never drift:

  • create commits the desired row before registering the scheduler. If registration fails (a custom cron BullMQ rejects), the row is rolled back only when no newer mutation has superseded it.
  • update rewrites the row, then re-registers the scheduler. If the new config can't register it ROLLS THE CONFIG BACK to the last-known-good one (the schedule keeps delivering on its old pattern) rather than pausing — never silently kill a healthy schedule on a bad edit or a Redis blip.
  • setEnabled flips the row, then re-syncs: enabled → upsert; disabled → remove. Enabling a schedule whose config can't register fails closed (it stays disabled) — you can't enable a broken schedule.
  • delete soft-deletes the row, then removes the scheduler.

The row is always committed FIRST (it is the source of truth). Redis calls never occupy a database transaction or make uncommitted state observable. Every mutation increments a durable version copied into BullMQ job data; stale writers re-read and apply the newer desired state, while stale fires skip delivery. Cross-store atomicity is impossible (Redis + PG), so reconcileReportSchedules also closes the crash window between the committed row and its Redis synchronization at worker startup.

Constructors

Constructor

new ReportScheduleService(deps: ReportScheduleServiceDeps): ReportScheduleService;

Defined in: server/insights/scheduling/report-schedule-service.ts:141

Parameters

ParameterType
depsReportScheduleServiceDeps

Returns

ReportScheduleService

Methods

create()

create(input: CreateReportScheduleInput, ctx: ReportScheduleContext): Promise<ReportSchedule>;

Defined in: server/insights/scheduling/report-schedule-service.ts:200

Parameters

Returns

Promise<ReportSchedule>


createDashboard()

createDashboard(input: CreateDashboardScheduleInput, ctx: ReportScheduleContext): Promise<DashboardSchedule>;

Defined in: server/insights/scheduling/report-schedule-service.ts:227

Parameters

Returns

Promise<DashboardSchedule>


delete()

delete(id: string, ctx: ReportScheduleContext): Promise<void>;

Defined in: server/insights/scheduling/report-schedule-service.ts:534

Parameters

ParameterType
idstring
ctxReportScheduleContext

Returns

Promise<void>


get()

get(id: string, ctx: ReportScheduleContext): Promise<ReportSchedule>;

Defined in: server/insights/scheduling/report-schedule-service.ts:180

Parameters

ParameterType
idstring
ctxReportScheduleContext

Returns

Promise<ReportSchedule>


getDashboardScheduleManagement()

getDashboardScheduleManagement(dashboardKey: string, ctx: ReportScheduleContext): Promise<DashboardScheduleManagementState>;

Defined in: server/insights/scheduling/report-schedule-service.ts:254

Parameters

ParameterType
dashboardKeystring
ctxReportScheduleContext

Returns

Promise<DashboardScheduleManagementState>


list()

list(ctx: ReportScheduleContext, savedReportId?: string): Promise<ReportSchedule[]>;

Defined in: server/insights/scheduling/report-schedule-service.ts:148

Parameters

ParameterType
ctxReportScheduleContext
savedReportId?string

Returns

Promise<ReportSchedule[]>


listRuns()

listRuns(id: string, ctx: ReportScheduleContext): Promise<InsightScheduleRunSummary[]>;

Defined in: server/insights/scheduling/report-schedule-service.ts:189

Parameters

ParameterType
idstring
ctxReportScheduleContext

Returns

Promise<InsightScheduleRunSummary[]>


runNow()

runNow(input: RunReportScheduleNowInput, ctx: ReportScheduleContext): Promise<RunReportScheduleNowResult>;

Defined in: server/insights/scheduling/report-schedule-service.ts:563

Enqueue one delivery without changing recurring state. Disabled schedules may be run deliberately; deletion, tenant scoping, write authorization, corrupt config, and concurrent mutations all fail closed before send.

Parameters

Returns

Promise<RunReportScheduleNowResult>


setEnabled()

setEnabled(
   id: string, 
   enabled: boolean, 
   ctx: ReportScheduleContext
): Promise<void>;

Defined in: server/insights/scheduling/report-schedule-service.ts:461

Parameters

ParameterType
idstring
enabledboolean
ctxReportScheduleContext

Returns

Promise<void>


update()

update(
   id: string, 
   input: UpdateReportScheduleInput, 
   ctx: ReportScheduleContext
): Promise<ReportSchedule>;

Defined in: server/insights/scheduling/report-schedule-service.ts:348

Parameters

Returns

Promise<ReportSchedule>


updateDashboard()

updateDashboard(
   id: string, 
   input: UpdateReportScheduleInput, 
   ctx: ReportScheduleContext
): Promise<DashboardSchedule>;

Defined in: server/insights/scheduling/report-schedule-service.ts:372

Parameters

Returns

Promise<DashboardSchedule>

On this page