@nwire/cron 0.9.2 → 0.10.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.
- package/dist/cron.d.ts +3 -15
- package/dist/cron.js +11 -24
- package/package.json +3 -3
- package/dist/cron.d.ts.map +0 -1
- package/dist/cron.js.map +0 -1
package/dist/cron.d.ts
CHANGED
|
@@ -5,35 +5,23 @@
|
|
|
5
5
|
* owning app. Fresh envelope per tick; correlation/causation propagate
|
|
6
6
|
* through chained dispatches. Built on `croner`. For multi-process
|
|
7
7
|
* deployments run cron in ONE process.
|
|
8
|
-
*
|
|
9
|
-
* See: architecture-sketch.html §05 (Adapters tier).
|
|
10
8
|
*/
|
|
11
9
|
import { Cron } from "croner";
|
|
12
|
-
import type {
|
|
10
|
+
import type { ForgeApp } from "@nwire/forge";
|
|
13
11
|
export type CronScheduleEntry = string | {
|
|
14
12
|
readonly action: string;
|
|
15
13
|
readonly input?: unknown;
|
|
16
14
|
readonly tenant?: string;
|
|
17
15
|
};
|
|
18
16
|
export interface CronWireOptions {
|
|
19
|
-
|
|
20
|
-
readonly apps: readonly AppDefinition[];
|
|
21
|
-
/** Pre-instantiated `App`s (for tests where stores are injected). */
|
|
22
|
-
readonly appInstances?: readonly App[];
|
|
23
|
-
/**
|
|
24
|
-
* Schedule: keys are cron expressions, values are action names or full specs.
|
|
25
|
-
* Examples: `0 2 * * *` (daily 02:00), `@hourly` (Croner shortcuts supported).
|
|
26
|
-
*/
|
|
17
|
+
readonly apps: readonly ForgeApp[];
|
|
27
18
|
readonly schedule: Readonly<Record<string, CronScheduleEntry>>;
|
|
28
|
-
/** Timezone (IANA) for evaluating cron expressions. Default: process default. */
|
|
29
19
|
readonly timezone?: string;
|
|
30
20
|
}
|
|
31
21
|
export interface CronWire {
|
|
32
|
-
readonly apps: readonly
|
|
33
|
-
/** Active Cron handles (for inspection / testing). */
|
|
22
|
+
readonly apps: readonly ForgeApp[];
|
|
34
23
|
readonly schedules: readonly Cron[];
|
|
35
24
|
start(): Promise<void>;
|
|
36
25
|
stop(): Promise<void>;
|
|
37
26
|
}
|
|
38
27
|
export declare function createCronWire(options: CronWireOptions): CronWire;
|
|
39
|
-
//# sourceMappingURL=cron.d.ts.map
|
package/dist/cron.js
CHANGED
|
@@ -5,13 +5,11 @@
|
|
|
5
5
|
* owning app. Fresh envelope per tick; correlation/causation propagate
|
|
6
6
|
* through chained dispatches. Built on `croner`. For multi-process
|
|
7
7
|
* deployments run cron in ONE process.
|
|
8
|
-
*
|
|
9
|
-
* See: architecture-sketch.html §05 (Adapters tier).
|
|
10
8
|
*/
|
|
11
9
|
import { Cron } from "croner";
|
|
12
10
|
import { seedEnvelope } from "@nwire/envelope";
|
|
13
11
|
export function createCronWire(options) {
|
|
14
|
-
const instances = options.
|
|
12
|
+
const instances = options.apps;
|
|
15
13
|
const schedules = [];
|
|
16
14
|
return {
|
|
17
15
|
apps: instances,
|
|
@@ -20,16 +18,14 @@ export function createCronWire(options) {
|
|
|
20
18
|
await Promise.all(instances.map((a) => a.start()));
|
|
21
19
|
for (const [expr, entry] of Object.entries(options.schedule)) {
|
|
22
20
|
const spec = typeof entry === "string" ? { action: entry, input: {} } : entry;
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
21
|
+
const located = locateAction(instances, spec.action);
|
|
22
|
+
if (!located) {
|
|
25
23
|
throw new Error(`@nwire/cron: action "${spec.action}" not found in any registered app`);
|
|
26
24
|
}
|
|
27
|
-
const
|
|
28
|
-
if (!action)
|
|
29
|
-
continue;
|
|
25
|
+
const { owner, action } = located;
|
|
30
26
|
const cron = new Cron(expr, { timezone: options.timezone, protect: true }, async () => {
|
|
31
27
|
const envelope = seedEnvelope({ tenant: spec.tenant });
|
|
32
|
-
await owner.
|
|
28
|
+
await owner.dispatch(action, spec.input ?? {}, envelope);
|
|
33
29
|
});
|
|
34
30
|
schedules.push(cron);
|
|
35
31
|
}
|
|
@@ -38,24 +34,15 @@ export function createCronWire(options) {
|
|
|
38
34
|
for (const c of schedules)
|
|
39
35
|
c.stop();
|
|
40
36
|
schedules.length = 0;
|
|
37
|
+
await Promise.all(instances.map((a) => a.stop()));
|
|
41
38
|
},
|
|
42
39
|
};
|
|
43
40
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
return names;
|
|
51
|
-
}
|
|
52
|
-
function findAction(app, name) {
|
|
53
|
-
for (const m of app.modules) {
|
|
54
|
-
for (const a of m.manifest.actions ?? []) {
|
|
55
|
-
if (a.name === name)
|
|
56
|
-
return a;
|
|
57
|
-
}
|
|
41
|
+
function locateAction(apps, name) {
|
|
42
|
+
for (const app of apps) {
|
|
43
|
+
const action = app.dispatcher().findActionByName(name);
|
|
44
|
+
if (action)
|
|
45
|
+
return { owner: app, action };
|
|
58
46
|
}
|
|
59
47
|
return undefined;
|
|
60
48
|
}
|
|
61
|
-
//# sourceMappingURL=cron.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nwire/cron",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Nwire — cron interface factory. Dispatch actions on a schedule (croner-backed).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cron",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"croner": "^9.1.0",
|
|
32
|
-
"@nwire/
|
|
33
|
-
"@nwire/
|
|
32
|
+
"@nwire/envelope": "0.10.1",
|
|
33
|
+
"@nwire/forge": "0.10.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "^22.19.9",
|
package/dist/cron.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cron.d.ts","sourceRoot":"","sources":["../src/cron.ts"],"names":[],"mappings":"AAAA;;;;;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