@sonamu-kit/tasks 0.0.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/.swcrc +17 -0
- package/README.md +7 -0
- package/dist/backend.d.ts +107 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +3 -0
- package/dist/backend.js.map +1 -0
- package/dist/chaos.test.d.ts +2 -0
- package/dist/chaos.test.d.ts.map +1 -0
- package/dist/chaos.test.js +92 -0
- package/dist/chaos.test.js.map +1 -0
- package/dist/client.d.ts +178 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +223 -0
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +339 -0
- package/dist/client.test.js.map +1 -0
- package/dist/config.d.ts +22 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +23 -0
- package/dist/config.js.map +1 -0
- package/dist/config.test.d.ts +2 -0
- package/dist/config.test.d.ts.map +1 -0
- package/dist/config.test.js +24 -0
- package/dist/config.test.js.map +1 -0
- package/dist/core/duration.d.ts +22 -0
- package/dist/core/duration.d.ts.map +1 -0
- package/dist/core/duration.js +64 -0
- package/dist/core/duration.js.map +1 -0
- package/dist/core/duration.test.d.ts +2 -0
- package/dist/core/duration.test.d.ts.map +1 -0
- package/dist/core/duration.test.js +265 -0
- package/dist/core/duration.test.js.map +1 -0
- package/dist/core/error.d.ts +15 -0
- package/dist/core/error.d.ts.map +1 -0
- package/dist/core/error.js +25 -0
- package/dist/core/error.js.map +1 -0
- package/dist/core/error.test.d.ts +2 -0
- package/dist/core/error.test.d.ts.map +1 -0
- package/dist/core/error.test.js +63 -0
- package/dist/core/error.test.js.map +1 -0
- package/dist/core/json.d.ts +5 -0
- package/dist/core/json.d.ts.map +1 -0
- package/dist/core/json.js +3 -0
- package/dist/core/json.js.map +1 -0
- package/dist/core/result.d.ts +22 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +22 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/result.test.d.ts +2 -0
- package/dist/core/result.test.d.ts.map +1 -0
- package/dist/core/result.test.js +19 -0
- package/dist/core/result.test.js.map +1 -0
- package/dist/core/retry.d.ts +21 -0
- package/dist/core/retry.d.ts.map +1 -0
- package/dist/core/retry.js +25 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/retry.test.d.ts +2 -0
- package/dist/core/retry.test.d.ts.map +1 -0
- package/dist/core/retry.test.js +37 -0
- package/dist/core/retry.test.js.map +1 -0
- package/dist/core/schema.d.ts +57 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +4 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/step.d.ts +96 -0
- package/dist/core/step.d.ts.map +1 -0
- package/dist/core/step.js +78 -0
- package/dist/core/step.js.map +1 -0
- package/dist/core/step.test.d.ts +2 -0
- package/dist/core/step.test.d.ts.map +1 -0
- package/dist/core/step.test.js +356 -0
- package/dist/core/step.test.js.map +1 -0
- package/dist/core/workflow.d.ts +78 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +46 -0
- package/dist/core/workflow.js.map +1 -0
- package/dist/core/workflow.test.d.ts +2 -0
- package/dist/core/workflow.test.d.ts.map +1 -0
- package/dist/core/workflow.test.js +172 -0
- package/dist/core/workflow.test.js.map +1 -0
- package/dist/database/backend.d.ts +60 -0
- package/dist/database/backend.d.ts.map +1 -0
- package/dist/database/backend.js +387 -0
- package/dist/database/backend.js.map +1 -0
- package/dist/database/backend.test.d.ts +2 -0
- package/dist/database/backend.test.d.ts.map +1 -0
- package/dist/database/backend.test.js +17 -0
- package/dist/database/backend.test.js.map +1 -0
- package/dist/database/backend.testsuite.d.ts +20 -0
- package/dist/database/backend.testsuite.d.ts.map +1 -0
- package/dist/database/backend.testsuite.js +1174 -0
- package/dist/database/backend.testsuite.js.map +1 -0
- package/dist/database/base.d.ts +12 -0
- package/dist/database/base.d.ts.map +1 -0
- package/dist/database/base.js +19 -0
- package/dist/database/base.js.map +1 -0
- package/dist/database/migrations/20251212000000_0_init.js +9 -0
- package/dist/database/migrations/20251212000000_0_init.js.map +1 -0
- package/dist/database/migrations/20251212000000_1_tables.js +88 -0
- package/dist/database/migrations/20251212000000_1_tables.js.map +1 -0
- package/dist/database/migrations/20251212000000_2_fk.js +48 -0
- package/dist/database/migrations/20251212000000_2_fk.js.map +1 -0
- package/dist/database/migrations/20251212000000_3_indexes.js +107 -0
- package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -0
- package/dist/database/pubsub.d.ts +17 -0
- package/dist/database/pubsub.d.ts.map +1 -0
- package/dist/database/pubsub.js +70 -0
- package/dist/database/pubsub.js.map +1 -0
- package/dist/database/pubsub.test.d.ts +2 -0
- package/dist/database/pubsub.test.d.ts.map +1 -0
- package/dist/database/pubsub.test.js +86 -0
- package/dist/database/pubsub.test.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/execution.d.ts +82 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +182 -0
- package/dist/execution.js.map +1 -0
- package/dist/execution.test.d.ts +2 -0
- package/dist/execution.test.d.ts.map +1 -0
- package/dist/execution.test.js +556 -0
- package/dist/execution.test.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +12 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +5 -0
- package/dist/internal.js.map +1 -0
- package/dist/practices/01-remote-workflow.d.ts +2 -0
- package/dist/practices/01-remote-workflow.d.ts.map +1 -0
- package/dist/practices/01-remote-workflow.js +69 -0
- package/dist/practices/01-remote-workflow.js.map +1 -0
- package/dist/practices/01-remote.d.ts +2 -0
- package/dist/practices/01-remote.d.ts.map +1 -0
- package/dist/practices/01-remote.js +87 -0
- package/dist/practices/01-remote.js.map +1 -0
- package/dist/practices/02-local.d.ts +2 -0
- package/dist/practices/02-local.d.ts.map +1 -0
- package/dist/practices/02-local.js +84 -0
- package/dist/practices/02-local.js.map +1 -0
- package/dist/practices/03-local-retry.d.ts +2 -0
- package/dist/practices/03-local-retry.d.ts.map +1 -0
- package/dist/practices/03-local-retry.js +85 -0
- package/dist/practices/03-local-retry.js.map +1 -0
- package/dist/practices/04-scheduler-dispose.d.ts +2 -0
- package/dist/practices/04-scheduler-dispose.d.ts.map +1 -0
- package/dist/practices/04-scheduler-dispose.js +65 -0
- package/dist/practices/04-scheduler-dispose.js.map +1 -0
- package/dist/practices/05-router.d.ts +2 -0
- package/dist/practices/05-router.d.ts.map +1 -0
- package/dist/practices/05-router.js +80 -0
- package/dist/practices/05-router.js.map +1 -0
- package/dist/registry.d.ts +33 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +54 -0
- package/dist/registry.js.map +1 -0
- package/dist/registry.test.d.ts +2 -0
- package/dist/registry.test.d.ts.map +1 -0
- package/dist/registry.test.js +95 -0
- package/dist/registry.test.js.map +1 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +117 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/tasks/index.d.ts +4 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +5 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/local-task.d.ts +6 -0
- package/dist/tasks/local-task.d.ts.map +1 -0
- package/dist/tasks/local-task.js +95 -0
- package/dist/tasks/local-task.js.map +1 -0
- package/dist/tasks/remote-task.d.ts +11 -0
- package/dist/tasks/remote-task.d.ts.map +1 -0
- package/dist/tasks/remote-task.js +213 -0
- package/dist/tasks/remote-task.js.map +1 -0
- package/dist/tasks/shared.d.ts +8 -0
- package/dist/tasks/shared.d.ts.map +1 -0
- package/dist/tasks/shared.js +41 -0
- package/dist/tasks/shared.js.map +1 -0
- package/dist/testing/connection.d.ts +7 -0
- package/dist/testing/connection.d.ts.map +1 -0
- package/dist/testing/connection.js +38 -0
- package/dist/testing/connection.js.map +1 -0
- package/dist/types/config.d.ts +44 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/context.d.ts +18 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/context.js +4 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/events.d.ts +43 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +3 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/task-items.d.ts +12 -0
- package/dist/types/task-items.d.ts.map +1 -0
- package/dist/types/task-items.js +3 -0
- package/dist/types/task-items.js.map +1 -0
- package/dist/types/utils.d.ts +4 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +8 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/worker.d.ts +61 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +206 -0
- package/dist/worker.js.map +1 -0
- package/dist/worker.test.d.ts +2 -0
- package/dist/worker.test.d.ts.map +1 -0
- package/dist/worker.test.js +1163 -0
- package/dist/worker.test.js.map +1 -0
- package/dist/workflow.d.ts +44 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +21 -0
- package/dist/workflow.js.map +1 -0
- package/dist/workflow.test.d.ts +2 -0
- package/dist/workflow.test.d.ts.map +1 -0
- package/dist/workflow.test.js +73 -0
- package/dist/workflow.test.js.map +1 -0
- package/nodemon.json +6 -0
- package/package.json +63 -0
- package/scripts/migrate.ts +11 -0
- package/src/backend.ts +133 -0
- package/src/chaos.test.ts +108 -0
- package/src/client.test.ts +297 -0
- package/src/client.ts +331 -0
- package/src/config.test.ts +23 -0
- package/src/config.ts +35 -0
- package/src/core/duration.test.ts +326 -0
- package/src/core/duration.ts +86 -0
- package/src/core/error.test.ts +77 -0
- package/src/core/error.ts +30 -0
- package/src/core/json.ts +2 -0
- package/src/core/result.test.ts +13 -0
- package/src/core/result.ts +29 -0
- package/src/core/retry.test.ts +41 -0
- package/src/core/retry.ts +29 -0
- package/src/core/schema.ts +74 -0
- package/src/core/step.test.ts +362 -0
- package/src/core/step.ts +152 -0
- package/src/core/workflow.test.ts +184 -0
- package/src/core/workflow.ts +127 -0
- package/src/database/backend.test.ts +16 -0
- package/src/database/backend.testsuite.ts +1376 -0
- package/src/database/backend.ts +655 -0
- package/src/database/base.ts +23 -0
- package/src/database/migrations/20251212000000_0_init.ts +10 -0
- package/src/database/migrations/20251212000000_1_tables.ts +54 -0
- package/src/database/migrations/20251212000000_2_fk.ts +46 -0
- package/src/database/migrations/20251212000000_3_indexes.ts +82 -0
- package/src/database/pubsub.test.ts +92 -0
- package/src/database/pubsub.ts +92 -0
- package/src/execution.test.ts +508 -0
- package/src/execution.ts +291 -0
- package/src/index.ts +7 -0
- package/src/internal.ts +11 -0
- package/src/practices/01-remote-workflow.ts +61 -0
- package/src/registry.test.ts +122 -0
- package/src/registry.ts +65 -0
- package/src/testing/connection.ts +44 -0
- package/src/worker.test.ts +1138 -0
- package/src/worker.ts +281 -0
- package/src/workflow.test.ts +68 -0
- package/src/workflow.ts +84 -0
- package/table_ddl.sql +60 -0
- package/templates/openworkflow.config.ts +22 -0
- package/tsconfig.json +40 -0
- package/tsconfig.test.json +4 -0
- package/vite.config.ts +13 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"01-remote-workflow.d.ts","sourceRoot":"","sources":["../../src/practices/01-remote-workflow.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { BackendPostgres, OpenWorkflow } from "../index.js";
|
|
4
|
+
import { KNEX_GLOBAL_CONFIG } from "../testing/connection.js";
|
|
5
|
+
let _backend = null;
|
|
6
|
+
async function getBackend() {
|
|
7
|
+
if (_backend !== null) {
|
|
8
|
+
return _backend;
|
|
9
|
+
}
|
|
10
|
+
_backend = await BackendPostgres.connect(KNEX_GLOBAL_CONFIG, {
|
|
11
|
+
runMigrations: true,
|
|
12
|
+
namespaceId: randomUUID()
|
|
13
|
+
});
|
|
14
|
+
return _backend;
|
|
15
|
+
}
|
|
16
|
+
async function practice() {
|
|
17
|
+
const backend = await getBackend();
|
|
18
|
+
const ow = new OpenWorkflow({
|
|
19
|
+
backend
|
|
20
|
+
});
|
|
21
|
+
const sampleWorkflow = ow.defineWorkflow({
|
|
22
|
+
name: "sample-workflow"
|
|
23
|
+
}, async ({ step })=>{
|
|
24
|
+
const { result: result1 } = await step.run({
|
|
25
|
+
name: "test-1"
|
|
26
|
+
}, async ()=>{
|
|
27
|
+
return {
|
|
28
|
+
result: [
|
|
29
|
+
"Result from test-1"
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
await step.run({
|
|
34
|
+
name: "test-2"
|
|
35
|
+
}, async ()=>{
|
|
36
|
+
return await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
37
|
+
});
|
|
38
|
+
return await step.run({
|
|
39
|
+
name: "test-3"
|
|
40
|
+
}, async ()=>{
|
|
41
|
+
return {
|
|
42
|
+
result: [
|
|
43
|
+
...result1,
|
|
44
|
+
"Result from test-3"
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
// create a worker that will listen to the channel and process the workflow runs
|
|
50
|
+
const worker = ow.newWorker({
|
|
51
|
+
concurrency: 3
|
|
52
|
+
});
|
|
53
|
+
await worker.start();
|
|
54
|
+
const handle = await sampleWorkflow.run();
|
|
55
|
+
await new Promise((resolve)=>setTimeout(resolve, 3000));
|
|
56
|
+
await worker.tick();
|
|
57
|
+
const result = await handle.result();
|
|
58
|
+
assert.deepEqual(result, {
|
|
59
|
+
result: [
|
|
60
|
+
"Result from test-1",
|
|
61
|
+
"Result from test-3"
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
await worker.stop();
|
|
65
|
+
await backend.stop();
|
|
66
|
+
}
|
|
67
|
+
await practice();
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=01-remote-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/practices/01-remote-workflow.ts"],"sourcesContent":["import assert from \"node:assert\";\nimport { randomUUID } from \"node:crypto\";\nimport { BackendPostgres, OpenWorkflow } from \"../\";\nimport { KNEX_GLOBAL_CONFIG } from \"../testing/connection\";\n\nlet _backend: BackendPostgres | null = null;\n\nasync function getBackend(): Promise<BackendPostgres> {\n if (_backend !== null) {\n return _backend;\n }\n\n _backend = await BackendPostgres.connect(KNEX_GLOBAL_CONFIG, {\n runMigrations: true,\n namespaceId: randomUUID(),\n });\n\n return _backend;\n}\n\nasync function practice() {\n const backend = await getBackend();\n const ow = new OpenWorkflow({ backend });\n\n const sampleWorkflow = ow.defineWorkflow({ name: \"sample-workflow\" }, async ({ step }) => {\n const { result: result1 } = await step.run({ name: \"test-1\" }, async () => {\n return {\n result: [\"Result from test-1\"],\n };\n });\n\n await step.run({ name: \"test-2\" }, async () => {\n return await new Promise<void>((resolve) => setTimeout(resolve, 1000));\n });\n\n return await step.run({ name: \"test-3\" }, async () => {\n return {\n result: [...result1, \"Result from test-3\"],\n };\n });\n });\n\n // create a worker that will listen to the channel and process the workflow runs\n const worker = ow.newWorker({ concurrency: 3 });\n await worker.start();\n\n const handle = await sampleWorkflow.run();\n\n await new Promise((resolve) => setTimeout(resolve, 3000));\n await worker.tick();\n\n const result = await handle.result();\n assert.deepEqual(result, {\n result: [\"Result from test-1\", \"Result from test-3\"],\n });\n\n await worker.stop();\n await backend.stop();\n}\n\nawait practice();\n"],"names":["assert","randomUUID","BackendPostgres","OpenWorkflow","KNEX_GLOBAL_CONFIG","_backend","getBackend","connect","runMigrations","namespaceId","practice","backend","ow","sampleWorkflow","defineWorkflow","name","step","result","result1","run","Promise","resolve","setTimeout","worker","newWorker","concurrency","start","handle","tick","deepEqual","stop"],"mappings":"AAAA,OAAOA,YAAY,cAAc;AACjC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,eAAe,EAAEC,YAAY,QAAQ,cAAM;AACpD,SAASC,kBAAkB,QAAQ,2BAAwB;AAE3D,IAAIC,WAAmC;AAEvC,eAAeC;IACb,IAAID,aAAa,MAAM;QACrB,OAAOA;IACT;IAEAA,WAAW,MAAMH,gBAAgBK,OAAO,CAACH,oBAAoB;QAC3DI,eAAe;QACfC,aAAaR;IACf;IAEA,OAAOI;AACT;AAEA,eAAeK;IACb,MAAMC,UAAU,MAAML;IACtB,MAAMM,KAAK,IAAIT,aAAa;QAAEQ;IAAQ;IAEtC,MAAME,iBAAiBD,GAAGE,cAAc,CAAC;QAAEC,MAAM;IAAkB,GAAG,OAAO,EAAEC,IAAI,EAAE;QACnF,MAAM,EAAEC,QAAQC,OAAO,EAAE,GAAG,MAAMF,KAAKG,GAAG,CAAC;YAAEJ,MAAM;QAAS,GAAG;YAC7D,OAAO;gBACLE,QAAQ;oBAAC;iBAAqB;YAChC;QACF;QAEA,MAAMD,KAAKG,GAAG,CAAC;YAAEJ,MAAM;QAAS,GAAG;YACjC,OAAO,MAAM,IAAIK,QAAc,CAACC,UAAYC,WAAWD,SAAS;QAClE;QAEA,OAAO,MAAML,KAAKG,GAAG,CAAC;YAAEJ,MAAM;QAAS,GAAG;YACxC,OAAO;gBACLE,QAAQ;uBAAIC;oBAAS;iBAAqB;YAC5C;QACF;IACF;IAEA,gFAAgF;IAChF,MAAMK,SAASX,GAAGY,SAAS,CAAC;QAAEC,aAAa;IAAE;IAC7C,MAAMF,OAAOG,KAAK;IAElB,MAAMC,SAAS,MAAMd,eAAeM,GAAG;IAEvC,MAAM,IAAIC,QAAQ,CAACC,UAAYC,WAAWD,SAAS;IACnD,MAAME,OAAOK,IAAI;IAEjB,MAAMX,SAAS,MAAMU,OAAOV,MAAM;IAClCjB,OAAO6B,SAAS,CAACZ,QAAQ;QACvBA,QAAQ;YAAC;YAAsB;SAAqB;IACtD;IAEA,MAAMM,OAAOO,IAAI;IACjB,MAAMnB,QAAQmB,IAAI;AACpB;AAEA,MAAMpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"01-remote.d.ts","sourceRoot":"","sources":["../../src/practices/01-remote.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createScheduler } from "../scheduler.js";
|
|
3
|
+
import assert from "node:assert";
|
|
4
|
+
function getConfig() {
|
|
5
|
+
const schema = z.object();
|
|
6
|
+
return {
|
|
7
|
+
database: {
|
|
8
|
+
client: "mysql2",
|
|
9
|
+
pool: {
|
|
10
|
+
min: 1,
|
|
11
|
+
max: 5
|
|
12
|
+
},
|
|
13
|
+
connection: {
|
|
14
|
+
database: "miomock",
|
|
15
|
+
host: "0.0.0.0",
|
|
16
|
+
port: 3306,
|
|
17
|
+
user: "root",
|
|
18
|
+
password: "miomock123",
|
|
19
|
+
typeCast: function(field, next) {
|
|
20
|
+
if (field.type === "TINY" && field.length === 1) {
|
|
21
|
+
const value = field.string();
|
|
22
|
+
return value ? value === "1" : null;
|
|
23
|
+
}
|
|
24
|
+
// DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)
|
|
25
|
+
if (field.type === "DATE") {
|
|
26
|
+
return field.string();
|
|
27
|
+
}
|
|
28
|
+
return next();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
routes: [
|
|
33
|
+
{
|
|
34
|
+
path: "/test",
|
|
35
|
+
schema: schema,
|
|
36
|
+
target: async (ctx)=>{
|
|
37
|
+
console.log("Processed", ctx);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
path: "/test2",
|
|
42
|
+
retry: {
|
|
43
|
+
maxAttempts: 3,
|
|
44
|
+
delay: {
|
|
45
|
+
seconds: 1
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
schema: schema,
|
|
49
|
+
target: async ({ taskItem, retry })=>{
|
|
50
|
+
if (taskItem.attempt !== retry.maxAttempts) {
|
|
51
|
+
throw new Error("실패!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
retry: {
|
|
57
|
+
delay: {},
|
|
58
|
+
maxAttempts: 1
|
|
59
|
+
},
|
|
60
|
+
tasks: [
|
|
61
|
+
{
|
|
62
|
+
type: "remote",
|
|
63
|
+
// node-cron은 초까지 지원하기 때문에 이렇게 10초마다 돌릴 수 있음.
|
|
64
|
+
expression: "*/10 * * * * *",
|
|
65
|
+
options: {
|
|
66
|
+
timezone: "Asia/Seoul",
|
|
67
|
+
name: "remote-job",
|
|
68
|
+
noOverlap: false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
(async ()=>{
|
|
75
|
+
const scheduler = await createScheduler(getConfig());
|
|
76
|
+
// name이 *일 경우엔 모든 이벤트를 수신할 수 있음.
|
|
77
|
+
scheduler.on("*", (evt)=>{
|
|
78
|
+
console.log("Event: ", evt);
|
|
79
|
+
});
|
|
80
|
+
scheduler.on("process:start", (evt)=>{
|
|
81
|
+
assert(evt.type === "process:start");
|
|
82
|
+
console.log("[Process Started] Task Item: ", evt.task.id);
|
|
83
|
+
});
|
|
84
|
+
scheduler.start();
|
|
85
|
+
})();
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=01-remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/practices/01-remote.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createScheduler } from \"../scheduler\";\nimport type { TaskContext, SchedulerConfig, TaskEvent } from \"../types\";\nimport assert from \"node:assert\";\n\nfunction getConfig(): SchedulerConfig {\n const schema = z.object();\n\n return {\n database: {\n client: \"mysql2\",\n pool: { min: 1, max: 5 },\n connection: {\n database: \"miomock\",\n host: \"0.0.0.0\",\n port: 3306,\n user: \"root\",\n password: \"miomock123\",\n typeCast: function (field: any, next: any) {\n if (field.type === \"TINY\" && field.length === 1) {\n const value = field.string();\n return value ? value === \"1\" : null;\n }\n // DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)\n if (field.type === \"DATE\") {\n return field.string();\n }\n return next();\n },\n },\n },\n routes: [\n {\n path: \"/test\",\n schema: schema,\n target: async (ctx: TaskContext<typeof schema>) => {\n console.log(\"Processed\", ctx);\n },\n },\n {\n path: \"/test2\",\n retry: { maxAttempts: 3, delay: { seconds: 1 } },\n schema: schema,\n target: async ({ taskItem, retry }: TaskContext<typeof schema>) => {\n if (taskItem.attempt !== retry.maxAttempts) {\n throw new Error(\"실패!\");\n }\n },\n },\n ],\n\n retry: {\n delay: {},\n maxAttempts: 1,\n },\n\n tasks: [\n {\n type: \"remote\",\n // node-cron은 초까지 지원하기 때문에 이렇게 10초마다 돌릴 수 있음.\n expression: \"*/10 * * * * *\",\n options: {\n timezone: \"Asia/Seoul\",\n name: \"remote-job\",\n noOverlap: false,\n },\n },\n ],\n };\n}\n\n(async () => {\n const scheduler = await createScheduler(getConfig());\n\n // name이 *일 경우엔 모든 이벤트를 수신할 수 있음.\n scheduler.on(\"*\", (evt: TaskEvent) => {\n console.log(\"Event: \", evt);\n });\n\n scheduler.on(\"process:start\", (evt: TaskEvent) => {\n assert(evt.type === \"process:start\");\n console.log(\"[Process Started] Task Item: \", evt.task.id);\n });\n\n scheduler.start();\n})();\n"],"names":["z","createScheduler","assert","getConfig","schema","object","database","client","pool","min","max","connection","host","port","user","password","typeCast","field","next","type","length","value","string","routes","path","target","ctx","console","log","retry","maxAttempts","delay","seconds","taskItem","attempt","Error","tasks","expression","options","timezone","name","noOverlap","scheduler","on","evt","task","id","start"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,QAAQ,kBAAe;AAE/C,OAAOC,YAAY,cAAc;AAEjC,SAASC;IACP,MAAMC,SAASJ,EAAEK,MAAM;IAEvB,OAAO;QACLC,UAAU;YACRC,QAAQ;YACRC,MAAM;gBAAEC,KAAK;gBAAGC,KAAK;YAAE;YACvBC,YAAY;gBACVL,UAAU;gBACVM,MAAM;gBACNC,MAAM;gBACNC,MAAM;gBACNC,UAAU;gBACVC,UAAU,SAAUC,KAAU,EAAEC,IAAS;oBACvC,IAAID,MAAME,IAAI,KAAK,UAAUF,MAAMG,MAAM,KAAK,GAAG;wBAC/C,MAAMC,QAAQJ,MAAMK,MAAM;wBAC1B,OAAOD,QAAQA,UAAU,MAAM;oBACjC;oBACA,mCAAmC;oBACnC,IAAIJ,MAAME,IAAI,KAAK,QAAQ;wBACzB,OAAOF,MAAMK,MAAM;oBACrB;oBACA,OAAOJ;gBACT;YACF;QACF;QACAK,QAAQ;YACN;gBACEC,MAAM;gBACNpB,QAAQA;gBACRqB,QAAQ,OAAOC;oBACbC,QAAQC,GAAG,CAAC,aAAaF;gBAC3B;YACF;YACA;gBACEF,MAAM;gBACNK,OAAO;oBAAEC,aAAa;oBAAGC,OAAO;wBAAEC,SAAS;oBAAE;gBAAE;gBAC/C5B,QAAQA;gBACRqB,QAAQ,OAAO,EAAEQ,QAAQ,EAAEJ,KAAK,EAA8B;oBAC5D,IAAII,SAASC,OAAO,KAAKL,MAAMC,WAAW,EAAE;wBAC1C,MAAM,IAAIK,MAAM;oBAClB;gBACF;YACF;SACD;QAEDN,OAAO;YACLE,OAAO,CAAC;YACRD,aAAa;QACf;QAEAM,OAAO;YACL;gBACEjB,MAAM;gBACN,6CAA6C;gBAC7CkB,YAAY;gBACZC,SAAS;oBACPC,UAAU;oBACVC,MAAM;oBACNC,WAAW;gBACb;YACF;SACD;IACH;AACF;AAEC,CAAA;IACC,MAAMC,YAAY,MAAMzC,gBAAgBE;IAExC,iCAAiC;IACjCuC,UAAUC,EAAE,CAAC,KAAK,CAACC;QACjBjB,QAAQC,GAAG,CAAC,WAAWgB;IACzB;IAEAF,UAAUC,EAAE,CAAC,iBAAiB,CAACC;QAC7B1C,OAAO0C,IAAIzB,IAAI,KAAK;QACpBQ,QAAQC,GAAG,CAAC,iCAAiCgB,IAAIC,IAAI,CAACC,EAAE;IAC1D;IAEAJ,UAAUK,KAAK;AACjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"02-local.d.ts","sourceRoot":"","sources":["../../src/practices/02-local.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createScheduler } from "../scheduler.js";
|
|
3
|
+
function getConfig() {
|
|
4
|
+
const schema = z.object();
|
|
5
|
+
return {
|
|
6
|
+
database: {
|
|
7
|
+
client: "mysql2",
|
|
8
|
+
pool: {
|
|
9
|
+
min: 1,
|
|
10
|
+
max: 5
|
|
11
|
+
},
|
|
12
|
+
connection: {
|
|
13
|
+
database: "miomock",
|
|
14
|
+
host: "0.0.0.0",
|
|
15
|
+
port: 3306,
|
|
16
|
+
user: "root",
|
|
17
|
+
password: "miomock123",
|
|
18
|
+
typeCast: function(field, next) {
|
|
19
|
+
if (field.type === "TINY" && field.length === 1) {
|
|
20
|
+
const value = field.string();
|
|
21
|
+
return value ? value === "1" : null;
|
|
22
|
+
}
|
|
23
|
+
// DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)
|
|
24
|
+
if (field.type === "DATE") {
|
|
25
|
+
return field.string();
|
|
26
|
+
}
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
routes: [
|
|
32
|
+
{
|
|
33
|
+
path: "/test",
|
|
34
|
+
schema: schema,
|
|
35
|
+
target: async (ctx)=>{
|
|
36
|
+
console.log("Processed", ctx);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: "/test2",
|
|
41
|
+
retry: {
|
|
42
|
+
maxAttempts: 3,
|
|
43
|
+
delay: {
|
|
44
|
+
seconds: 1
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
schema: schema,
|
|
48
|
+
target: async ({ taskItem, retry })=>{
|
|
49
|
+
// 마지막 시도에서만 성공하게 함.
|
|
50
|
+
if (taskItem.attempt !== retry.maxAttempts) {
|
|
51
|
+
throw new Error("실패!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
retry: {
|
|
57
|
+
delay: {},
|
|
58
|
+
maxAttempts: 1
|
|
59
|
+
},
|
|
60
|
+
tasks: [
|
|
61
|
+
{
|
|
62
|
+
type: "local",
|
|
63
|
+
expression: "*/10 * * * * *",
|
|
64
|
+
// local에서 실행할 때는 어느 namespace에서 어느 payload로 실행할지를 넣어야 함.
|
|
65
|
+
payload: {},
|
|
66
|
+
namespace: "/test2",
|
|
67
|
+
// node-cron에서 쓰는 options를 공유함.
|
|
68
|
+
options: {
|
|
69
|
+
timezone: "Asia/Seoul",
|
|
70
|
+
noOverlap: false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
(async ()=>{
|
|
77
|
+
const scheduler = await createScheduler(getConfig());
|
|
78
|
+
scheduler.on("*", (evt)=>{
|
|
79
|
+
console.log("Event:", evt);
|
|
80
|
+
});
|
|
81
|
+
scheduler.start();
|
|
82
|
+
})();
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=02-local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/practices/02-local.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createScheduler } from \"../scheduler\";\nimport type { TaskContext, SchedulerConfig, TaskEvent } from \"../types\";\n\nfunction getConfig(): SchedulerConfig {\n const schema = z.object();\n\n return {\n database: {\n client: \"mysql2\",\n pool: { min: 1, max: 5 },\n connection: {\n database: \"miomock\",\n host: \"0.0.0.0\",\n port: 3306,\n user: \"root\",\n password: \"miomock123\",\n typeCast: function (field: any, next: any) {\n if (field.type === \"TINY\" && field.length === 1) {\n const value = field.string();\n return value ? value === \"1\" : null;\n }\n // DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)\n if (field.type === \"DATE\") {\n return field.string();\n }\n return next();\n },\n },\n },\n routes: [\n {\n path: \"/test\",\n schema: schema,\n target: async (ctx: TaskContext<typeof schema>) => {\n console.log(\"Processed\", ctx);\n },\n },\n {\n path: \"/test2\",\n retry: { maxAttempts: 3, delay: { seconds: 1 } },\n schema: schema,\n target: async ({ taskItem, retry }: TaskContext<typeof schema>) => {\n // 마지막 시도에서만 성공하게 함.\n if (taskItem.attempt !== retry.maxAttempts) {\n throw new Error(\"실패!\");\n }\n },\n },\n ],\n\n retry: {\n delay: {},\n maxAttempts: 1,\n },\n\n tasks: [\n {\n type: \"local\",\n expression: \"*/10 * * * * *\",\n\n // local에서 실행할 때는 어느 namespace에서 어느 payload로 실행할지를 넣어야 함.\n payload: {},\n namespace: \"/test2\",\n\n // node-cron에서 쓰는 options를 공유함.\n options: {\n timezone: \"Asia/Seoul\",\n noOverlap: false,\n },\n },\n ],\n };\n}\n\n(async () => {\n const scheduler = await createScheduler(getConfig());\n scheduler.on(\"*\", (evt: TaskEvent) => {\n console.log(\"Event:\", evt);\n });\n\n scheduler.start();\n})();\n"],"names":["z","createScheduler","getConfig","schema","object","database","client","pool","min","max","connection","host","port","user","password","typeCast","field","next","type","length","value","string","routes","path","target","ctx","console","log","retry","maxAttempts","delay","seconds","taskItem","attempt","Error","tasks","expression","payload","namespace","options","timezone","noOverlap","scheduler","on","evt","start"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,QAAQ,kBAAe;AAG/C,SAASC;IACP,MAAMC,SAASH,EAAEI,MAAM;IAEvB,OAAO;QACLC,UAAU;YACRC,QAAQ;YACRC,MAAM;gBAAEC,KAAK;gBAAGC,KAAK;YAAE;YACvBC,YAAY;gBACVL,UAAU;gBACVM,MAAM;gBACNC,MAAM;gBACNC,MAAM;gBACNC,UAAU;gBACVC,UAAU,SAAUC,KAAU,EAAEC,IAAS;oBACvC,IAAID,MAAME,IAAI,KAAK,UAAUF,MAAMG,MAAM,KAAK,GAAG;wBAC/C,MAAMC,QAAQJ,MAAMK,MAAM;wBAC1B,OAAOD,QAAQA,UAAU,MAAM;oBACjC;oBACA,mCAAmC;oBACnC,IAAIJ,MAAME,IAAI,KAAK,QAAQ;wBACzB,OAAOF,MAAMK,MAAM;oBACrB;oBACA,OAAOJ;gBACT;YACF;QACF;QACAK,QAAQ;YACN;gBACEC,MAAM;gBACNpB,QAAQA;gBACRqB,QAAQ,OAAOC;oBACbC,QAAQC,GAAG,CAAC,aAAaF;gBAC3B;YACF;YACA;gBACEF,MAAM;gBACNK,OAAO;oBAAEC,aAAa;oBAAGC,OAAO;wBAAEC,SAAS;oBAAE;gBAAE;gBAC/C5B,QAAQA;gBACRqB,QAAQ,OAAO,EAAEQ,QAAQ,EAAEJ,KAAK,EAA8B;oBAC5D,oBAAoB;oBACpB,IAAII,SAASC,OAAO,KAAKL,MAAMC,WAAW,EAAE;wBAC1C,MAAM,IAAIK,MAAM;oBAClB;gBACF;YACF;SACD;QAEDN,OAAO;YACLE,OAAO,CAAC;YACRD,aAAa;QACf;QAEAM,OAAO;YACL;gBACEjB,MAAM;gBACNkB,YAAY;gBAEZ,yDAAyD;gBACzDC,SAAS,CAAC;gBACVC,WAAW;gBAEX,+BAA+B;gBAC/BC,SAAS;oBACPC,UAAU;oBACVC,WAAW;gBACb;YACF;SACD;IACH;AACF;AAEC,CAAA;IACC,MAAMC,YAAY,MAAMzC,gBAAgBC;IACxCwC,UAAUC,EAAE,CAAC,KAAK,CAACC;QACjBlB,QAAQC,GAAG,CAAC,UAAUiB;IACxB;IAEAF,UAAUG,KAAK;AACjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"03-local-retry.d.ts","sourceRoot":"","sources":["../../src/practices/03-local-retry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createScheduler } from "../scheduler.js";
|
|
3
|
+
function getConfig() {
|
|
4
|
+
const schema = z.object();
|
|
5
|
+
return {
|
|
6
|
+
database: {
|
|
7
|
+
client: "mysql2",
|
|
8
|
+
pool: {
|
|
9
|
+
min: 1,
|
|
10
|
+
max: 5
|
|
11
|
+
},
|
|
12
|
+
connection: {
|
|
13
|
+
database: "miomock",
|
|
14
|
+
host: "0.0.0.0",
|
|
15
|
+
port: 3306,
|
|
16
|
+
user: "root",
|
|
17
|
+
password: "miomock123",
|
|
18
|
+
typeCast: function(field, next) {
|
|
19
|
+
if (field.type === "TINY" && field.length === 1) {
|
|
20
|
+
const value = field.string();
|
|
21
|
+
return value ? value === "1" : null;
|
|
22
|
+
}
|
|
23
|
+
// DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)
|
|
24
|
+
if (field.type === "DATE") {
|
|
25
|
+
return field.string();
|
|
26
|
+
}
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
routes: [
|
|
32
|
+
{
|
|
33
|
+
path: "/test",
|
|
34
|
+
schema: schema,
|
|
35
|
+
target: async (ctx)=>{
|
|
36
|
+
console.log("Processed", ctx);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: "/test2",
|
|
41
|
+
retry: {
|
|
42
|
+
maxAttempts: 3,
|
|
43
|
+
// delay는 함수로 넘겨서 Exponential Backoff 등을 구현할 수 있음.
|
|
44
|
+
delay: (attempt)=>{
|
|
45
|
+
return {
|
|
46
|
+
seconds: Math.pow(3, attempt)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
schema: schema,
|
|
51
|
+
target: async ({ taskItem, retry })=>{
|
|
52
|
+
console.log(`Attempt: ${taskItem.attempt}, Max Attempts: ${retry.maxAttempts}, Time: ${new Date()}`);
|
|
53
|
+
// 마지막 시도에서만 성공하게 함.
|
|
54
|
+
if (taskItem.attempt !== retry.maxAttempts) {
|
|
55
|
+
throw new Error("실패!");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
retry: {
|
|
61
|
+
delay: {},
|
|
62
|
+
maxAttempts: 1
|
|
63
|
+
},
|
|
64
|
+
tasks: [
|
|
65
|
+
{
|
|
66
|
+
type: "local",
|
|
67
|
+
expression: "*/10 * * * * *",
|
|
68
|
+
// local에서 실행할 때는 어느 namespace에서 어느 payload로 실행할지를 넣어야 함.
|
|
69
|
+
payload: {},
|
|
70
|
+
namespace: "/test2",
|
|
71
|
+
// node-cron에서 쓰는 options를 공유함.
|
|
72
|
+
options: {
|
|
73
|
+
timezone: "Asia/Seoul",
|
|
74
|
+
noOverlap: false
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
(async ()=>{
|
|
81
|
+
const scheduler = await createScheduler(getConfig());
|
|
82
|
+
scheduler.start();
|
|
83
|
+
})();
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=03-local-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/practices/03-local-retry.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createScheduler } from \"../scheduler\";\nimport type { TaskContext, SchedulerConfig } from \"../types\";\n\nfunction getConfig(): SchedulerConfig {\n const schema = z.object();\n\n return {\n database: {\n client: \"mysql2\",\n pool: { min: 1, max: 5 },\n connection: {\n database: \"miomock\",\n host: \"0.0.0.0\",\n port: 3306,\n user: \"root\",\n password: \"miomock123\",\n typeCast: function (field: any, next: any) {\n if (field.type === \"TINY\" && field.length === 1) {\n const value = field.string();\n return value ? value === \"1\" : null;\n }\n // DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)\n if (field.type === \"DATE\") {\n return field.string();\n }\n return next();\n },\n },\n },\n routes: [\n {\n path: \"/test\",\n schema: schema,\n target: async (ctx: TaskContext<typeof schema>) => {\n console.log(\"Processed\", ctx);\n },\n },\n {\n path: \"/test2\",\n retry: {\n maxAttempts: 3,\n // delay는 함수로 넘겨서 Exponential Backoff 등을 구현할 수 있음.\n delay: (attempt: number) => {\n return { seconds: Math.pow(3, attempt) };\n },\n },\n schema: schema,\n target: async ({ taskItem, retry }: TaskContext<typeof schema>) => {\n console.log(\n `Attempt: ${taskItem.attempt}, Max Attempts: ${retry.maxAttempts}, Time: ${new Date()}`,\n );\n\n // 마지막 시도에서만 성공하게 함.\n if (taskItem.attempt !== retry.maxAttempts) {\n throw new Error(\"실패!\");\n }\n },\n },\n ],\n\n retry: {\n delay: {},\n maxAttempts: 1,\n },\n\n tasks: [\n {\n type: \"local\",\n expression: \"*/10 * * * * *\",\n\n // local에서 실행할 때는 어느 namespace에서 어느 payload로 실행할지를 넣어야 함.\n payload: {},\n namespace: \"/test2\",\n\n // node-cron에서 쓰는 options를 공유함.\n options: {\n timezone: \"Asia/Seoul\",\n noOverlap: false,\n },\n },\n ],\n };\n}\n\n(async () => {\n const scheduler = await createScheduler(getConfig());\n scheduler.start();\n})();\n"],"names":["z","createScheduler","getConfig","schema","object","database","client","pool","min","max","connection","host","port","user","password","typeCast","field","next","type","length","value","string","routes","path","target","ctx","console","log","retry","maxAttempts","delay","attempt","seconds","Math","pow","taskItem","Date","Error","tasks","expression","payload","namespace","options","timezone","noOverlap","scheduler","start"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,QAAQ,kBAAe;AAG/C,SAASC;IACP,MAAMC,SAASH,EAAEI,MAAM;IAEvB,OAAO;QACLC,UAAU;YACRC,QAAQ;YACRC,MAAM;gBAAEC,KAAK;gBAAGC,KAAK;YAAE;YACvBC,YAAY;gBACVL,UAAU;gBACVM,MAAM;gBACNC,MAAM;gBACNC,MAAM;gBACNC,UAAU;gBACVC,UAAU,SAAUC,KAAU,EAAEC,IAAS;oBACvC,IAAID,MAAME,IAAI,KAAK,UAAUF,MAAMG,MAAM,KAAK,GAAG;wBAC/C,MAAMC,QAAQJ,MAAMK,MAAM;wBAC1B,OAAOD,QAAQA,UAAU,MAAM;oBACjC;oBACA,mCAAmC;oBACnC,IAAIJ,MAAME,IAAI,KAAK,QAAQ;wBACzB,OAAOF,MAAMK,MAAM;oBACrB;oBACA,OAAOJ;gBACT;YACF;QACF;QACAK,QAAQ;YACN;gBACEC,MAAM;gBACNpB,QAAQA;gBACRqB,QAAQ,OAAOC;oBACbC,QAAQC,GAAG,CAAC,aAAaF;gBAC3B;YACF;YACA;gBACEF,MAAM;gBACNK,OAAO;oBACLC,aAAa;oBACb,kDAAkD;oBAClDC,OAAO,CAACC;wBACN,OAAO;4BAAEC,SAASC,KAAKC,GAAG,CAAC,GAAGH;wBAAS;oBACzC;gBACF;gBACA5B,QAAQA;gBACRqB,QAAQ,OAAO,EAAEW,QAAQ,EAAEP,KAAK,EAA8B;oBAC5DF,QAAQC,GAAG,CACT,CAAC,SAAS,EAAEQ,SAASJ,OAAO,CAAC,gBAAgB,EAAEH,MAAMC,WAAW,CAAC,QAAQ,EAAE,IAAIO,QAAQ;oBAGzF,oBAAoB;oBACpB,IAAID,SAASJ,OAAO,KAAKH,MAAMC,WAAW,EAAE;wBAC1C,MAAM,IAAIQ,MAAM;oBAClB;gBACF;YACF;SACD;QAEDT,OAAO;YACLE,OAAO,CAAC;YACRD,aAAa;QACf;QAEAS,OAAO;YACL;gBACEpB,MAAM;gBACNqB,YAAY;gBAEZ,yDAAyD;gBACzDC,SAAS,CAAC;gBACVC,WAAW;gBAEX,+BAA+B;gBAC/BC,SAAS;oBACPC,UAAU;oBACVC,WAAW;gBACb;YACF;SACD;IACH;AACF;AAEC,CAAA;IACC,MAAMC,YAAY,MAAM5C,gBAAgBC;IACxC2C,UAAUC,KAAK;AACjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"04-scheduler-dispose.d.ts","sourceRoot":"","sources":["../../src/practices/04-scheduler-dispose.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createScheduler } from "../scheduler.js";
|
|
3
|
+
function getConfig() {
|
|
4
|
+
const schema = z.object();
|
|
5
|
+
return {
|
|
6
|
+
database: {
|
|
7
|
+
client: "mysql2",
|
|
8
|
+
pool: {
|
|
9
|
+
min: 1,
|
|
10
|
+
max: 5
|
|
11
|
+
},
|
|
12
|
+
connection: {
|
|
13
|
+
database: "miomock",
|
|
14
|
+
host: "0.0.0.0",
|
|
15
|
+
port: 3306,
|
|
16
|
+
user: "root",
|
|
17
|
+
password: "miomock123",
|
|
18
|
+
typeCast: function(field, next) {
|
|
19
|
+
if (field.type === "TINY" && field.length === 1) {
|
|
20
|
+
const value = field.string();
|
|
21
|
+
return value ? value === "1" : null;
|
|
22
|
+
}
|
|
23
|
+
// DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)
|
|
24
|
+
if (field.type === "DATE") {
|
|
25
|
+
return field.string();
|
|
26
|
+
}
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
routes: [
|
|
32
|
+
{
|
|
33
|
+
path: "/test",
|
|
34
|
+
schema: schema,
|
|
35
|
+
target: async (ctx)=>{
|
|
36
|
+
console.log("Processed", ctx);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
retry: {
|
|
41
|
+
delay: {},
|
|
42
|
+
maxAttempts: 1
|
|
43
|
+
},
|
|
44
|
+
tasks: [
|
|
45
|
+
{
|
|
46
|
+
type: "remote",
|
|
47
|
+
expression: "5 * * * *",
|
|
48
|
+
options: {
|
|
49
|
+
timezone: "Asia/Seoul",
|
|
50
|
+
noOverlap: false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// scheduler를 dispose하면 대기 중인 Promise가 없기 때문에 프로그램은 1분 뒤에 바로 종료된다.
|
|
57
|
+
(async ()=>{
|
|
58
|
+
const scheduler = await createScheduler(getConfig());
|
|
59
|
+
setTimeout(()=>{
|
|
60
|
+
scheduler.dispose();
|
|
61
|
+
}, 60 * 1000);
|
|
62
|
+
scheduler.start();
|
|
63
|
+
})();
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=04-scheduler-dispose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/practices/04-scheduler-dispose.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createScheduler } from \"../scheduler\";\nimport type { TaskContext, SchedulerConfig } from \"../types\";\n\nfunction getConfig(): SchedulerConfig {\n const schema = z.object();\n\n return {\n database: {\n client: \"mysql2\",\n pool: { min: 1, max: 5 },\n connection: {\n database: \"miomock\",\n host: \"0.0.0.0\",\n port: 3306,\n user: \"root\",\n password: \"miomock123\",\n typeCast: function (field: any, next: any) {\n if (field.type === \"TINY\" && field.length === 1) {\n const value = field.string();\n return value ? value === \"1\" : null;\n }\n // DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)\n if (field.type === \"DATE\") {\n return field.string();\n }\n return next();\n },\n },\n },\n routes: [\n {\n path: \"/test\",\n schema: schema,\n target: async (ctx: TaskContext<typeof schema>) => {\n console.log(\"Processed\", ctx);\n },\n },\n ],\n\n retry: {\n delay: {},\n maxAttempts: 1,\n },\n\n tasks: [\n {\n type: \"remote\",\n expression: \"5 * * * *\",\n options: {\n timezone: \"Asia/Seoul\",\n noOverlap: false,\n },\n },\n ],\n };\n}\n// scheduler를 dispose하면 대기 중인 Promise가 없기 때문에 프로그램은 1분 뒤에 바로 종료된다.\n(async () => {\n const scheduler = await createScheduler(getConfig());\n setTimeout(() => {\n scheduler.dispose();\n }, 60 * 1000);\n\n scheduler.start();\n})();\n"],"names":["z","createScheduler","getConfig","schema","object","database","client","pool","min","max","connection","host","port","user","password","typeCast","field","next","type","length","value","string","routes","path","target","ctx","console","log","retry","delay","maxAttempts","tasks","expression","options","timezone","noOverlap","scheduler","setTimeout","dispose","start"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,QAAQ,kBAAe;AAG/C,SAASC;IACP,MAAMC,SAASH,EAAEI,MAAM;IAEvB,OAAO;QACLC,UAAU;YACRC,QAAQ;YACRC,MAAM;gBAAEC,KAAK;gBAAGC,KAAK;YAAE;YACvBC,YAAY;gBACVL,UAAU;gBACVM,MAAM;gBACNC,MAAM;gBACNC,MAAM;gBACNC,UAAU;gBACVC,UAAU,SAAUC,KAAU,EAAEC,IAAS;oBACvC,IAAID,MAAME,IAAI,KAAK,UAAUF,MAAMG,MAAM,KAAK,GAAG;wBAC/C,MAAMC,QAAQJ,MAAMK,MAAM;wBAC1B,OAAOD,QAAQA,UAAU,MAAM;oBACjC;oBACA,mCAAmC;oBACnC,IAAIJ,MAAME,IAAI,KAAK,QAAQ;wBACzB,OAAOF,MAAMK,MAAM;oBACrB;oBACA,OAAOJ;gBACT;YACF;QACF;QACAK,QAAQ;YACN;gBACEC,MAAM;gBACNpB,QAAQA;gBACRqB,QAAQ,OAAOC;oBACbC,QAAQC,GAAG,CAAC,aAAaF;gBAC3B;YACF;SACD;QAEDG,OAAO;YACLC,OAAO,CAAC;YACRC,aAAa;QACf;QAEAC,OAAO;YACL;gBACEb,MAAM;gBACNc,YAAY;gBACZC,SAAS;oBACPC,UAAU;oBACVC,WAAW;gBACb;YACF;SACD;IACH;AACF;AACA,kEAAkE;AACjE,CAAA;IACC,MAAMC,YAAY,MAAMnC,gBAAgBC;IACxCmC,WAAW;QACTD,UAAUE,OAAO;IACnB,GAAG,KAAK;IAERF,UAAUG,KAAK;AACjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"05-router.d.ts","sourceRoot":"","sources":["../../src/practices/05-router.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createScheduler } from "../scheduler.js";
|
|
3
|
+
function getConfig() {
|
|
4
|
+
const schema = z.object();
|
|
5
|
+
return {
|
|
6
|
+
database: {
|
|
7
|
+
client: "mysql2",
|
|
8
|
+
pool: {
|
|
9
|
+
min: 1,
|
|
10
|
+
max: 5
|
|
11
|
+
},
|
|
12
|
+
connection: {
|
|
13
|
+
database: "miomock",
|
|
14
|
+
host: "0.0.0.0",
|
|
15
|
+
port: 3306,
|
|
16
|
+
user: "root",
|
|
17
|
+
password: "miomock123",
|
|
18
|
+
typeCast: function(field, next) {
|
|
19
|
+
if (field.type === "TINY" && field.length === 1) {
|
|
20
|
+
const value = field.string();
|
|
21
|
+
return value ? value === "1" : null;
|
|
22
|
+
}
|
|
23
|
+
// DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)
|
|
24
|
+
if (field.type === "DATE") {
|
|
25
|
+
return field.string();
|
|
26
|
+
}
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
routes: [
|
|
32
|
+
{
|
|
33
|
+
path: "/test",
|
|
34
|
+
schema: schema,
|
|
35
|
+
target: async (ctx)=>{
|
|
36
|
+
console.log("Processed", ctx);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
// rou3을 쓰기 때문에, task의 path는 HTTP Router 문법에 대응됨.
|
|
41
|
+
path: "/test/:complexId",
|
|
42
|
+
retry: {
|
|
43
|
+
maxAttempts: 3,
|
|
44
|
+
delay: {
|
|
45
|
+
seconds: 1
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
schema: schema,
|
|
49
|
+
target: async ({ params })=>{
|
|
50
|
+
// router를 통해 complexId가 전달됨.
|
|
51
|
+
console.log(params?.complexId);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
retry: {
|
|
56
|
+
delay: {},
|
|
57
|
+
maxAttempts: 1
|
|
58
|
+
},
|
|
59
|
+
tasks: [
|
|
60
|
+
{
|
|
61
|
+
type: "local",
|
|
62
|
+
expression: "*/10 * * * * *",
|
|
63
|
+
// rou3을 쓰기 때문에, task의 path는 HTTP Router 문법에 대응됨.
|
|
64
|
+
namespace: "/test/some-complex-data",
|
|
65
|
+
payload: {},
|
|
66
|
+
options: {
|
|
67
|
+
timezone: "Asia/Seoul",
|
|
68
|
+
name: "local-router-test",
|
|
69
|
+
noOverlap: false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
(async ()=>{
|
|
76
|
+
const scheduler = await createScheduler(getConfig());
|
|
77
|
+
scheduler.start();
|
|
78
|
+
})();
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=05-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/practices/05-router.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { createScheduler } from \"../scheduler\";\nimport type { TaskContext, SchedulerConfig } from \"../types\";\n\nfunction getConfig(): SchedulerConfig {\n const schema = z.object();\n\n return {\n database: {\n client: \"mysql2\",\n pool: { min: 1, max: 5 },\n connection: {\n database: \"miomock\",\n host: \"0.0.0.0\",\n port: 3306,\n user: \"root\",\n password: \"miomock123\",\n typeCast: function (field: any, next: any) {\n if (field.type === \"TINY\" && field.length === 1) {\n const value = field.string();\n return value ? value === \"1\" : null;\n }\n // DATE 타입은 문자열로 유지 (YYYY-MM-dd 형태)\n if (field.type === \"DATE\") {\n return field.string();\n }\n return next();\n },\n },\n },\n routes: [\n {\n path: \"/test\",\n schema: schema,\n target: async (ctx: TaskContext<typeof schema>) => {\n console.log(\"Processed\", ctx);\n },\n },\n {\n // rou3을 쓰기 때문에, task의 path는 HTTP Router 문법에 대응됨.\n path: \"/test/:complexId\",\n retry: { maxAttempts: 3, delay: { seconds: 1 } },\n schema: schema,\n target: async ({ params }: TaskContext<typeof schema>) => {\n // router를 통해 complexId가 전달됨.\n console.log(params?.complexId);\n },\n },\n ],\n\n retry: {\n delay: {},\n maxAttempts: 1,\n },\n\n tasks: [\n {\n type: \"local\",\n expression: \"*/10 * * * * *\",\n // rou3을 쓰기 때문에, task의 path는 HTTP Router 문법에 대응됨.\n namespace: \"/test/some-complex-data\",\n payload: {},\n options: {\n timezone: \"Asia/Seoul\",\n name: \"local-router-test\",\n noOverlap: false,\n },\n },\n ],\n };\n}\n\n(async () => {\n const scheduler = await createScheduler(getConfig());\n scheduler.start();\n})();\n"],"names":["z","createScheduler","getConfig","schema","object","database","client","pool","min","max","connection","host","port","user","password","typeCast","field","next","type","length","value","string","routes","path","target","ctx","console","log","retry","maxAttempts","delay","seconds","params","complexId","tasks","expression","namespace","payload","options","timezone","name","noOverlap","scheduler","start"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,QAAQ,kBAAe;AAG/C,SAASC;IACP,MAAMC,SAASH,EAAEI,MAAM;IAEvB,OAAO;QACLC,UAAU;YACRC,QAAQ;YACRC,MAAM;gBAAEC,KAAK;gBAAGC,KAAK;YAAE;YACvBC,YAAY;gBACVL,UAAU;gBACVM,MAAM;gBACNC,MAAM;gBACNC,MAAM;gBACNC,UAAU;gBACVC,UAAU,SAAUC,KAAU,EAAEC,IAAS;oBACvC,IAAID,MAAME,IAAI,KAAK,UAAUF,MAAMG,MAAM,KAAK,GAAG;wBAC/C,MAAMC,QAAQJ,MAAMK,MAAM;wBAC1B,OAAOD,QAAQA,UAAU,MAAM;oBACjC;oBACA,mCAAmC;oBACnC,IAAIJ,MAAME,IAAI,KAAK,QAAQ;wBACzB,OAAOF,MAAMK,MAAM;oBACrB;oBACA,OAAOJ;gBACT;YACF;QACF;QACAK,QAAQ;YACN;gBACEC,MAAM;gBACNpB,QAAQA;gBACRqB,QAAQ,OAAOC;oBACbC,QAAQC,GAAG,CAAC,aAAaF;gBAC3B;YACF;YACA;gBACE,iDAAiD;gBACjDF,MAAM;gBACNK,OAAO;oBAAEC,aAAa;oBAAGC,OAAO;wBAAEC,SAAS;oBAAE;gBAAE;gBAC/C5B,QAAQA;gBACRqB,QAAQ,OAAO,EAAEQ,MAAM,EAA8B;oBACnD,6BAA6B;oBAC7BN,QAAQC,GAAG,CAACK,QAAQC;gBACtB;YACF;SACD;QAEDL,OAAO;YACLE,OAAO,CAAC;YACRD,aAAa;QACf;QAEAK,OAAO;YACL;gBACEhB,MAAM;gBACNiB,YAAY;gBACZ,iDAAiD;gBACjDC,WAAW;gBACXC,SAAS,CAAC;gBACVC,SAAS;oBACPC,UAAU;oBACVC,MAAM;oBACNC,WAAW;gBACb;YACF;SACD;IACH;AACF;AAEC,CAAA;IACC,MAAMC,YAAY,MAAMzC,gBAAgBC;IACxCwC,UAAUC,KAAK;AACjB,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Workflow } from "./workflow";
|
|
2
|
+
/**
|
|
3
|
+
* A registry for storing and retrieving workflows by name and version.
|
|
4
|
+
* Provides a centralized way to manage workflow registrations.
|
|
5
|
+
*/
|
|
6
|
+
export declare class WorkflowRegistry {
|
|
7
|
+
private readonly workflows;
|
|
8
|
+
/**
|
|
9
|
+
* Register a workflow in the registry.
|
|
10
|
+
* @param workflow - The workflow to register
|
|
11
|
+
* @throws {Error} If a workflow with the same name and version is already registered
|
|
12
|
+
*/
|
|
13
|
+
register(workflow: Workflow<unknown, unknown, unknown>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Get a workflow from the registry by name and version.
|
|
16
|
+
* @param name - The workflow name
|
|
17
|
+
* @param version - The workflow version (null for unversioned)
|
|
18
|
+
* @returns The workflow if found, undefined otherwise
|
|
19
|
+
*/
|
|
20
|
+
get(name: string, version: string | null): Workflow<unknown, unknown, unknown> | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Get a workflow from the registry by name and version.
|
|
23
|
+
* @param name - The workflow name
|
|
24
|
+
* @param version - The workflow version (null for unversioned)
|
|
25
|
+
* @returns The workflow if found, undefined otherwise
|
|
26
|
+
*/
|
|
27
|
+
has(name: string, version: string | null): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Remove a workflow from the registry by name and version.
|
|
30
|
+
*/
|
|
31
|
+
remove(name: string, version: string | null): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0D;IAEpF;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI;IAW7D;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS;IAK1F;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAKlD;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;CAInD"}
|