@twin.org/background-task-scheduler 0.9.1 → 0.9.2-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -172,17 +172,25 @@ export class TaskSchedulerService {
172
172
  */
173
173
  calculateNextTriggerTime(time) {
174
174
  let nextTriggerTime = time.nextTriggerTime;
175
+ const dayMs = 24 * 60 * 60 * 1000;
176
+ const hourMs = 60 * 60 * 1000;
177
+ const minuteMs = 60 * 1000;
175
178
  if (Is.empty(nextTriggerTime)) {
176
179
  nextTriggerTime = Date.now();
177
180
  }
178
- if (!Is.empty(time.intervalDays)) {
179
- nextTriggerTime += time.intervalDays * 24 * 60 * 60 * 1000;
180
- }
181
- if (!Is.empty(time.intervalHours)) {
182
- nextTriggerTime += time.intervalHours * 60 * 60 * 1000;
183
- }
184
- if (!Is.empty(time.intervalMinutes)) {
185
- nextTriggerTime += time.intervalMinutes * 60 * 1000;
181
+ let intervalMs = 0;
182
+ intervalMs += (time.intervalDays ?? 0) * dayMs;
183
+ intervalMs += (time.intervalHours ?? 0) * hourMs;
184
+ intervalMs += (time.intervalMinutes ?? 0) * minuteMs;
185
+ if (intervalMs > 0) {
186
+ // Move to the next regular slot and, if that slot is already in the past,
187
+ // skip missed slots so the next trigger is strictly in the future.
188
+ nextTriggerTime += intervalMs;
189
+ const now = Date.now();
190
+ if (nextTriggerTime <= now) {
191
+ const intervalsToAdvance = Math.floor((now - nextTriggerTime) / intervalMs) + 1;
192
+ nextTriggerTime += intervalsToAdvance * intervalMs;
193
+ }
186
194
  }
187
195
  return nextTriggerTime;
188
196
  }
@@ -1 +1 @@
1
- {"version":3,"file":"taskSchedulerService.js","sourceRoot":"","sources":["../../src/taskSchedulerService.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAMzC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E,MAAM;gCACV,WAAW,EAAE,SAAS;6BACtB,CAAC,CAAC;4BAEH,8CAA8C;4BAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;4BACjD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gCAChB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;4BACrC,CAAC;wBACF,CAAC;oBACF,CAAC;oBAED,oEAAoE;oBACpE,IACC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC;wBAC/B,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;wBAChC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,eAAe,CAAC,EACjC,CAAC;wBACF,QAAQ,CAAC,eAAe,GAAG,SAAS,CAAC;oBACtC,CAAC;yBAAM,CAAC;wBACP,4EAA4E;wBAC5E,QAAQ,CAAC,eAAe,GAAG,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC;oBACpE,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIScheduledTaskInfo,\n\tIScheduledTaskTime,\n\tITaskSchedulerComponent\n} from \"@twin.org/background-task-models\";\nimport { BaseError, ComponentFactory, Is } from \"@twin.org/core\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { ScheduledTask } from \"./entities/scheduledTask.js\";\nimport type { ITaskSchedulerConstructorOptions } from \"./models/ITaskSchedulerConstructorOptions.js\";\n\n/**\n * Class for scheduling tasks.\n */\nexport class TaskSchedulerService implements ITaskSchedulerComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TaskSchedulerService>();\n\n\t/**\n\t * The logger for the task service.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The entity storage for the scheduled tasks.\n\t * @internal\n\t */\n\tprivate readonly _scheduledTaskEntityStorageConnector: IEntityStorageConnector<ScheduledTask>;\n\n\t/**\n\t * The interval in milliseconds at which the tasks are checked.\n\t * @internal\n\t */\n\tprivate readonly _tickIntervalMs: number;\n\n\t/**\n\t * The timeout in milliseconds after which an in-progress task is considered stalled.\n\t * @internal\n\t */\n\tprivate readonly _stalledTaskTimeoutMs: number;\n\n\t/**\n\t * The tasks that are scheduled.\n\t * @internal\n\t */\n\tprivate readonly _tasks: {\n\t\t[id: string]: {\n\t\t\ttimes: IScheduledTaskTime[];\n\t\t\ttaskCallback: () => Promise<void>;\n\t\t};\n\t};\n\n\t/**\n\t * The tasks currently running in this scheduler instance.\n\t * @internal\n\t */\n\tprivate _runningTasks: string[];\n\n\t/**\n\t * The timer for running scheduled tasks.\n\t * @internal\n\t */\n\tprivate _timer?: ReturnType<typeof setInterval>;\n\n\t/**\n\t * Whether the scheduler has been started.\n\t * @internal\n\t */\n\tprivate _started: boolean;\n\n\t/**\n\t * Create a new instance of TaskSchedulerComponent.\n\t * @param options The options for the scheduler.\n\t */\n\tconstructor(options?: ITaskSchedulerConstructorOptions) {\n\t\tthis._scheduledTaskEntityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.scheduledTaskEntityStorageType ?? \"scheduled-task\"\n\t\t);\n\t\tthis._logging = ComponentFactory.getIfExists(options?.loggingComponentType);\n\t\tthis._tasks = {};\n\t\tthis._runningTasks = [];\n\t\tthis._started = false;\n\t\tthis._tickIntervalMs = options?.config?.intervalMs ?? 60 * 1000; // 1 minute\n\t\tthis._stalledTaskTimeoutMs = options?.config?.stalledTaskTimeoutMs ?? 5 * 60 * 1000; // 5 minutes\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TaskSchedulerService.CLASS_NAME;\n\t}\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the service has started and pending tasks are being processed\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (!this._started) {\n\t\t\tthis._started = true;\n\t\t\tif (Object.keys(this._tasks).length > 0) {\n\t\t\t\tawait this.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The component needs to be stopped when the node is closed.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the scheduler has stopped and in-flight tasks have been reset\n\t */\n\tpublic async stop(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (this._started) {\n\t\t\tthis._started = false;\n\t\t\tthis.stopTimer();\n\n\t\t\t// If we had any running tasks, we reset their last run time to allow them to be\n\t\t\t// triggered by other components\n\t\t\tfor (const taskId of this._runningTasks) {\n\t\t\t\tawait this._scheduledTaskEntityStorageConnector.set({\n\t\t\t\t\tid: taskId,\n\t\t\t\t\tlastRunTime: undefined\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._runningTasks = [];\n\t\t}\n\t}\n\n\t/**\n\t * Add a task to the scheduler.\n\t * @param taskId The id of the task to add.\n\t * @param times The times at which the task should be scheduled.\n\t * @param taskCallback The callback to execute when the task is scheduled.\n\t * @returns A promise that resolves when the task has been registered and the scheduler timer started\n\t */\n\tpublic async addTask(\n\t\ttaskId: string,\n\t\ttimes: IScheduledTaskTime[],\n\t\ttaskCallback: () => Promise<void>\n\t): Promise<void> {\n\t\tthis._tasks[taskId] = {\n\t\t\ttimes: times.map(time => ({\n\t\t\t\t...time,\n\t\t\t\tnextTriggerTime: Is.empty(time.nextTriggerTime)\n\t\t\t\t\t? this.calculateNextTriggerTime(time)\n\t\t\t\t\t: time.nextTriggerTime\n\t\t\t})),\n\t\t\ttaskCallback\n\t\t};\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"taskAdded\",\n\t\t\tdata: {\n\t\t\t\tid: taskId\n\t\t\t}\n\t\t});\n\n\t\tawait this.startTimer();\n\t}\n\n\t/**\n\t * Remove a task from the scheduler.\n\t * @param taskId The id of the task to remove.\n\t * @returns A promise that resolves when the task has been removed\n\t */\n\tpublic async removeTask(taskId: string): Promise<void> {\n\t\tif (!Is.empty(this._tasks[taskId])) {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"taskRemoved\",\n\t\t\t\tdata: {\n\t\t\t\t\tid: taskId\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tdelete this._tasks[taskId];\n\n\t\t\tif (Object.keys(this._tasks).length === 0) {\n\t\t\t\tthis.stopTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the information about the tasks.\n\t * @returns The tasks information.\n\t */\n\tpublic async tasksInfo(): Promise<IScheduledTaskInfo> {\n\t\tconst tasksInfo: IScheduledTaskInfo = {\n\t\t\ttasks: {}\n\t\t};\n\t\tfor (const taskId in this._tasks) {\n\t\t\ttasksInfo.tasks[taskId] = this._tasks[taskId].times;\n\t\t}\n\t\treturn tasksInfo;\n\t}\n\n\t/**\n\t * Calculate the next run time for a task based on its scheduled times.\n\t * @param time The times at which the task should be scheduled.\n\t * @returns The update time with the next run.\n\t * @internal\n\t */\n\tprivate calculateNextTriggerTime(time: IScheduledTaskTime): number {\n\t\tlet nextTriggerTime = time.nextTriggerTime;\n\n\t\tif (Is.empty(nextTriggerTime)) {\n\t\t\tnextTriggerTime = Date.now();\n\t\t}\n\n\t\tif (!Is.empty(time.intervalDays)) {\n\t\t\tnextTriggerTime += time.intervalDays * 24 * 60 * 60 * 1000;\n\t\t}\n\n\t\tif (!Is.empty(time.intervalHours)) {\n\t\t\tnextTriggerTime += time.intervalHours * 60 * 60 * 1000;\n\t\t}\n\n\t\tif (!Is.empty(time.intervalMinutes)) {\n\t\t\tnextTriggerTime += time.intervalMinutes * 60 * 1000;\n\t\t}\n\n\t\treturn nextTriggerTime;\n\t}\n\n\t/**\n\t * Start the timer for running scheduled tasks.\n\t * @returns A promise that resolves when the timer has been started and any immediately due tasks triggered\n\t * @internal\n\t */\n\tprivate async startTimer(): Promise<void> {\n\t\tif (Is.empty(this._timer) && this._started) {\n\t\t\t// Trigger immediately to catch up on any missed tasks\n\t\t\tawait this.triggerScheduledTasks();\n\t\t\t// Re-check after the await: stop() may have been called while triggerScheduledTasks() was running.\n\t\t\t// At that point _timer was still undefined so stopTimer() was a no-op — without this guard,\n\t\t\t// setInterval would create a timer that is never cleaned up.\n\t\t\tif (this._started) {\n\t\t\t\tthis._timer = globalThis.setInterval(async () => {\n\t\t\t\t\tif (this._started) {\n\t\t\t\t\t\tawait this.triggerScheduledTasks();\n\t\t\t\t\t}\n\t\t\t\t}, this._tickIntervalMs);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Stop the timer for running scheduled tasks.\n\t * @internal\n\t */\n\tprivate stopTimer(): void {\n\t\tif (!Is.empty(this._timer)) {\n\t\t\tglobalThis.clearInterval(this._timer);\n\t\t\tthis._timer = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Trigger scheduled tasks based on their next run times.\n\t * @returns A promise that resolves when all due tasks have been triggered and their next trigger times updated\n\t * @internal\n\t */\n\tprivate async triggerScheduledTasks(): Promise<void> {\n\t\tconst now = Date.now();\n\n\t\tfor (const taskId in this._tasks) {\n\t\t\tconst task = this._tasks[taskId];\n\n\t\t\tfor (const taskTime of task.times) {\n\t\t\t\tif (!Is.empty(taskTime.nextTriggerTime) && taskTime.nextTriggerTime <= now) {\n\t\t\t\t\tlet taskStarted = false;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst scheduledTask = await this._scheduledTaskEntityStorageConnector.get(taskId);\n\t\t\t\t\t\tconst lastRunTime = scheduledTask?.lastRunTime;\n\t\t\t\t\t\tconst taskInProgress = !Is.empty(lastRunTime);\n\t\t\t\t\t\tconst taskStalled = taskInProgress && now - lastRunTime >= this._stalledTaskTimeoutMs;\n\n\t\t\t\t\t\tif (taskStalled) {\n\t\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\t\tlevel: \"warn\",\n\t\t\t\t\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\t\tmessage: \"taskStalled\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\t\tlastRunTime,\n\t\t\t\t\t\t\t\t\tstalledForMs: now - (lastRunTime ?? now),\n\t\t\t\t\t\t\t\t\tstalledTaskTimeoutMs: this._stalledTaskTimeoutMs\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!taskInProgress || taskStalled) {\n\t\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\t\tmessage: \"taskTriggered\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\t\ttime: new Date(taskTime.nextTriggerTime).toISOString()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// Update the last run time of the task to prevent multiple triggers in case of long running tasks\n\t\t\t\t\t\t\tawait this._scheduledTaskEntityStorageConnector.set({\n\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\tlastRunTime: Date.now()\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (!this._runningTasks.includes(taskId)) {\n\t\t\t\t\t\t\t\tthis._runningTasks.push(taskId);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttaskStarted = true;\n\t\t\t\t\t\t\tawait task.taskCallback();\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\tmessage: \"taskFailed\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tid: taskId\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\terror: BaseError.fromError(error)\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (taskStarted) {\n\t\t\t\t\t\t\t// Reset the last run time to allow future triggers, even if the task callback fails\n\t\t\t\t\t\t\tawait this._scheduledTaskEntityStorageConnector.set({\n\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\tlastRunTime: undefined\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// Remove the task from the running tasks list\n\t\t\t\t\t\t\tconst index = this._runningTasks.indexOf(taskId);\n\t\t\t\t\t\t\tif (index >= 0) {\n\t\t\t\t\t\t\t\tthis._runningTasks.splice(index, 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the intervals are empty, we do not recalculate a next run time\n\t\t\t\t\tif (\n\t\t\t\t\t\tIs.empty(taskTime.intervalDays) &&\n\t\t\t\t\t\tIs.empty(taskTime.intervalHours) &&\n\t\t\t\t\t\tIs.empty(taskTime.intervalMinutes)\n\t\t\t\t\t) {\n\t\t\t\t\t\ttaskTime.nextTriggerTime = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Recalculate the next run time based on the current time and the intervals\n\t\t\t\t\t\ttaskTime.nextTriggerTime = this.calculateNextTriggerTime(taskTime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"taskSchedulerService.js","sourceRoot":"","sources":["../../src/taskSchedulerService.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAMzC;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,oCAAoC,CAAyC;IAE9F;;;OAGG;IACc,eAAe,CAAS;IAEzC;;;OAGG;IACc,qBAAqB,CAAS;IAE/C;;;OAGG;IACc,MAAM,CAKrB;IAEF;;;OAGG;IACK,aAAa,CAAW;IAEhC;;;OAGG;IACK,MAAM,CAAkC;IAEhD;;;OAGG;IACK,QAAQ,CAAU;IAE1B;;;OAGG;IACH,YAAY,OAA0C;QACrD,IAAI,CAAC,oCAAoC,GAAG,6BAA6B,CAAC,GAAG,CAC5E,OAAO,EAAE,8BAA8B,IAAI,gBAAgB,CAC3D,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;QAC5E,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,eAAe,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,WAAW;QAC5E,IAAI,CAAC,qBAAqB,GAAG,OAAO,EAAE,MAAM,EAAE,oBAAoB,I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AS,CAAC;oBACtC,CAAC;yBAAM,CAAC;wBACP,4EAA4E;wBAC5E,QAAQ,CAAC,eAAe,GAAG,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC;oBACpE,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIScheduledTaskInfo,\n\tIScheduledTaskTime,\n\tITaskSchedulerComponent\n} from \"@twin.org/background-task-models\";\nimport { BaseError, ComponentFactory, Is } from \"@twin.org/core\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { ScheduledTask } from \"./entities/scheduledTask.js\";\nimport type { ITaskSchedulerConstructorOptions } from \"./models/ITaskSchedulerConstructorOptions.js\";\n\n/**\n * Class for scheduling tasks.\n */\nexport class TaskSchedulerService implements ITaskSchedulerComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TaskSchedulerService>();\n\n\t/**\n\t * The logger for the task service.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The entity storage for the scheduled tasks.\n\t * @internal\n\t */\n\tprivate readonly _scheduledTaskEntityStorageConnector: IEntityStorageConnector<ScheduledTask>;\n\n\t/**\n\t * The interval in milliseconds at which the tasks are checked.\n\t * @internal\n\t */\n\tprivate readonly _tickIntervalMs: number;\n\n\t/**\n\t * The timeout in milliseconds after which an in-progress task is considered stalled.\n\t * @internal\n\t */\n\tprivate readonly _stalledTaskTimeoutMs: number;\n\n\t/**\n\t * The tasks that are scheduled.\n\t * @internal\n\t */\n\tprivate readonly _tasks: {\n\t\t[id: string]: {\n\t\t\ttimes: IScheduledTaskTime[];\n\t\t\ttaskCallback: () => Promise<void>;\n\t\t};\n\t};\n\n\t/**\n\t * The tasks currently running in this scheduler instance.\n\t * @internal\n\t */\n\tprivate _runningTasks: string[];\n\n\t/**\n\t * The timer for running scheduled tasks.\n\t * @internal\n\t */\n\tprivate _timer?: ReturnType<typeof setInterval>;\n\n\t/**\n\t * Whether the scheduler has been started.\n\t * @internal\n\t */\n\tprivate _started: boolean;\n\n\t/**\n\t * Create a new instance of TaskSchedulerComponent.\n\t * @param options The options for the scheduler.\n\t */\n\tconstructor(options?: ITaskSchedulerConstructorOptions) {\n\t\tthis._scheduledTaskEntityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.scheduledTaskEntityStorageType ?? \"scheduled-task\"\n\t\t);\n\t\tthis._logging = ComponentFactory.getIfExists(options?.loggingComponentType);\n\t\tthis._tasks = {};\n\t\tthis._runningTasks = [];\n\t\tthis._started = false;\n\t\tthis._tickIntervalMs = options?.config?.intervalMs ?? 60 * 1000; // 1 minute\n\t\tthis._stalledTaskTimeoutMs = options?.config?.stalledTaskTimeoutMs ?? 5 * 60 * 1000; // 5 minutes\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TaskSchedulerService.CLASS_NAME;\n\t}\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the service has started and pending tasks are being processed\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (!this._started) {\n\t\t\tthis._started = true;\n\t\t\tif (Object.keys(this._tasks).length > 0) {\n\t\t\t\tawait this.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * The component needs to be stopped when the node is closed.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the scheduler has stopped and in-flight tasks have been reset\n\t */\n\tpublic async stop(nodeLoggingComponentType?: string): Promise<void> {\n\t\tif (this._started) {\n\t\t\tthis._started = false;\n\t\t\tthis.stopTimer();\n\n\t\t\t// If we had any running tasks, we reset their last run time to allow them to be\n\t\t\t// triggered by other components\n\t\t\tfor (const taskId of this._runningTasks) {\n\t\t\t\tawait this._scheduledTaskEntityStorageConnector.set({\n\t\t\t\t\tid: taskId,\n\t\t\t\t\tlastRunTime: undefined\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._runningTasks = [];\n\t\t}\n\t}\n\n\t/**\n\t * Add a task to the scheduler.\n\t * @param taskId The id of the task to add.\n\t * @param times The times at which the task should be scheduled.\n\t * @param taskCallback The callback to execute when the task is scheduled.\n\t * @returns A promise that resolves when the task has been registered and the scheduler timer started\n\t */\n\tpublic async addTask(\n\t\ttaskId: string,\n\t\ttimes: IScheduledTaskTime[],\n\t\ttaskCallback: () => Promise<void>\n\t): Promise<void> {\n\t\tthis._tasks[taskId] = {\n\t\t\ttimes: times.map(time => ({\n\t\t\t\t...time,\n\t\t\t\tnextTriggerTime: Is.empty(time.nextTriggerTime)\n\t\t\t\t\t? this.calculateNextTriggerTime(time)\n\t\t\t\t\t: time.nextTriggerTime\n\t\t\t})),\n\t\t\ttaskCallback\n\t\t};\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: \"taskAdded\",\n\t\t\tdata: {\n\t\t\t\tid: taskId\n\t\t\t}\n\t\t});\n\n\t\tawait this.startTimer();\n\t}\n\n\t/**\n\t * Remove a task from the scheduler.\n\t * @param taskId The id of the task to remove.\n\t * @returns A promise that resolves when the task has been removed\n\t */\n\tpublic async removeTask(taskId: string): Promise<void> {\n\t\tif (!Is.empty(this._tasks[taskId])) {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"taskRemoved\",\n\t\t\t\tdata: {\n\t\t\t\t\tid: taskId\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tdelete this._tasks[taskId];\n\n\t\t\tif (Object.keys(this._tasks).length === 0) {\n\t\t\t\tthis.stopTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the information about the tasks.\n\t * @returns The tasks information.\n\t */\n\tpublic async tasksInfo(): Promise<IScheduledTaskInfo> {\n\t\tconst tasksInfo: IScheduledTaskInfo = {\n\t\t\ttasks: {}\n\t\t};\n\t\tfor (const taskId in this._tasks) {\n\t\t\ttasksInfo.tasks[taskId] = this._tasks[taskId].times;\n\t\t}\n\t\treturn tasksInfo;\n\t}\n\n\t/**\n\t * Calculate the next run time for a task based on its scheduled times.\n\t * @param time The times at which the task should be scheduled.\n\t * @returns The update time with the next run.\n\t * @internal\n\t */\n\tprivate calculateNextTriggerTime(time: IScheduledTaskTime): number {\n\t\tlet nextTriggerTime = time.nextTriggerTime;\n\t\tconst dayMs = 24 * 60 * 60 * 1000;\n\t\tconst hourMs = 60 * 60 * 1000;\n\t\tconst minuteMs = 60 * 1000;\n\n\t\tif (Is.empty(nextTriggerTime)) {\n\t\t\tnextTriggerTime = Date.now();\n\t\t}\n\n\t\tlet intervalMs = 0;\n\t\tintervalMs += (time.intervalDays ?? 0) * dayMs;\n\t\tintervalMs += (time.intervalHours ?? 0) * hourMs;\n\t\tintervalMs += (time.intervalMinutes ?? 0) * minuteMs;\n\n\t\tif (intervalMs > 0) {\n\t\t\t// Move to the next regular slot and, if that slot is already in the past,\n\t\t\t// skip missed slots so the next trigger is strictly in the future.\n\t\t\tnextTriggerTime += intervalMs;\n\t\t\tconst now = Date.now();\n\t\t\tif (nextTriggerTime <= now) {\n\t\t\t\tconst intervalsToAdvance = Math.floor((now - nextTriggerTime) / intervalMs) + 1;\n\t\t\t\tnextTriggerTime += intervalsToAdvance * intervalMs;\n\t\t\t}\n\t\t}\n\n\t\treturn nextTriggerTime;\n\t}\n\n\t/**\n\t * Start the timer for running scheduled tasks.\n\t * @returns A promise that resolves when the timer has been started and any immediately due tasks triggered\n\t * @internal\n\t */\n\tprivate async startTimer(): Promise<void> {\n\t\tif (Is.empty(this._timer) && this._started) {\n\t\t\t// Trigger immediately to catch up on any missed tasks\n\t\t\tawait this.triggerScheduledTasks();\n\t\t\t// Re-check after the await: stop() may have been called while triggerScheduledTasks() was running.\n\t\t\t// At that point _timer was still undefined so stopTimer() was a no-op — without this guard,\n\t\t\t// setInterval would create a timer that is never cleaned up.\n\t\t\tif (this._started) {\n\t\t\t\tthis._timer = globalThis.setInterval(async () => {\n\t\t\t\t\tif (this._started) {\n\t\t\t\t\t\tawait this.triggerScheduledTasks();\n\t\t\t\t\t}\n\t\t\t\t}, this._tickIntervalMs);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Stop the timer for running scheduled tasks.\n\t * @internal\n\t */\n\tprivate stopTimer(): void {\n\t\tif (!Is.empty(this._timer)) {\n\t\t\tglobalThis.clearInterval(this._timer);\n\t\t\tthis._timer = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * Trigger scheduled tasks based on their next run times.\n\t * @returns A promise that resolves when all due tasks have been triggered and their next trigger times updated\n\t * @internal\n\t */\n\tprivate async triggerScheduledTasks(): Promise<void> {\n\t\tconst now = Date.now();\n\n\t\tfor (const taskId in this._tasks) {\n\t\t\tconst task = this._tasks[taskId];\n\n\t\t\tfor (const taskTime of task.times) {\n\t\t\t\tif (!Is.empty(taskTime.nextTriggerTime) && taskTime.nextTriggerTime <= now) {\n\t\t\t\t\tlet taskStarted = false;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst scheduledTask = await this._scheduledTaskEntityStorageConnector.get(taskId);\n\t\t\t\t\t\tconst lastRunTime = scheduledTask?.lastRunTime;\n\t\t\t\t\t\tconst taskInProgress = !Is.empty(lastRunTime);\n\t\t\t\t\t\tconst taskStalled = taskInProgress && now - lastRunTime >= this._stalledTaskTimeoutMs;\n\n\t\t\t\t\t\tif (taskStalled) {\n\t\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\t\tlevel: \"warn\",\n\t\t\t\t\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\t\tmessage: \"taskStalled\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\t\tlastRunTime,\n\t\t\t\t\t\t\t\t\tstalledForMs: now - (lastRunTime ?? now),\n\t\t\t\t\t\t\t\t\tstalledTaskTimeoutMs: this._stalledTaskTimeoutMs\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!taskInProgress || taskStalled) {\n\t\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\t\tmessage: \"taskTriggered\",\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\t\ttime: new Date(taskTime.nextTriggerTime).toISOString()\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// Update the last run time of the task to prevent multiple triggers in case of long running tasks\n\t\t\t\t\t\t\tawait this._scheduledTaskEntityStorageConnector.set({\n\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\tlastRunTime: Date.now()\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tif (!this._runningTasks.includes(taskId)) {\n\t\t\t\t\t\t\t\tthis._runningTasks.push(taskId);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttaskStarted = true;\n\t\t\t\t\t\t\tawait task.taskCallback();\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\t\t\tsource: TaskSchedulerService.CLASS_NAME,\n\t\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\t\tmessage: \"taskFailed\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tid: taskId\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\terror: BaseError.fromError(error)\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (taskStarted) {\n\t\t\t\t\t\t\t// Reset the last run time to allow future triggers, even if the task callback fails\n\t\t\t\t\t\t\tawait this._scheduledTaskEntityStorageConnector.set({\n\t\t\t\t\t\t\t\tid: taskId,\n\t\t\t\t\t\t\t\tlastRunTime: undefined\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// Remove the task from the running tasks list\n\t\t\t\t\t\t\tconst index = this._runningTasks.indexOf(taskId);\n\t\t\t\t\t\t\tif (index >= 0) {\n\t\t\t\t\t\t\t\tthis._runningTasks.splice(index, 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the intervals are empty, we do not recalculate a next run time\n\t\t\t\t\tif (\n\t\t\t\t\t\tIs.empty(taskTime.intervalDays) &&\n\t\t\t\t\t\tIs.empty(taskTime.intervalHours) &&\n\t\t\t\t\t\tIs.empty(taskTime.intervalMinutes)\n\t\t\t\t\t) {\n\t\t\t\t\t\ttaskTime.nextTriggerTime = undefined;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Recalculate the next run time based on the current time and the intervals\n\t\t\t\t\t\ttaskTime.nextTriggerTime = this.calculateNextTriggerTime(taskTime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.2-next.2](https://github.com/iotaledger/twin-background-task/compare/background-task-scheduler-v0.9.2-next.1...background-task-scheduler-v0.9.2-next.2) (2026-07-30)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * single idle trigger ([#98](https://github.com/iotaledger/twin-background-task/issues/98)) ([eaef7dd](https://github.com/iotaledger/twin-background-task/commit/eaef7dd43ce59bad430eaf31cd5530ed2f6cb4c2))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/background-task-models bumped from 0.9.2-next.1 to 0.9.2-next.2
16
+
17
+ ## [0.9.2-next.1](https://github.com/iotaledger/twin-background-task/compare/background-task-scheduler-v0.9.2-next.0...background-task-scheduler-v0.9.2-next.1) (2026-07-28)
18
+
19
+
20
+ ### Features
21
+
22
+ * add context id features ([#29](https://github.com/iotaledger/twin-background-task/issues/29)) ([46ede49](https://github.com/iotaledger/twin-background-task/commit/46ede49a51a4955fe1530e645a66f0073db9a1fd))
23
+ * add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
24
+ * add validate-locales ([968cbf9](https://github.com/iotaledger/twin-background-task/commit/968cbf966fffb5060305e8b221fecc0b6c8105b9))
25
+ * background tasks immediately trigger ([a0a847b](https://github.com/iotaledger/twin-background-task/commit/a0a847ba9686adcd0460e810540959f87dcaeab1))
26
+ * eslint migration to flat config ([6c9136c](https://github.com/iotaledger/twin-background-task/commit/6c9136c37bccdbbd109892d1503660aab7080d49))
27
+ * multi-instance lock ([#39](https://github.com/iotaledger/twin-background-task/issues/39)) ([7dcd434](https://github.com/iotaledger/twin-background-task/commit/7dcd434da5e3d1645b6fcd19ed34be4e628e50de))
28
+ * remove default logging ([ca9599a](https://github.com/iotaledger/twin-background-task/commit/ca9599aca7ef0375a20e19e0881eaa0e7a2cd7ac))
29
+ * remove unused parameters ([1028b3c](https://github.com/iotaledger/twin-background-task/commit/1028b3cc147c25da22a8ba8d7207acfb34f89cdb))
30
+ * rename task scheduler component ([2f8aa59](https://github.com/iotaledger/twin-background-task/commit/2f8aa59c069055ff020a3c0c149601f20c656022))
31
+ * rename task scheduler component to service ([f097a98](https://github.com/iotaledger/twin-background-task/commit/f097a988c9ee0795aa55d74deda616365ec4ffb1))
32
+ * typescript 6 update ([e3f2727](https://github.com/iotaledger/twin-background-task/commit/e3f272783e0de7cf4d31f3e84a8e6f5ff633961b))
33
+ * update dependencies ([0867e02](https://github.com/iotaledger/twin-background-task/commit/0867e02fc3c034f8e8cf5918ac6cc4e6b5ca0c93))
34
+ * update framework core ([a068098](https://github.com/iotaledger/twin-background-task/commit/a0680983d7923a1bfb980a67879019bb870ccc5d))
35
+ * update IComponent signatures ([e1a79bc](https://github.com/iotaledger/twin-background-task/commit/e1a79bc4dd813435c56e376f231a4b4ecd2276bf))
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * cleanup timers ([a0d30b4](https://github.com/iotaledger/twin-background-task/commit/a0d30b4afc485651ed9f1a3e60ad2f307fa3954a))
41
+ * models import ([c830b0d](https://github.com/iotaledger/twin-background-task/commit/c830b0da4deb06f8aeca6fec8988be4da877e73b))
42
+ * resolve timing race in scheduler interval tests ([261b1aa](https://github.com/iotaledger/twin-background-task/commit/261b1aaeef8bd100668be49df689a2abb36f36a6))
43
+ * restore task context in background task state-change callbacks ([#46](https://github.com/iotaledger/twin-background-task/issues/46)) ([d4f9f3b](https://github.com/iotaledger/twin-background-task/commit/d4f9f3bb57f8fb83c62024f9a385c81e2d511920))
44
+ * use async getStore in tests ([97931cd](https://github.com/iotaledger/twin-background-task/commit/97931cdc856e5748b621148737c2eaa14da217fa))
45
+
46
+
47
+ ### Dependencies
48
+
49
+ * The following workspace dependencies were updated
50
+ * dependencies
51
+ * @twin.org/background-task-models bumped from 0.9.2-next.0 to 0.9.2-next.1
52
+
3
53
  ## [0.9.1](https://github.com/iotaledger/twin-background-task/compare/background-task-scheduler-v0.9.1...background-task-scheduler-v0.9.1) (2026-07-27)
4
54
 
5
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/background-task-scheduler",
3
- "version": "0.9.1",
3
+ "version": "0.9.2-next.2",
4
4
  "description": "Schedules background tasks for one-off or recurring execution windows",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,11 +14,11 @@
14
14
  "node": ">=24.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/background-task-models": "^0.9.1",
18
- "@twin.org/core": "^0.9.1",
19
- "@twin.org/entity-storage-models": "^0.9.1",
20
- "@twin.org/logging-models": "^0.9.1",
21
- "@twin.org/nameof": "^0.9.1"
17
+ "@twin.org/background-task-models": "0.9.2-next.2",
18
+ "@twin.org/core": "next",
19
+ "@twin.org/entity-storage-models": "next",
20
+ "@twin.org/logging-models": "next",
21
+ "@twin.org/nameof": "next"
22
22
  },
23
23
  "main": "./dist/es/index.js",
24
24
  "types": "./dist/types/index.d.ts",