@twin.org/background-task-scheduler 0.0.3-next.4 → 0.0.3-next.5

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN Background Task Scheduler
2
2
 
3
- Schedule background tasks to run at a specific interval or time.
3
+ This package is part of the background task toolkit and helps build reliable asynchronous workflows in TWIN applications.
4
4
 
5
5
  ## Installation
6
6
 
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.5](https://github.com/twinfoundation/background-task/compare/background-task-scheduler-v0.0.3-next.4...background-task-scheduler-v0.0.3-next.5) (2026-04-10)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **background-task-scheduler:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/background-task-models bumped from 0.0.3-next.4 to 0.0.3-next.5
16
+
3
17
  ## [0.0.3-next.4](https://github.com/twinfoundation/background-task/compare/background-task-scheduler-v0.0.3-next.3...background-task-scheduler-v0.0.3-next.4) (2026-02-23)
4
18
 
5
19
 
@@ -269,4 +283,4 @@
269
283
  * dependencies
270
284
  * @twin.org/background-task-models bumped from 0.0.1-next.18 to 0.0.1-next.19
271
285
 
272
- ## @twin.org/background-task-scheduler - Changelog
286
+ ## Changelog
package/docs/examples.md CHANGED
@@ -1 +1,95 @@
1
- # @twin.org/background-task-scheduler - Examples
1
+ # Background Task Scheduler Examples
2
+
3
+ Use these snippets to configure recurring schedules and monitor trigger state for background work.
4
+
5
+ ## TaskSchedulerService
6
+
7
+ ```typescript
8
+ import { TaskSchedulerService } from '@twin.org/background-task-scheduler';
9
+
10
+ const scheduler = new TaskSchedulerService({
11
+ config: {
12
+ intervalMs: 10000,
13
+ stalledTaskTimeoutMs: 120000
14
+ }
15
+ });
16
+
17
+ console.log(scheduler.className()); // TaskSchedulerService
18
+ ```
19
+
20
+ ```typescript
21
+ import { TaskSchedulerService } from '@twin.org/background-task-scheduler';
22
+
23
+ const scheduler = new TaskSchedulerService();
24
+ const taskId = 'report-refresh';
25
+
26
+ await scheduler.addTask(
27
+ taskId,
28
+ [
29
+ {
30
+ nextTriggerTime: Date.now() + 5000,
31
+ intervalMinutes: 10
32
+ },
33
+ {
34
+ nextTriggerTime: Date.now() + 30000,
35
+ intervalHours: 1
36
+ }
37
+ ],
38
+ async () => {
39
+ const runAt = new Date().toISOString();
40
+ console.log('report-refresh runAt', runAt); // report-refresh runAt 2026-03-09T10:45:05.000Z
41
+ }
42
+ );
43
+
44
+ const info = await scheduler.tasksInfo();
45
+ console.log(info.tasks[taskId].length); // 2
46
+ ```
47
+
48
+ ```typescript
49
+ import { TaskSchedulerService } from '@twin.org/background-task-scheduler';
50
+
51
+ const scheduler = new TaskSchedulerService();
52
+ const taskId = 'cache-prune';
53
+
54
+ await scheduler.addTask(
55
+ taskId,
56
+ [
57
+ {
58
+ nextTriggerTime: Date.now() + 1000,
59
+ intervalMinutes: 5
60
+ }
61
+ ],
62
+ async () => {
63
+ const runAt = new Date().toISOString();
64
+ console.log('cache-prune runAt', runAt); // cache-prune runAt 2026-03-09T10:45:01.000Z
65
+ }
66
+ );
67
+
68
+ await scheduler.removeTask(taskId);
69
+
70
+ const infoAfterRemoval = await scheduler.tasksInfo();
71
+ console.log(taskId in infoAfterRemoval.tasks); // false
72
+
73
+ await scheduler.stop();
74
+ ```
75
+
76
+ ## ScheduledTask
77
+
78
+ ```typescript
79
+ import { ScheduledTask } from '@twin.org/background-task-scheduler';
80
+
81
+ const scheduledTask = new ScheduledTask();
82
+ scheduledTask.id = 'nightly-index';
83
+ scheduledTask.lastRunTime = Date.now();
84
+
85
+ console.log(scheduledTask.id); // nightly-index
86
+ console.log(typeof scheduledTask.lastRunTime); // number
87
+ ```
88
+
89
+ ## initSchema
90
+
91
+ ```typescript
92
+ import { initSchema } from '@twin.org/background-task-scheduler';
93
+
94
+ initSchema();
95
+ ```
@@ -14,7 +14,7 @@ Class defining a scheduled task.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### id
17
+ ### id {#id}
18
18
 
19
19
  > **id**: `string`
20
20
 
@@ -22,8 +22,8 @@ The id.
22
22
 
23
23
  ***
24
24
 
25
- ### lastRunTime?
25
+ ### lastRunTime? {#lastruntime}
26
26
 
27
- > `optional` **lastRunTime**: `number`
27
+ > `optional` **lastRunTime?**: `number`
28
28
 
29
29
  The last run time of the task, if undefined waiting for next run.
@@ -28,7 +28,7 @@ The options for the scheduler.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
- ### className()
39
+ ### className() {#classname}
40
40
 
41
41
  > **className**(): `string`
42
42
 
@@ -54,7 +54,7 @@ The class name of the component.
54
54
 
55
55
  ***
56
56
 
57
- ### stop()
57
+ ### stop() {#stop}
58
58
 
59
59
  > **stop**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
60
60
 
@@ -80,7 +80,7 @@ Nothing.
80
80
 
81
81
  ***
82
82
 
83
- ### addTask()
83
+ ### addTask() {#addtask}
84
84
 
85
85
  > **addTask**(`taskId`, `times`, `taskCallback`): `Promise`\<`void`\>
86
86
 
@@ -118,7 +118,7 @@ Nothing.
118
118
 
119
119
  ***
120
120
 
121
- ### removeTask()
121
+ ### removeTask() {#removetask}
122
122
 
123
123
  > **removeTask**(`taskId`): `Promise`\<`void`\>
124
124
 
@@ -144,7 +144,7 @@ Nothing.
144
144
 
145
145
  ***
146
146
 
147
- ### tasksInfo()
147
+ ### tasksInfo() {#tasksinfo}
148
148
 
149
149
  > **tasksInfo**(): `Promise`\<`IScheduledTaskInfo`\>
150
150
 
@@ -4,9 +4,9 @@ Interface for the task scheduler configuration.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### intervalMs?
7
+ ### intervalMs? {#intervalms}
8
8
 
9
- > `optional` **intervalMs**: `number`
9
+ > `optional` **intervalMs?**: `number`
10
10
 
11
11
  The interval between checks for running tasks, defaults to 1 minute since that is the resolution of the tasks.
12
12
 
@@ -18,9 +18,9 @@ The interval between checks for running tasks, defaults to 1 minute since that i
18
18
 
19
19
  ***
20
20
 
21
- ### stalledTaskTimeoutMs?
21
+ ### stalledTaskTimeoutMs? {#stalledtasktimeoutms}
22
22
 
23
- > `optional` **stalledTaskTimeoutMs**: `number`
23
+ > `optional` **stalledTaskTimeoutMs?**: `number`
24
24
 
25
25
  The time in milliseconds after which a task that is still marked as running is considered stalled and can be run again.
26
26
 
@@ -4,9 +4,9 @@ Options for the task scheduler constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### loggingComponentType?
7
+ ### loggingComponentType? {#loggingcomponenttype}
8
8
 
9
- > `optional` **loggingComponentType**: `string`
9
+ > `optional` **loggingComponentType?**: `string`
10
10
 
11
11
  The logging component type.
12
12
 
@@ -18,9 +18,9 @@ logging
18
18
 
19
19
  ***
20
20
 
21
- ### scheduledTaskEntityStorageType?
21
+ ### scheduledTaskEntityStorageType? {#scheduledtaskentitystoragetype}
22
22
 
23
- > `optional` **scheduledTaskEntityStorageType**: `string`
23
+ > `optional` **scheduledTaskEntityStorageType?**: `string`
24
24
 
25
25
  The scheduled task entity storage connector type.
26
26
 
@@ -32,8 +32,8 @@ scheduled-task
32
32
 
33
33
  ***
34
34
 
35
- ### config?
35
+ ### config? {#config}
36
36
 
37
- > `optional` **config**: [`ITaskSchedulerConfig`](ITaskSchedulerConfig.md)
37
+ > `optional` **config?**: [`ITaskSchedulerConfig`](ITaskSchedulerConfig.md)
38
38
 
39
39
  The configuration for the task scheduler.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/background-task-scheduler",
3
- "version": "0.0.3-next.4",
4
- "description": "Background task scheduler",
3
+ "version": "0.0.3-next.5",
4
+ "description": "Schedules background tasks for one-off or recurring execution windows",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/background-task.git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/background-task-models": "0.0.3-next.4",
17
+ "@twin.org/background-task-models": "0.0.3-next.5",
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/entity-storage-models": "next",
20
20
  "@twin.org/logging-models": "next",