@twin.org/background-task-scheduler 0.0.2-next.3 → 0.0.2-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.
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@twin.org/core');
4
- var loggingModels = require('@twin.org/logging-models');
5
4
 
6
5
  /**
7
6
  * Class for scheduling tasks.
@@ -12,7 +11,7 @@ class TaskSchedulerService {
12
11
  */
13
12
  CLASS_NAME = "TaskSchedulerService";
14
13
  /**
15
- * The logger for the task connector.
14
+ * The logger for the task service.
16
15
  * @internal
17
16
  */
18
17
  _logging;
@@ -36,18 +35,18 @@ class TaskSchedulerService {
36
35
  * @param options The options for the scheduler.
37
36
  */
38
37
  constructor(options) {
39
- this._logging = loggingModels.LoggingConnectorFactory.getIfExists(options?.loggingConnectorType ?? "logging");
38
+ this._logging = core.ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
40
39
  this._tasks = {};
41
40
  this._tickInterval = options?.config?.overrideInterval ?? 60 * 1000; // Default to 1 minute
42
41
  }
43
42
  /**
44
43
  * The component needs to be stopped when the node is closed.
45
44
  * @param nodeIdentity The identity of the node stopping the component.
46
- * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
45
+ * @param nodeLoggingComponentType The node logging component type.
47
46
  * @param componentState A persistent state which can be modified by the method.
48
47
  * @returns Nothing.
49
48
  */
50
- async stop(nodeIdentity, nodeLoggingConnectorType, componentState) {
49
+ async stop(nodeIdentity, nodeLoggingComponentType, componentState) {
51
50
  this.stopTimer();
52
51
  }
53
52
  /**
@@ -76,7 +75,7 @@ class TaskSchedulerService {
76
75
  id: taskId
77
76
  }
78
77
  });
79
- this.startTimer();
78
+ await this.startTimer();
80
79
  }
81
80
  /**
82
81
  * Remove a task from the scheduler.
@@ -139,8 +138,11 @@ class TaskSchedulerService {
139
138
  * Start the timer for running scheduled tasks.
140
139
  * @internal
141
140
  */
142
- startTimer() {
141
+ async startTimer() {
143
142
  if (core.Is.empty(this._timer)) {
143
+ // Trigger immediately to catch up on any missed tasks
144
+ await this.triggerScheduledTasks();
145
+ // Set the timer to run at the specified interval
144
146
  this._timer = setInterval(async () => this.triggerScheduledTasks(), this._tickInterval);
145
147
  }
146
148
  }
@@ -1,5 +1,4 @@
1
- import { Is, BaseError } from '@twin.org/core';
2
- import { LoggingConnectorFactory } from '@twin.org/logging-models';
1
+ import { ComponentFactory, Is, BaseError } from '@twin.org/core';
3
2
 
4
3
  /**
5
4
  * Class for scheduling tasks.
@@ -10,7 +9,7 @@ class TaskSchedulerService {
10
9
  */
11
10
  CLASS_NAME = "TaskSchedulerService";
12
11
  /**
13
- * The logger for the task connector.
12
+ * The logger for the task service.
14
13
  * @internal
15
14
  */
16
15
  _logging;
@@ -34,18 +33,18 @@ class TaskSchedulerService {
34
33
  * @param options The options for the scheduler.
35
34
  */
36
35
  constructor(options) {
37
- this._logging = LoggingConnectorFactory.getIfExists(options?.loggingConnectorType ?? "logging");
36
+ this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
38
37
  this._tasks = {};
39
38
  this._tickInterval = options?.config?.overrideInterval ?? 60 * 1000; // Default to 1 minute
40
39
  }
41
40
  /**
42
41
  * The component needs to be stopped when the node is closed.
43
42
  * @param nodeIdentity The identity of the node stopping the component.
44
- * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
43
+ * @param nodeLoggingComponentType The node logging component type.
45
44
  * @param componentState A persistent state which can be modified by the method.
46
45
  * @returns Nothing.
47
46
  */
48
- async stop(nodeIdentity, nodeLoggingConnectorType, componentState) {
47
+ async stop(nodeIdentity, nodeLoggingComponentType, componentState) {
49
48
  this.stopTimer();
50
49
  }
51
50
  /**
@@ -74,7 +73,7 @@ class TaskSchedulerService {
74
73
  id: taskId
75
74
  }
76
75
  });
77
- this.startTimer();
76
+ await this.startTimer();
78
77
  }
79
78
  /**
80
79
  * Remove a task from the scheduler.
@@ -137,8 +136,11 @@ class TaskSchedulerService {
137
136
  * Start the timer for running scheduled tasks.
138
137
  * @internal
139
138
  */
140
- startTimer() {
139
+ async startTimer() {
141
140
  if (Is.empty(this._timer)) {
141
+ // Trigger immediately to catch up on any missed tasks
142
+ await this.triggerScheduledTasks();
143
+ // Set the timer to run at the specified interval
142
144
  this._timer = setInterval(async () => this.triggerScheduledTasks(), this._tickInterval);
143
145
  }
144
146
  }
@@ -4,10 +4,10 @@ import type { ITaskSchedulerConfig } from "./ITaskSchedulerConfig";
4
4
  */
5
5
  export interface ITaskSchedulerConstructorOptions {
6
6
  /**
7
- * The logging connector type.
7
+ * The logging component type.
8
8
  * @default logging
9
9
  */
10
- loggingConnectorType?: string;
10
+ loggingComponentType?: string;
11
11
  /**
12
12
  * The configuration for the task scheduler.
13
13
  */
@@ -16,11 +16,11 @@ export declare class TaskSchedulerService implements ITaskSchedulerComponent {
16
16
  /**
17
17
  * The component needs to be stopped when the node is closed.
18
18
  * @param nodeIdentity The identity of the node stopping the component.
19
- * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
19
+ * @param nodeLoggingComponentType The node logging component type.
20
20
  * @param componentState A persistent state which can be modified by the method.
21
21
  * @returns Nothing.
22
22
  */
23
- stop(nodeIdentity: string, nodeLoggingConnectorType: string | undefined, componentState?: {
23
+ stop(nodeIdentity: string, nodeLoggingComponentType: string | undefined, componentState?: {
24
24
  [id: string]: unknown;
25
25
  }): Promise<void>;
26
26
  /**
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.2-next.5](https://github.com/twinfoundation/background-task/compare/background-task-scheduler-v0.0.2-next.4...background-task-scheduler-v0.0.2-next.5) (2025-08-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * update framework core ([a068098](https://github.com/twinfoundation/background-task/commit/a0680983d7923a1bfb980a67879019bb870ccc5d))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/background-task-models bumped from 0.0.2-next.4 to 0.0.2-next.5
16
+
17
+ ## [0.0.2-next.4](https://github.com/twinfoundation/background-task/compare/background-task-scheduler-v0.0.2-next.3...background-task-scheduler-v0.0.2-next.4) (2025-07-23)
18
+
19
+
20
+ ### Features
21
+
22
+ * background tasks immediately trigger ([a0a847b](https://github.com/twinfoundation/background-task/commit/a0a847ba9686adcd0460e810540959f87dcaeab1))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/background-task-models bumped from 0.0.2-next.3 to 0.0.2-next.4
30
+
3
31
  ## [0.0.2-next.3](https://github.com/twinfoundation/background-task/compare/background-task-scheduler-v0.0.2-next.2...background-task-scheduler-v0.0.2-next.3) (2025-07-21)
4
32
 
5
33
 
@@ -42,7 +42,7 @@ Runtime name for the class.
42
42
 
43
43
  ### stop()
44
44
 
45
- > **stop**(`nodeIdentity`, `nodeLoggingConnectorType`, `componentState?`): `Promise`\<`void`\>
45
+ > **stop**(`nodeIdentity`, `nodeLoggingComponentType`, `componentState?`): `Promise`\<`void`\>
46
46
 
47
47
  The component needs to be stopped when the node is closed.
48
48
 
@@ -54,9 +54,9 @@ The component needs to be stopped when the node is closed.
54
54
 
55
55
  The identity of the node stopping the component.
56
56
 
57
- ##### nodeLoggingConnectorType
57
+ ##### nodeLoggingComponentType
58
58
 
59
- The node logging connector type, defaults to "node-logging".
59
+ The node logging component type.
60
60
 
61
61
  `undefined` | `string`
62
62
 
@@ -4,11 +4,11 @@ Options for the task scheduler constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### loggingConnectorType?
7
+ ### loggingComponentType?
8
8
 
9
- > `optional` **loggingConnectorType**: `string`
9
+ > `optional` **loggingComponentType**: `string`
10
10
 
11
- The logging connector type.
11
+ The logging component type.
12
12
 
13
13
  #### Default
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/background-task-scheduler",
3
- "version": "0.0.2-next.3",
3
+ "version": "0.0.2-next.5",
4
4
  "description": "Background task scheduler",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/background-task-models": "0.0.2-next.3",
17
+ "@twin.org/background-task-models": "0.0.2-next.5",
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/logging-models": "next",
20
20
  "@twin.org/nameof": "next"