Skip to Content
⚠️Active Development Notice: TimeTiles is under active development. Information may be placeholder content or not up-to-date.
ReferenceAPI ReferenceLibraryServicesScheduled Import Trigger Service

web


web / lib/services/scheduled-import-trigger-service

lib/services/scheduled-import-trigger-service

Shared trigger logic for scheduled imports.

Consolidates the common steps for triggering a scheduled import run (name generation, status updates, job queueing, statistics) into a single helper used by both the webhook route and the schedule manager job.

Functions

generateImportName()

generateImportName(scheduledImport, currentTime): string

Generate an import name from the scheduled import’s template. Replaces {{name}}, {{date}}, {{time}}, and {{url}} placeholders.

All time values use UTC to ensure consistent filenames regardless of which code path (webhook or schedule manager) triggers the import.

Parameters

scheduledImport

ScheduledImport

currentTime

Date

Returns

string


triggerScheduledImport()

triggerScheduledImport(payload, scheduledImport, currentTime, options): Promise<{ jobId: number; }>

Shared logic for triggering a scheduled import run.

Sets status to “running”, queues a URL fetch job, bumps totalRuns, and resets currentRetries to 0. The caller controls whether nextRun is updated via TriggerOptions.nextRun.

Execution history is NOT recorded here because the import has only been queued, not completed. The actual success/failure entry is added by the url-fetch job handler when processing finishes.

Parameters

payload

BasePayload

scheduledImport

ScheduledImport

currentTime

Date

options

TriggerOptions

Returns

Promise<{ jobId: number; }>

The queued job ID.

Throws

If the job cannot be queued. The caller is responsible for error recovery (e.g. reverting status or recording failure).


queueWebhookImport()

queueWebhookImport(payload, scheduledImport): Promise<{ jobId: number; }>

Queue an import job for a webhook-triggered scheduled import.

Sets status to “running” before queueing, reverts on failure. Does NOT update nextRun because webhooks are event-driven and should not interfere with the scheduled cadence.

Parameters

payload

BasePayload

scheduledImport

ScheduledImport

Returns

Promise<{ jobId: number; }>

The queued job ID on success.

Throws

If the job cannot be queued (status is reverted first).

Last updated on