@tc-libs/task 3.5.0 → 3.6.1

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.
Files changed (2) hide show
  1. package/README.md +66 -6
  2. package/package.json +11 -11
package/README.md CHANGED
@@ -1,11 +1,71 @@
1
- # task
1
+ # @tc-libs/task
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Tracking stato e run di job/task schedulati o manuali.
4
4
 
5
- ## Building
5
+ Il package fornisce:
6
6
 
7
- Run `nx build task` to build the library.
7
+ - `TaskModule`
8
+ - `TaskService`
9
+ - `TaskRunService`
10
+ - entity/repository/controller admin
8
11
 
9
- ## Running unit tests
12
+ ## `TaskService`
10
13
 
11
- Run `nx test task` to execute the unit tests via [Jest](https://jestjs.io).
14
+ Metodi specifici:
15
+
16
+ - `ensureTask(code, env)`
17
+ - `tryAcquireLock(code, env, staleMs)`
18
+ - `markSuccess(code, elapsedMs, env)`
19
+ - `markError(code, error, elapsedMs, env)`
20
+
21
+ Uso tipico:
22
+
23
+ ```ts
24
+ const task = await this.taskService.ensureTask('SYNC_USERS', 'prod');
25
+ const lock = await this.taskService.tryAcquireLock('SYNC_USERS', 'prod', 300000);
26
+
27
+ if (!lock) return;
28
+ ```
29
+
30
+ Questo permette di evitare run concorrenti della stessa task.
31
+
32
+ ## `TaskRunService`
33
+
34
+ Gestisce le esecuzioni singole:
35
+
36
+ - `startRun(task)`
37
+ - `endRun(runId, elapsedMs)`
38
+ - `failRun(runId, error, elapsedMs)`
39
+
40
+ Esempio:
41
+
42
+ ```ts
43
+ const run = await this.taskRunService.startRun(task);
44
+
45
+ try {
46
+ // esegui job
47
+ await this.taskRunService.endRun(run._id.toString(), elapsedMs);
48
+ await this.taskService.markSuccess(task.code, elapsedMs, task.env);
49
+ } catch (error) {
50
+ await this.taskRunService.failRun(run._id.toString(), error, elapsedMs);
51
+ await this.taskService.markError(task.code, error, elapsedMs, task.env);
52
+ }
53
+ ```
54
+
55
+ ## Stati task
56
+
57
+ `TASK_STATUS_ENUM`:
58
+
59
+ - `IDLE`
60
+ - `RUNNING`
61
+ - `COMPLETED`
62
+ - `FAILED`
63
+
64
+ Nel servizio attuale il lock usa soprattutto `IDLE` e `RUNNING`.
65
+
66
+ ## Sviluppo
67
+
68
+ ```bash
69
+ nx build task
70
+ nx test task
71
+ ```
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@tc-libs/task",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "dependencies": {
5
- "@tc-libs/pagination": "3.5.0",
5
+ "@tc-libs/pagination": "3.6.1",
6
6
  "@nestjs/common": "^11.0.12",
7
7
  "@nestjs/swagger": "^11.1.0",
8
- "@tc-libs/authentication": "3.5.0",
9
- "@tc-libs/request": "3.5.0",
10
- "@tc-libs/response": "3.5.0",
8
+ "@tc-libs/authentication": "3.6.1",
9
+ "@tc-libs/request": "3.6.1",
10
+ "@tc-libs/response": "3.6.1",
11
11
  "class-transformer": "^0.5.1",
12
12
  "class-validator": "^0.14.1",
13
13
  "@nestjs/mongoose": "^11.0.3",
14
- "@tc-libs/database": "3.5.0",
14
+ "@tc-libs/database": "3.6.1",
15
15
  "mongoose": "^8.13.1",
16
- "@tc-libs/app-cache": "3.5.0",
17
- "@tc-libs/retry-policy": "3.5.0",
18
- "@tc-libs/logger": "3.5.0",
19
- "@tc-libs/helper": "3.5.0",
20
- "@tc-libs/service": "3.5.0",
16
+ "@tc-libs/app-cache": "3.6.1",
17
+ "@tc-libs/retry-policy": "3.6.1",
18
+ "@tc-libs/logger": "3.6.1",
19
+ "@tc-libs/helper": "3.6.1",
20
+ "@tc-libs/service": "3.6.1",
21
21
  "tslib": "^2.8.1"
22
22
  },
23
23
  "type": "commonjs",