@lango-project/lango-boss 0.0.0-stage → 0.1.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 (121) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +118 -2
  4. package/dist/.lango/bignumber.mjs +3119 -0
  5. package/dist/.lango/entries/cli.mjs +139 -0
  6. package/dist/.lango/entries/cli.mjs.map +1 -0
  7. package/dist/.lango/localization.mjs +108 -0
  8. package/dist/.lango/runtime.mjs +725 -0
  9. package/dist/.lango/vendor/i18next.LICENSE +21 -0
  10. package/dist/.lango/vendor/i18next.mjs +2434 -0
  11. package/dist/.lango/xmldom/conventions.js +429 -0
  12. package/dist/.lango/xmldom/dom-parser.js +591 -0
  13. package/dist/.lango/xmldom/dom.js +3759 -0
  14. package/dist/.lango/xmldom/entities.js +2171 -0
  15. package/dist/.lango/xmldom/errors.js +205 -0
  16. package/dist/.lango/xmldom/grammar.js +559 -0
  17. package/dist/.lango/xmldom/index.js +41 -0
  18. package/dist/.lango/xmldom/package.json +1 -0
  19. package/dist/.lango/xmldom/sax.js +983 -0
  20. package/dist/.lango/xmldom.LICENSE.md +8 -0
  21. package/dist/boss.mjs +136 -0
  22. package/dist/boss.mjs.map +1 -0
  23. package/dist/claim_watch.mjs +99 -0
  24. package/dist/claim_watch.mjs.map +1 -0
  25. package/dist/cli.mjs +7 -0
  26. package/dist/cli.mjs.map +1 -0
  27. package/dist/configuration.mjs +58 -0
  28. package/dist/configuration.mjs.map +1 -0
  29. package/dist/dispatcher.mjs +108 -0
  30. package/dist/dispatcher.mjs.map +1 -0
  31. package/dist/driver.mjs +98 -0
  32. package/dist/driver.mjs.map +1 -0
  33. package/dist/envelope.mjs +92 -0
  34. package/dist/envelope.mjs.map +1 -0
  35. package/dist/library.mjs +139 -0
  36. package/dist/library.mjs.map +1 -0
  37. package/dist/management.mjs +360 -0
  38. package/dist/management.mjs.map +1 -0
  39. package/dist/management_transaction.mjs +26 -0
  40. package/dist/management_transaction.mjs.map +1 -0
  41. package/dist/namespace.mjs +27 -0
  42. package/dist/namespace.mjs.map +1 -0
  43. package/dist/queue.mjs +161 -0
  44. package/dist/queue.mjs.map +1 -0
  45. package/dist/reads.mjs +359 -0
  46. package/dist/reads.mjs.map +1 -0
  47. package/dist/retention.mjs +133 -0
  48. package/dist/retention.mjs.map +1 -0
  49. package/dist/schedule_sync.mjs +222 -0
  50. package/dist/schedule_sync.mjs.map +1 -0
  51. package/dist/schedule_transaction.mjs +24 -0
  52. package/dist/schedule_transaction.mjs.map +1 -0
  53. package/dist/schedules.mjs +201 -0
  54. package/dist/schedules.mjs.map +1 -0
  55. package/dist/transaction.mjs +16 -0
  56. package/dist/transaction.mjs.map +1 -0
  57. package/dist/validation.mjs +90 -0
  58. package/dist/validation.mjs.map +1 -0
  59. package/dist/worker.mjs +316 -0
  60. package/dist/worker.mjs.map +1 -0
  61. package/docs/guide.md +88 -0
  62. package/docs/management.md +93 -0
  63. package/docs/producer.md +115 -0
  64. package/docs/reads.md +107 -0
  65. package/docs/reference.md +77 -0
  66. package/docs/release.md +103 -0
  67. package/docs/retention.md +47 -0
  68. package/docs/scheduling.md +79 -0
  69. package/docs/worker.md +90 -0
  70. package/examples/reports/README.md +118 -0
  71. package/examples/reports/app.lango +133 -0
  72. package/examples/reports/deploy.xml +6 -0
  73. package/examples/reports/dist/.lango/bignumber.mjs +3119 -0
  74. package/examples/reports/dist/.lango/entries/app.mjs +133 -0
  75. package/examples/reports/dist/.lango/entries/app.mjs.map +1 -0
  76. package/examples/reports/dist/.lango/localization.mjs +108 -0
  77. package/examples/reports/dist/.lango/runtime.mjs +725 -0
  78. package/examples/reports/dist/.lango/vendor/i18next.LICENSE +21 -0
  79. package/examples/reports/dist/.lango/vendor/i18next.mjs +2434 -0
  80. package/examples/reports/dist/.lango/xmldom/conventions.js +429 -0
  81. package/examples/reports/dist/.lango/xmldom/dom-parser.js +591 -0
  82. package/examples/reports/dist/.lango/xmldom/dom.js +3759 -0
  83. package/examples/reports/dist/.lango/xmldom/entities.js +2171 -0
  84. package/examples/reports/dist/.lango/xmldom/errors.js +205 -0
  85. package/examples/reports/dist/.lango/xmldom/grammar.js +559 -0
  86. package/examples/reports/dist/.lango/xmldom/index.js +41 -0
  87. package/examples/reports/dist/.lango/xmldom/package.json +1 -0
  88. package/examples/reports/dist/.lango/xmldom/sax.js +983 -0
  89. package/examples/reports/dist/.lango/xmldom.LICENSE.md +8 -0
  90. package/examples/reports/dist/app.mjs +7 -0
  91. package/examples/reports/dist/app.mjs.map +1 -0
  92. package/examples/reports/dist/handlers.mjs +202 -0
  93. package/examples/reports/dist/handlers.mjs.map +1 -0
  94. package/examples/reports/dist/setup.mjs +14 -0
  95. package/examples/reports/dist/setup.mjs.map +1 -0
  96. package/examples/reports/handlers.lango +153 -0
  97. package/examples/reports/jobs.xml +5 -0
  98. package/examples/reports/package.json +23 -0
  99. package/examples/reports/routes.xml +4 -0
  100. package/examples/reports/setup.lango +17 -0
  101. package/package.json +62 -4
  102. package/src/boss.lango +92 -0
  103. package/src/claim_watch.lango +58 -0
  104. package/src/cli.lango +103 -0
  105. package/src/configuration.lango +43 -0
  106. package/src/dispatcher.lango +75 -0
  107. package/src/driver.lango +72 -0
  108. package/src/envelope.lango +56 -0
  109. package/src/library.lango +66 -0
  110. package/src/management.lango +302 -0
  111. package/src/management_transaction.lango +28 -0
  112. package/src/namespace.lango +15 -0
  113. package/src/queue.lango +115 -0
  114. package/src/reads.lango +277 -0
  115. package/src/retention.lango +107 -0
  116. package/src/schedule_sync.lango +190 -0
  117. package/src/schedule_transaction.lango +22 -0
  118. package/src/schedules.lango +165 -0
  119. package/src/transaction.lango +23 -0
  120. package/src/validation.lango +45 -0
  121. package/src/worker.lango +230 -0
@@ -0,0 +1,133 @@
1
+ import { schemaName } from "./namespace.mjs";
2
+ import * as server from "@lango-project/lango-server";
3
+ import {
4
+ hostGlobal as __hostGlobal,
5
+ hostGlobalCall as __hostGlobalCall,
6
+ contextGet as __contextGet,
7
+ contextSet as __contextSet,
8
+ contextRestore as __contextRestore,
9
+ bindContexts as __bindContexts,
10
+ requireBoolean as __requireBoolean,
11
+ normalize as __normalize,
12
+ finite as __finite,
13
+ boundary as __boundary,
14
+ query as __query,
15
+ requireArity as __requireArity,
16
+ withArity as __withArity,
17
+ } from "./.lango/runtime.mjs";
18
+
19
+ export class Retention {
20
+ #config;
21
+ #interval;
22
+ #batchSize;
23
+ #timer;
24
+ #pending;
25
+ #closed;
26
+ constructor(config, intervalSeconds, batchSize) {
27
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
28
+ config = __boundary(config);
29
+ intervalSeconds = __boundary(intervalSeconds);
30
+ batchSize = __boundary(batchSize);
31
+ this.#config = config;
32
+ this.#interval = __finite(intervalSeconds * 1000);
33
+ this.#batchSize = batchSize;
34
+ this.#timer = null;
35
+ this.#pending = null;
36
+ this.#closed = false;
37
+ }
38
+ start() {
39
+ this.#pending = this.#sweep();
40
+ return __normalize(this.#pending).then(__withArity(__bindContexts((ignored) => {
41
+ ignored = __boundary(ignored);
42
+ this.#arm();
43
+ return null;
44
+ }), [0], "closure"));
45
+ return null;
46
+ }
47
+ #arm() {
48
+ if (__requireBoolean(__normalize(this.#closed))) {
49
+ return null;
50
+ }
51
+ let fire = __bindContexts(() => {
52
+ this.#timer = null;
53
+ this.#pending = this.#sweep();
54
+ this.#pending = __normalize(this.#pending).catch(__withArity(__bindContexts((error) => {
55
+ const __contextScope = [];
56
+ try {
57
+ error = __boundary(error);
58
+ __normalize(__contextGet("log").err(`Boss retention cleanup failed: ${error}`));
59
+ return null;
60
+ } finally {
61
+ __contextRestore(__contextScope);
62
+ }
63
+ }), [0], "closure")).finally(__bindContexts(() => {
64
+ this.#arm();
65
+ return null;
66
+ }));
67
+ return null;
68
+ });
69
+ this.#timer = __hostGlobalCall(["setTimeout"], fire, __normalize(this.#interval));
70
+ __normalize(this.#timer.unref());
71
+ return null;
72
+ return null;
73
+ }
74
+ #sweep() {
75
+ return __normalize(__hostGlobal(["Promise"]).resolve(null)).then(__withArity(__bindContexts((ignored) => {
76
+ ignored = __boundary(ignored);
77
+ return cleanRecords(__normalize(this.#config), __normalize(this.#batchSize));
78
+ return null;
79
+ }), [0], "closure")).then(__withArity(__bindContexts((count) => {
80
+ const __contextScope = [];
81
+ try {
82
+ count = __boundary(count);
83
+ __normalize(__contextGet("log").debug(`Boss retention cleanup removed ${count} terminal jobs`));
84
+ return count;
85
+ return null;
86
+ } finally {
87
+ __contextRestore(__contextScope);
88
+ }
89
+ }), [0], "closure"));
90
+ return null;
91
+ }
92
+ close() {
93
+ this.#closed = true;
94
+ if (__requireBoolean(__normalize(this.#timer) !== null)) {
95
+ __hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
96
+ this.#timer = null;
97
+ }
98
+ return __normalize(__hostGlobal(["Promise"]).resolve(__normalize(this.#pending)));
99
+ return null;
100
+ }
101
+ }
102
+ function scope(config) {
103
+ __requireArity(arguments.length, [0], "scope");
104
+ config = __boundary(config);
105
+ let schema = schemaName(__normalize(config.application));
106
+ let query = __query("select set_config('search_path', :schema, false)", ["schema"]);
107
+ query.schema = schema;
108
+ __normalize(query.execute());
109
+ return null;
110
+ return null;
111
+ }
112
+
113
+ export function cleanRecords(config, batchSize) {
114
+ __requireArity(arguments.length, [0, 1], "cleanRecords");
115
+ config = __boundary(config);
116
+ batchSize = __boundary(batchSize);
117
+ let action = __bindContexts(() => {
118
+ scope(config);
119
+ let protect = __query("update job set deletion_seconds = 0\nwhere data->>'application' = :application and data->>'version' = '1'\n and deletion_seconds <> 0", ["application"]);
120
+ protect.application = __normalize(config.application);
121
+ __normalize(protect.execute());
122
+ let query = __query("with candidates as (\n select name, id from job\n where data->>'application' = :application and data->>'version' = '1'\n and state in ('failed', 'completed', 'cancelled')\n and completed_on is not null\n and completed_on + (\n case when state = 'failed' then\n case when jsonb_typeof(data->'failedRetentionSeconds') = 'number' then\n case when (data->>'failedRetentionSeconds')::numeric between 1 and 2147483647\n and trunc((data->>'failedRetentionSeconds')::numeric) = (data->>'failedRetentionSeconds')::numeric\n then (data->>'failedRetentionSeconds')::numeric else 604800 end\n else 604800 end\n else 604800 end\n ) * interval '1 second' <= now()\n order by completed_on, name, id\n limit :batchSize for update skip locked\n), removed as (\n delete from job j using candidates c\n where j.name = c.name and j.id = c.id\n returning j.id\n)\nselect count(*)::integer as total from removed", ["application","batchSize"]);
123
+ query.application = __normalize(config.application);
124
+ query.batchSize = batchSize;
125
+ __normalize(query.execute());
126
+ __normalize(query.next());
127
+ return __normalize(query.total);
128
+ return null;
129
+ });
130
+ return __normalize(server.withDatabase(__normalize(config.root), action));
131
+ return null;
132
+ }
133
+ //# sourceMappingURL=retention.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.mjs","sources":["retention.lango"],"sourcesContent":["import \"./namespace\"\n schemaName(application)\nimport js \"@lango-project/lango-server\" as server\nimport js global Promise\nimport js global setTimeout\nimport js global clearTimeout\n\nexport cleanRecords(config, batchSize)\nexport class Retention(config, intervalSeconds, batchSize)\n methods\n start()\n close()\n\nRetention(config, intervalSeconds, batchSize)\n @config = config\n @interval = intervalSeconds * 1000\n @batchSize = batchSize\n @timer = null\n @pending = null\n @closed = false\n\nRetention:start()\n @pending = sweep()\n return chain @pending\n then(ignored)\n arm()\n\nRetention:arm()\n if @closed\n return null\n fire = ()\n @timer = null\n @pending = sweep()\n @pending = chain @pending\n catch(error)\n context log\n log.err(\"Boss retention cleanup failed: ${error}\")\n finally\n arm()\n @timer = setTimeout(fire, @interval)\n @timer.unref()\n return null\n\nRetention:sweep()\n return chain Promise/resolve(null)\n then(ignored)\n return cleanRecords(@config, @batchSize)\n then(count)\n context log\n log.debug(\"Boss retention cleanup removed ${count} terminal jobs\")\n return count\n\nRetention:close()\n @closed = true\n if @timer != null\n clearTimeout(@timer)\n @timer = null\n return Promise/resolve(@pending)\n\nscope(config)\n schema = schemaName(config.application)\n query = SQL\n select set_config('search_path', :schema, false)\n query.schema = schema\n query.execute()\n return null\n\ncleanRecords(config, batchSize)\n action = ()\n capture config\n capture batchSize\n scope(config)\n protect = SQL\n update job set deletion_seconds = 0\n where data->>'application' = :application and data->>'version' = '1'\n and deletion_seconds <> 0\n protect.application = config.application\n protect.execute()\n query = SQL\n with candidates as (\n select name, id from job\n where data->>'application' = :application and data->>'version' = '1'\n and state in ('failed', 'completed', 'cancelled')\n and completed_on is not null\n and completed_on + (\n case when state = 'failed' then\n case when jsonb_typeof(data->'failedRetentionSeconds') = 'number' then\n case when (data->>'failedRetentionSeconds')::numeric between 1 and 2147483647\n and trunc((data->>'failedRetentionSeconds')::numeric) = (data->>'failedRetentionSeconds')::numeric\n then (data->>'failedRetentionSeconds')::numeric else 604800 end\n else 604800 end\n else 604800 end\n ) * interval '1 second' <= now()\n order by completed_on, name, id\n limit :batchSize for update skip locked\n ), removed as (\n delete from job j using candidates c\n where j.name = c.name and j.id = c.id\n returning j.id\n )\n select count(*)::integer as total from removed\n query.application = config.application\n query.batchSize = batchSize\n query.execute()\n query.next()\n return query.total\n return server/withDatabase(config.root, action)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA;;;;;;;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"1843c3a7471c7e6752cf82860fb71ca2a88a54d0b1637ef3c0bc2cbecfd2d480","outputHash":"5c581087afeda8719fd2c3c10305cc07f89e109d70da636d984b5c97c8da48c8","mapHash":"caf62d8848f77be1720d5891b1ad82badd70db5fda09a98e19abbc47dfc2a0f9"}}
@@ -0,0 +1,222 @@
1
+ import { schemaName, scheduleKey } from "./namespace.mjs";
2
+ import * as server from "@lango-project/lango-server";
3
+ import * as crypto from "node:crypto";
4
+ import {
5
+ hostGlobal as __hostGlobal,
6
+ contextGet as __contextGet,
7
+ contextSet as __contextSet,
8
+ contextRestore as __contextRestore,
9
+ bindContexts as __bindContexts,
10
+ fromJson as __fromJson,
11
+ toJson as __toJson,
12
+ isNumber as __isNumber,
13
+ isString as __isString,
14
+ isBool as __isBool,
15
+ isObject as __isObject,
16
+ isArray as __isArray,
17
+ requireBoolean as __requireBoolean,
18
+ normalize as __normalize,
19
+ boundary as __boundary,
20
+ startTrans as __startTrans,
21
+ commitTrans as __commitTrans,
22
+ rollbackTrans as __rollbackTrans,
23
+ transState as __transState,
24
+ query as __query,
25
+ requireArity as __requireArity,
26
+ } from "./.lango/runtime.mjs";
27
+
28
+ export function synchronizeSchedules(config) {
29
+ __requireArity(arguments.length, [0], "synchronizeSchedules");
30
+ config = __boundary(config);
31
+ let action = __bindContexts(() => {
32
+ return synchronize(config);
33
+ return null;
34
+ });
35
+ return __normalize(server.withDatabase(__normalize(config.root), action));
36
+ return null;
37
+ }
38
+
39
+ function fingerprint(items) {
40
+ __requireArity(arguments.length, [0], "fingerprint");
41
+ items = __boundary(items);
42
+ let definitions = __normalize(__hostGlobal(["Object"]).create(null));
43
+ for (const item of items) {
44
+ definitions[__normalize(item.name)] = item;
45
+ }
46
+ let hash = __normalize(crypto.createHash("sha256"));
47
+ __normalize(hash.update(__toJson(canonical(definitions))));
48
+ return __normalize(hash.digest("hex"));
49
+ return null;
50
+ }
51
+
52
+ function canonical(value) {
53
+ __requireArity(arguments.length, [0], "canonical");
54
+ value = __boundary(value);
55
+ let array;
56
+ let result;
57
+ let keys;
58
+ if (__requireBoolean(__isArray(value))) {
59
+ array = [];
60
+ for (const item of value) {
61
+ array.push(canonical(item));
62
+ }
63
+ return array;
64
+ }
65
+ if (__requireBoolean(__requireBoolean(__isObject(value)) && __requireBoolean(value !== null))) {
66
+ result = __normalize(__hostGlobal(["Object"]).create(null));
67
+ keys = __normalize(__hostGlobal(["Object"]).keys(value));
68
+ __normalize(keys.sort());
69
+ for (const key of keys) {
70
+ result[key] = canonical(__normalize(value[key]));
71
+ }
72
+ return result;
73
+ }
74
+ return value;
75
+ return null;
76
+ }
77
+
78
+ function synchronize(config) {
79
+ __requireArity(arguments.length, [0], "synchronize");
80
+ config = __boundary(config);
81
+ let lock;
82
+ let stamp;
83
+ let current;
84
+ let store;
85
+ let schema = schemaName(__normalize(config.application));
86
+ let search = __query("select set_config('search_path', :schema, false)", ["schema"]);
87
+ search.schema = schema;
88
+ __normalize(search.execute());
89
+ __startTrans();
90
+ try {
91
+ lock = __query("select pg_advisory_xact_lock(hashtextextended(:name, 0))", ["name"]);
92
+ lock.name = `lango-boss:schedules:${__normalize(config.application)}`;
93
+ __normalize(lock.execute());
94
+ initializeSchedules(schema);
95
+ stamp = fingerprint(__normalize(config.schedules));
96
+ current = __query("select application, revision, fingerprint from lango_schedule_state where id = 1 for update", []);
97
+ __normalize(current.execute());
98
+ if (__requireBoolean(__normalize(current.next()))) {
99
+ if (__requireBoolean(__normalize(current.application) !== __normalize(config.application))) {
100
+ throw "Schedule schema belongs to another application";
101
+ }
102
+ if (__requireBoolean(__normalize(config.scheduleRevision) < __normalize(current.revision))) {
103
+ throw "Schedule revision is older than the deployed revision";
104
+ }
105
+ if (__requireBoolean(__requireBoolean(__normalize(config.scheduleRevision) === __normalize(current.revision)) && __requireBoolean(stamp !== __normalize(current.fingerprint)))) {
106
+ throw "Schedule content changed without increasing revision";
107
+ }
108
+ }
109
+ applyDefinitions(config, schema);
110
+ store = __query("insert into lango_schedule_state (id, application, revision, fingerprint)\nvalues (1, :application, :revision, :fingerprint)\non conflict (id) do update set revision = excluded.revision,\n fingerprint = excluded.fingerprint, updated_at = now()", ["application","revision","fingerprint"]);
111
+ store.application = __normalize(config.application);
112
+ store.revision = __normalize(config.scheduleRevision);
113
+ store.fingerprint = stamp;
114
+ __normalize(store.execute());
115
+ __commitTrans();
116
+ } catch (error) {
117
+ __rollbackTrans();
118
+ throw error;
119
+ }
120
+ return null;
121
+ return null;
122
+ }
123
+
124
+ export function initializeSchedules(schema) {
125
+ __requireArity(arguments.length, [0], "initializeSchedules");
126
+ schema = __boundary(schema);
127
+ let state = __query("create table if not exists " + String(schema) + ".lango_schedule_state (\n id integer primary key check (id = 1), application text not null,\n revision integer not null, fingerprint text not null,\n updated_at timestamptz not null default now()\n)", []);
128
+ __normalize(state.execute());
129
+ let entries = __query("create table if not exists " + String(schema) + ".lango_schedule_definitions (\n name text primary key, queue text not null, key text not null,\n definition jsonb not null, paused boolean not null default false,\n present boolean not null default true,\n updated_at timestamptz not null default now(), unique (queue, key)\n)", []);
130
+ __normalize(entries.execute());
131
+ return null;
132
+ return null;
133
+ }
134
+
135
+ export function operation(schema, action, queue, key, item = null) {
136
+ const __contextScope = [];
137
+ try {
138
+ __requireArity(arguments.length, [0, 1, 2, 3], "operation");
139
+ schema = __boundary(schema);
140
+ action = __boundary(action);
141
+ queue = __boundary(queue);
142
+ key = __boundary(key);
143
+ item = __boundary(item);
144
+ let input = { schema: schema, action: action, queue: queue, key: key };
145
+ if (__requireBoolean(item !== null)) {
146
+ input.cron = __normalize(item.cron);
147
+ input.payload = { version: 1, application: __normalize(item.application), path: __normalize(item.path), input: __normalize(item.data), source: { kind: "system", identity: __normalize(item.identity) }, failedRetentionSeconds: item.retry.failedRetentionSeconds };
148
+ input.options = { key: key, tz: __normalize(item.timeZone), missed: __normalize(item.missed), precision: __normalize(item.precision), retryLimit: item.retry.retryLimit, retryDelay: item.retry.retryDelay, retryBackoff: item.retry.retryBackoff, retryDelayMax: item.retry.retryDelayMax, expireInSeconds: item.retry.expireInSeconds, heartbeatSeconds: 30, deleteAfterSeconds: 0 };
149
+ }
150
+ return __normalize(__contextGet("db").invoke({ module: "@lango-project/lango-boss/schedule-transaction", handler: "apply" }, input));
151
+ return null;
152
+ } finally {
153
+ __contextRestore(__contextScope);
154
+ }
155
+ }
156
+
157
+ function applyDefinitions(config, schema) {
158
+ __requireArity(arguments.length, [0, 1], "applyDefinitions");
159
+ config = __boundary(config);
160
+ schema = __boundary(schema);
161
+ let desired = __normalize(__hostGlobal(["Object"]).create(null));
162
+ for (const item of __normalize(config.schedules)) {
163
+ desired[__normalize(item.name)] = true;
164
+ }
165
+ let existing = __query("select name, queue, key from lango_schedule_definitions where present = true", []);
166
+ __normalize(existing.execute());
167
+ __loop1: while (__requireBoolean(__normalize(existing.next()))) {
168
+ if (__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(desired, __normalize(existing.name)))))) {
169
+ operation(schema, "remove", __normalize(existing.queue), __normalize(existing.key));
170
+ let missing = __query("update lango_schedule_definitions set present = false, updated_at = now() where name = :name", ["name"]);
171
+ missing.name = __normalize(existing.name);
172
+ __normalize(missing.execute());
173
+ }
174
+ }
175
+ for (const item of __normalize(config.schedules)) {
176
+ applyDefinition(__normalize(config.application), schema, item);
177
+ }
178
+ return null;
179
+ return null;
180
+ }
181
+
182
+ function applyDefinition(application, schema, supplied) {
183
+ __requireArity(arguments.length, [0, 1, 2], "applyDefinition");
184
+ application = __boundary(application);
185
+ schema = __boundary(schema);
186
+ supplied = __boundary(supplied);
187
+ let collision;
188
+ let item = __normalize(__hostGlobal(["Object"]).assign({ }, supplied, { application: application }));
189
+ let key = scheduleKey(application, __normalize(item.name));
190
+ let old = __query("select queue, key, paused from lango_schedule_definitions where name = :name", ["name"]);
191
+ old.name = __normalize(item.name);
192
+ __normalize(old.execute());
193
+ let found = __normalize(old.next());
194
+ let paused = false;
195
+ if (__requireBoolean(found)) {
196
+ paused = __normalize(old.paused);
197
+ }
198
+ let moved = __requireBoolean(found) && __requireBoolean(__requireBoolean(__normalize(old.queue) !== __normalize(item.queue)) || __requireBoolean(__normalize(old.key) !== key));
199
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(found)) || __requireBoolean(moved))) {
200
+ collision = operation(schema, "get", __normalize(item.queue), key);
201
+ if (__requireBoolean(collision !== null)) {
202
+ throw `Schedule key already exists outside the managed registry: ${__normalize(item.name)}`;
203
+ }
204
+ }
205
+ if (__requireBoolean(moved)) {
206
+ operation(schema, "remove", __normalize(old.queue), __normalize(old.key));
207
+ }
208
+ if (__requireBoolean(__requireBoolean(__normalize(item.enabled)) && __requireBoolean(!__requireBoolean(paused)))) {
209
+ operation(schema, "upsert", __normalize(item.queue), key, item);
210
+ } else {
211
+ operation(schema, "remove", __normalize(item.queue), key);
212
+ }
213
+ let store = __query("insert into lango_schedule_definitions (name, queue, key, definition)\nvalues (:name, :queue, :key, :definition::jsonb)\non conflict (name) do update set queue = excluded.queue, key = excluded.key,\n definition = excluded.definition, present = true, updated_at = now()", ["name","queue","key","definition"]);
214
+ store.name = __normalize(item.name);
215
+ store.queue = __normalize(item.queue);
216
+ store.key = key;
217
+ store.definition = __toJson(supplied);
218
+ __normalize(store.execute());
219
+ return null;
220
+ return null;
221
+ }
222
+ //# sourceMappingURL=schedule_sync.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule_sync.mjs","sources":["schedule_sync.lango"],"sourcesContent":["import \"./namespace\"\n schemaName(application)\n scheduleKey(application, name)\nimport js \"@lango-project/lango-server\" as server\nimport js \"node:crypto\" as crypto\nimport js global Object\n\nexport synchronizeSchedules(config)\nexport initializeSchedules(schema)\nexport operation(schema, action, queue, key, item = null)\n\nsynchronizeSchedules(config)\n action = ()\n capture config\n return synchronize(config)\n return server/withDatabase(config.root, action)\n\nfingerprint(items)\n definitions = Object/create(null)\n for items as item\n definitions[item.name] = item\n hash = crypto/createHash(\"sha256\")\n hash.update(to_json(canonical(definitions)))\n return hash.digest(\"hex\")\n\ncanonical(value)\n if is_array(value)\n array = []\n for value as item\n array.add(canonical(item))\n return array\n if is_object(value) and value != null\n result = Object/create(null)\n keys = Object/keys(value)\n keys.sort()\n for keys as key\n result[key] = canonical(value[key])\n return result\n return value\n\nsynchronize(config)\n schema = schemaName(config.application)\n search = SQL\n select set_config('search_path', :schema, false)\n search.schema = schema\n search.execute()\n start_trans()\n try\n lock = SQL\n select pg_advisory_xact_lock(hashtextextended(:name, 0))\n lock.name = \"lango-boss:schedules:${config.application}\"\n lock.execute()\n initializeSchedules(schema)\n stamp = fingerprint(config.schedules)\n current = SQL\n select application, revision, fingerprint from lango_schedule_state where id = 1 for update\n current.execute()\n if current.next()\n if current.application != config.application\n throw \"Schedule schema belongs to another application\"\n if config.scheduleRevision < current.revision\n throw \"Schedule revision is older than the deployed revision\"\n if config.scheduleRevision == current.revision and stamp != current.fingerprint\n throw \"Schedule content changed without increasing revision\"\n applyDefinitions(config, schema)\n store = SQL\n insert into lango_schedule_state (id, application, revision, fingerprint)\n values (1, :application, :revision, :fingerprint)\n on conflict (id) do update set revision = excluded.revision,\n fingerprint = excluded.fingerprint, updated_at = now()\n store.application = config.application\n store.revision = config.scheduleRevision\n store.fingerprint = stamp\n store.execute()\n commit_trans()\n catch error\n rollback_trans()\n throw error\n return null\n\ninitializeSchedules(schema)\n state = SQL\n create table if not exists ${schema}.lango_schedule_state (\n id integer primary key check (id = 1), application text not null,\n revision integer not null, fingerprint text not null,\n updated_at timestamptz not null default now()\n )\n state.execute()\n entries = SQL\n create table if not exists ${schema}.lango_schedule_definitions (\n name text primary key, queue text not null, key text not null,\n definition jsonb not null, paused boolean not null default false,\n present boolean not null default true,\n updated_at timestamptz not null default now(), unique (queue, key)\n )\n entries.execute()\n return null\n\noperation(schema, action, queue, key, item = null)\n context db\n input = {\n schema: schema\n action: action\n queue: queue\n key: key\n }\n if item != null\n input.cron = item.cron\n input.payload = {\n version: 1\n application: item.application\n path: item.path\n input: item.data\n source: {\n kind: \"system\"\n identity: item.identity\n }\n failedRetentionSeconds: item.retry.failedRetentionSeconds\n }\n input.options = {\n key: key\n tz: item.timeZone\n missed: item.missed\n precision: item.precision\n retryLimit: item.retry.retryLimit\n retryDelay: item.retry.retryDelay\n retryBackoff: item.retry.retryBackoff\n retryDelayMax: item.retry.retryDelayMax\n expireInSeconds: item.retry.expireInSeconds\n heartbeatSeconds: 30\n deleteAfterSeconds: 0\n }\n return db.invoke({\n module: \"@lango-project/lango-boss/schedule-transaction\"\n handler: \"apply\"\n }, input)\n\napplyDefinitions(config, schema)\n desired = Object/create(null)\n for config.schedules as item\n desired[item.name] = true\n existing = SQL\n select name, queue, key from lango_schedule_definitions where present = true\n existing.execute()\n loop while existing.next()\n if !Object/hasOwn(desired, existing.name)\n operation(schema, \"remove\", existing.queue, existing.key)\n missing = SQL\n update lango_schedule_definitions set present = false, updated_at = now() where name = :name\n missing.name = existing.name\n missing.execute()\n for config.schedules as item\n applyDefinition(config.application, schema, item)\n return null\n\napplyDefinition(application, schema, supplied)\n item = Object/assign({}, supplied, {\n application: application\n })\n key = scheduleKey(application, item.name)\n old = SQL\n select queue, key, paused from lango_schedule_definitions where name = :name\n old.name = item.name\n old.execute()\n found = old.next()\n paused = false\n if found\n paused = old.paused\n moved = found and (old.queue != item.queue or old.key != key)\n if !found or moved\n collision = operation(schema, \"get\", item.queue, key)\n if collision != null\n throw \"Schedule key already exists outside the managed registry: ${item.name}\"\n if moved\n operation(schema, \"remove\", old.queue, old.key)\n if item.enabled and !paused\n operation(schema, \"upsert\", item.queue, key, item)\n else\n operation(schema, \"remove\", item.queue, key)\n store = SQL\n insert into lango_schedule_definitions (name, queue, key, definition)\n values (:name, :queue, :key, :definition::jsonb)\n on conflict (name) do update set queue = excluded.queue, key = excluded.key,\n definition = excluded.definition, present = true, updated_at = now()\n store.name = item.name\n store.queue = item.queue\n store.key = key\n store.definition = to_json(supplied)\n store.execute()\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;AAMA;;;;;;;;;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;AAuCA;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"53ad7019bade46834282149c8b40437e047ed1843e7cfb0a4cc67581c8754cf5","outputHash":"0e5fd7d50b291744bda606fd9d1c192cc361736a1b5017efe1975cf113612710","mapHash":"2fe8cc50b8c2721a758b1519180384004f7472f0730b9ab3853c97dd244a5318"}}
@@ -0,0 +1,24 @@
1
+ import * as pgBoss from "pg-boss";
2
+ import {
3
+ normalize as __normalize,
4
+ boundary as __boundary,
5
+ requireArity as __requireArity,
6
+ } from "./.lango/runtime.mjs";
7
+
8
+ export function apply(db, input) {
9
+ __requireArity(arguments.length, [0, 1], "apply");
10
+ db = __boundary(db);
11
+ input = __boundary(input);
12
+ let boss = new pgBoss.PgBoss({ db: db, schema: __normalize(input.schema), migrate: false, supervise: false, schedule: false, registerInstance: false });
13
+ if (__normalize(input.action) === "get") {
14
+ return __normalize(boss.getSchedule(__normalize(input.queue), __normalize(input.key)));
15
+ } else if (__normalize(input.action) === "remove") {
16
+ return __normalize(boss.unschedule(__normalize(input.queue), __normalize(input.key)));
17
+ } else if (__normalize(input.action) === "upsert") {
18
+ return __normalize(boss.schedule(__normalize(input.queue), __normalize(input.cron), __normalize(input.payload), __normalize(input.options)));
19
+ } else {
20
+ throw "Unknown schedule operation";
21
+ }
22
+ return null;
23
+ }
24
+ //# sourceMappingURL=schedule_transaction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule_transaction.mjs","sources":["schedule_transaction.lango"],"sourcesContent":["import js \"pg-boss\" as pgBoss\n\nexport apply(db, input)\n\napply(db, input)\n boss = new pgBoss/PgBoss({\n db: db\n schema: input.schema\n migrate: false\n supervise: false\n schedule: false\n registerInstance: false\n })\n switch input.action\n case \"get\"\n return boss.getSchedule(input.queue, input.key)\n case \"remove\"\n return boss.unschedule(input.queue, input.key)\n case \"upsert\"\n return boss.schedule(input.queue, input.cron, input.payload, input.options)\n else\n throw \"Unknown schedule operation\"\n"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"429a061357c7ecb799f74527063b750cfc1dc5cfbdf9306f8208eec24542bbeb","outputHash":"04bb0743d4699ee4d3a8c7f6a828ffd6927c672948ee86d0255dd59ef34dac47","mapHash":"005297ed7e5aca3328a89f5f936475d905f407ca20952ddbb68aab68c6dd658f"}}
@@ -0,0 +1,201 @@
1
+ import { attributes, empty, integer, boolean, name } from "./validation.mjs";
2
+ import * as cron from "cron-parser";
3
+ import {
4
+ hostGlobal as __hostGlobal,
5
+ xml2obj as __xml2obj,
6
+ fromJson as __fromJson,
7
+ toJson as __toJson,
8
+ isNumber as __isNumber,
9
+ isString as __isString,
10
+ isBool as __isBool,
11
+ isObject as __isObject,
12
+ isArray as __isArray,
13
+ requireBoolean as __requireBoolean,
14
+ normalize as __normalize,
15
+ boundary as __boundary,
16
+ requireArity as __requireArity,
17
+ } from "./.lango/runtime.mjs";
18
+
19
+ function defaults() {
20
+ return { retryLimit: 3, retryDelay: 10, retryBackoff: true, retryDelayMax: 300, expireInSeconds: 900, failedRetentionSeconds: 604800 };
21
+ return null;
22
+ }
23
+
24
+ function retryFields() {
25
+ return ["retryLimit", "retryDelay", "retryBackoff", "retryDelayMax", "expireInSeconds", "failedRetentionSeconds"];
26
+ return null;
27
+ }
28
+
29
+ function retryOptions(spec, base) {
30
+ __requireArity(arguments.length, [0, 1], "retryOptions");
31
+ spec = __boundary(spec);
32
+ base = __boundary(base);
33
+ let result = { retryLimit: integer(__normalize(spec.retryLimit), __normalize(base.retryLimit), 0, 2147483647, "retryLimit"), retryDelay: integer(__normalize(spec.retryDelay), __normalize(base.retryDelay), 1, 2147483647, "retryDelay"), retryBackoff: boolean(__normalize(spec.retryBackoff), __normalize(base.retryBackoff), "retryBackoff"), retryDelayMax: integer(__normalize(spec.retryDelayMax), __normalize(base.retryDelayMax), 1, 2147483647, "retryDelayMax"), expireInSeconds: integer(__normalize(spec.expireInSeconds), __normalize(base.expireInSeconds), 1, 1209600, "expireInSeconds"), failedRetentionSeconds: integer(__normalize(spec.failedRetentionSeconds), __normalize(base.failedRetentionSeconds), 1, 2147483647, "failedRetentionSeconds") };
34
+ if (__requireBoolean(__normalize(result.retryDelay) > __normalize(result.retryDelayMax))) {
35
+ throw "retryDelay cannot exceed retryDelayMax";
36
+ }
37
+ return result;
38
+ return null;
39
+ }
40
+
41
+ function timeZone(value) {
42
+ __requireArity(arguments.length, [0], "timeZone");
43
+ value = __boundary(value);
44
+ let formatter;
45
+ if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(__normalize(value.trim()) !== value)) || __requireBoolean(value === ""))) {
46
+ throw "A valid time zone is required";
47
+ }
48
+ try {
49
+ formatter = new (__hostGlobal(["Intl"]).DateTimeFormat)("en", { timeZone: value });
50
+ } catch (error) {
51
+ throw `Invalid time zone: ${value}`;
52
+ }
53
+ return value;
54
+ return null;
55
+ }
56
+
57
+ function data(tag) {
58
+ __requireArity(arguments.length, [0], "data");
59
+ tag = __boundary(tag);
60
+ let children = __normalize(tag.children());
61
+ if (__requireBoolean(__normalize(children.length) === 0)) {
62
+ return { };
63
+ }
64
+ if (__requireBoolean(__requireBoolean(__normalize(children.length) !== 1) || __requireBoolean(__normalize(__normalize(children[0]).tag()) !== "data"))) {
65
+ throw "Job may contain only one data element";
66
+ }
67
+ let child = __normalize(children[0]);
68
+ attributes(child, []);
69
+ if (__requireBoolean(__normalize(__normalize(child.children()).length) !== 0)) {
70
+ throw "Job data must contain JSON text";
71
+ }
72
+ let value = null;
73
+ try {
74
+ value = __fromJson(__normalize(child.innerText()));
75
+ } catch (error) {
76
+ throw "Job data must be valid JSON";
77
+ }
78
+ if (__requireBoolean(__requireBoolean(__requireBoolean(value === null) || __requireBoolean(!__requireBoolean(__isObject(value)))) || __requireBoolean(__isArray(value)))) {
79
+ throw "Job data must be a JSON map";
80
+ }
81
+ return value;
82
+ return null;
83
+ }
84
+
85
+ function targetFor(path, targets) {
86
+ __requireArity(arguments.length, [0, 1], "targetFor");
87
+ path = __boundary(path);
88
+ targets = __boundary(targets);
89
+ for (const target of targets) {
90
+ if (__requireBoolean(__normalize(target.path) === path)) {
91
+ return target;
92
+ }
93
+ }
94
+ throw `Unknown job path: ${path}`;
95
+ return null;
96
+ }
97
+
98
+ export function parseSchedules(xml, targets) {
99
+ __requireArity(arguments.length, [0, 1], "parseSchedules");
100
+ xml = __boundary(xml);
101
+ targets = __boundary(targets);
102
+ let parsed = scheduleConfiguration(xml, targets);
103
+ return __normalize(parsed.items);
104
+ return null;
105
+ }
106
+
107
+ export function scheduleConfiguration(xml, targets) {
108
+ __requireArity(arguments.length, [0, 1], "scheduleConfiguration");
109
+ xml = __boundary(xml);
110
+ targets = __boundary(targets);
111
+ let root = __xml2obj(xml);
112
+ if (__requireBoolean(__normalize(root.tag()) !== "jobs")) {
113
+ throw "Expected jobs root";
114
+ }
115
+ attributes(root, ["timeZone", "identity", "revision"]);
116
+ if (__requireBoolean(__normalize(root.revision) === null)) {
117
+ throw "Jobs revision is required";
118
+ }
119
+ let revision = integer(__normalize(root.revision), null, 1, 2147483647, "revision");
120
+ if (__requireBoolean(__normalize(__normalize(root.innerText()).trim()) !== "")) {
121
+ throw "Jobs XML cannot contain text outside data elements";
122
+ }
123
+ let zone = __normalize(root.timeZone);
124
+ if (__requireBoolean(zone === null)) {
125
+ zone = "UTC";
126
+ }
127
+ timeZone(zone);
128
+ let profile = name(__normalize(root.identity), "Jobs identity");
129
+ let base = defaults();
130
+ let seenDefaults = false;
131
+ for (const tag of __normalize(root.children())) {
132
+ if (__requireBoolean(__normalize(tag.tag()) === "defaults")) {
133
+ if (__requireBoolean(seenDefaults)) {
134
+ throw "Duplicate jobs defaults";
135
+ }
136
+ seenDefaults = true;
137
+ attributes(tag, retryFields());
138
+ empty(tag);
139
+ base = retryOptions(__normalize(tag.attributes()), base);
140
+ } else {
141
+ if (__requireBoolean(__normalize(tag.tag()) !== "job")) {
142
+ throw `Unknown jobs element: ${__normalize(tag.tag())}`;
143
+ }
144
+ }
145
+ }
146
+ let seen = __normalize(__hostGlobal(["Object"]).create(null));
147
+ let items = [];
148
+ for (const tag of __normalize(root.children())) {
149
+ if (__requireBoolean(__normalize(tag.tag()) === "defaults")) {
150
+ continue;
151
+ }
152
+ let allowed = ["name", "path", "cron", "timeZone", "missed", "precision", "enabled"];
153
+ for (const field of retryFields()) {
154
+ allowed.push(field);
155
+ }
156
+ attributes(tag, allowed);
157
+ if (__requireBoolean(__normalize(__normalize(tag.innerText()).trim()) !== "")) {
158
+ throw "Job XML cannot contain text outside data";
159
+ }
160
+ let spec = __normalize(tag.attributes());
161
+ let id = name(__normalize(spec.name), "Job name");
162
+ if (__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(seen, id)))) {
163
+ throw `Duplicate job name: ${id}`;
164
+ }
165
+ seen[id] = true;
166
+ let target = targetFor(__normalize(spec.path), targets);
167
+ let selectedZone = zone;
168
+ if (__requireBoolean(__normalize(spec.timeZone) !== null)) {
169
+ selectedZone = timeZone(__normalize(spec.timeZone));
170
+ }
171
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.cron)))) || __requireBoolean(__normalize(spec.cron.trim()) === ""))) {
172
+ throw `Job cron expression is required: ${id}`;
173
+ }
174
+ try {
175
+ __normalize(cron.CronExpressionParser.parse(__normalize(spec.cron), { tz: selectedZone }));
176
+ } catch (error) {
177
+ throw `Invalid job cron expression: ${id}`;
178
+ }
179
+ let missed = __normalize(spec.missed);
180
+ if (__requireBoolean(missed === null)) {
181
+ missed = "skip";
182
+ }
183
+ let missedValues = ["skip", "once"];
184
+ if (__requireBoolean(!__requireBoolean(__normalize(missedValues.includes(missed))))) {
185
+ throw "Job missed must be skip or once";
186
+ }
187
+ let precision = __normalize(spec.precision);
188
+ if (__requireBoolean(precision === null)) {
189
+ precision = "minute";
190
+ }
191
+ let precisions = ["minute", "second"];
192
+ if (__requireBoolean(!__requireBoolean(__normalize(precisions.includes(precision))))) {
193
+ throw "Job precision must be minute or second";
194
+ }
195
+ let retry = retryOptions(spec, base);
196
+ items.push({ name: id, path: __normalize(target.path), queue: __normalize(target.queue), identity: profile, cron: __normalize(spec.cron), timeZone: selectedZone, missed: missed, precision: precision, enabled: boolean(__normalize(spec.enabled), true, "enabled"), data: data(tag), retry: retry });
197
+ }
198
+ return { revision: revision, items: items };
199
+ return null;
200
+ }
201
+ //# sourceMappingURL=schedules.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedules.mjs","sources":["schedules.lango"],"sourcesContent":["import \"./validation\"\n attributes(tag, allowed)\n empty(tag)\n integer(value, fallback, minimum, maximum, name)\n boolean(value, fallback, name)\n name(value, label)\nimport js \"cron-parser\" as cron\nimport js global Intl\nimport js global Object\n\nexport parseSchedules(xml, targets)\nexport scheduleConfiguration(xml, targets)\n\ndefaults()\n return {\n retryLimit: 3\n retryDelay: 10\n retryBackoff: true\n retryDelayMax: 300\n expireInSeconds: 900\n failedRetentionSeconds: 604800\n }\n\nretryFields()\n return [\"retryLimit\", \"retryDelay\", \"retryBackoff\", \"retryDelayMax\", \"expireInSeconds\", \"failedRetentionSeconds\"]\n\nretryOptions(spec, base)\n result = {\n retryLimit: integer(spec.retryLimit, base.retryLimit, 0, 2147483647, \"retryLimit\")\n retryDelay: integer(spec.retryDelay, base.retryDelay, 1, 2147483647, \"retryDelay\")\n retryBackoff: boolean(spec.retryBackoff, base.retryBackoff, \"retryBackoff\")\n retryDelayMax: integer(spec.retryDelayMax, base.retryDelayMax, 1, 2147483647, \"retryDelayMax\")\n expireInSeconds: integer(spec.expireInSeconds, base.expireInSeconds, 1, 1209600, \"expireInSeconds\")\n failedRetentionSeconds: integer(spec.failedRetentionSeconds, base.failedRetentionSeconds, 1, 2147483647, \"failedRetentionSeconds\")\n }\n if result.retryDelay > result.retryDelayMax\n throw \"retryDelay cannot exceed retryDelayMax\"\n return result\n\ntimeZone(value)\n if !is_string(value) or value.trim() != value or value == \"\"\n throw \"A valid time zone is required\"\n try\n formatter = new Intl/DateTimeFormat(\"en\", {\n timeZone: value\n })\n catch error\n throw \"Invalid time zone: ${value}\"\n return value\n\ndata(tag)\n children = tag.children()\n if children.length == 0\n return {}\n if children.length != 1 or children[0].tag() != \"data\"\n throw \"Job may contain only one data element\"\n child = children[0]\n attributes(child, [])\n if child.children().length != 0\n throw \"Job data must contain JSON text\"\n value = null\n try\n value = from_json(child.innerText())\n catch error\n throw \"Job data must be valid JSON\"\n if value == null or !is_object(value) or is_array(value)\n throw \"Job data must be a JSON map\"\n return value\n\ntargetFor(path, targets)\n for targets as target\n if target.path == path\n return target\n throw \"Unknown job path: ${path}\"\n\nparseSchedules(xml, targets)\n parsed = scheduleConfiguration(xml, targets)\n return parsed.items\n\nscheduleConfiguration(xml, targets)\n root = xml2obj(xml)\n if root.tag() != \"jobs\"\n throw \"Expected jobs root\"\n attributes(root, [\"timeZone\", \"identity\", \"revision\"])\n if root.revision == null\n throw \"Jobs revision is required\"\n revision = integer(root.revision, null, 1, 2147483647, \"revision\")\n if root.innerText().trim() != \"\"\n throw \"Jobs XML cannot contain text outside data elements\"\n zone = root.timeZone\n if zone == null\n zone = \"UTC\"\n timeZone(zone)\n profile = name(root.identity, \"Jobs identity\")\n base = defaults()\n seenDefaults = false\n for root.children() as tag\n if tag.tag() == \"defaults\"\n if seenDefaults\n throw \"Duplicate jobs defaults\"\n seenDefaults = true\n attributes(tag, retryFields())\n empty(tag)\n base = retryOptions(tag.attributes(), base)\n else\n if tag.tag() != \"job\"\n throw \"Unknown jobs element: ${tag.tag()}\"\n seen = Object/create(null)\n items = []\n for root.children() as tag\n if tag.tag() == \"defaults\"\n continue\n allowed = [\"name\", \"path\", \"cron\", \"timeZone\", \"missed\", \"precision\", \"enabled\"]\n for retryFields() as field\n allowed.add(field)\n attributes(tag, allowed)\n if tag.innerText().trim() != \"\"\n throw \"Job XML cannot contain text outside data\"\n spec = tag.attributes()\n id = name(spec.name, \"Job name\")\n if Object/hasOwn(seen, id)\n throw \"Duplicate job name: ${id}\"\n seen[id] = true\n target = targetFor(spec.path, targets)\n selectedZone = zone\n if spec.timeZone != null\n selectedZone = timeZone(spec.timeZone)\n if !is_string(spec.cron) or spec.cron.trim() == \"\"\n throw \"Job cron expression is required: ${id}\"\n try\n cron/CronExpressionParser/parse(spec.cron, {\n tz: selectedZone\n })\n catch error\n throw \"Invalid job cron expression: ${id}\"\n missed = spec.missed\n if missed == null\n missed = \"skip\"\n missedValues = [\"skip\", \"once\"]\n if !missedValues.includes(missed)\n throw \"Job missed must be skip or once\"\n precision = spec.precision\n if precision == null\n precision = \"minute\"\n precisions = [\"minute\", \"second\"]\n if !precisions.includes(precision)\n throw \"Job precision must be minute or second\"\n retry = retryOptions(spec, base)\n items.add({\n name: id\n path: target.path\n queue: target.queue\n identity: profile\n cron: spec.cron\n timeZone: selectedZone\n missed: missed\n precision: precision\n enabled: boolean(spec.enabled, true, \"enabled\")\n data: data(tag)\n retry: retry\n })\n return {\n revision: revision\n items: items\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAaA;;;;;AAUA;;;;;AAGA;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA;;;;;;;;;;;;;AAMA;;;;;;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","x_lango_build":{"fingerprint":"ebf3ab8c0f10e2abcf57cd27e76c976ad4f9fa29871a088180678e97a0ed40b0","outputHash":"641f6b530b9b008ef49911e54a2b3912c03e5fc6d0e0b6217deca3075cc00226","mapHash":"d466f4a0dd580d54b9ac256a7b23809de4aa99df1a9ba7cefe8e0a7273999283"}}
@@ -0,0 +1,16 @@
1
+ import * as pgBoss from "pg-boss";
2
+ import {
3
+ normalize as __normalize,
4
+ boundary as __boundary,
5
+ requireArity as __requireArity,
6
+ } from "./.lango/runtime.mjs";
7
+
8
+ export function send(db, input) {
9
+ __requireArity(arguments.length, [0, 1], "send");
10
+ db = __boundary(db);
11
+ input = __boundary(input);
12
+ let boss = new pgBoss.PgBoss({ db: db, schema: __normalize(input.schema), migrate: false, supervise: false, schedule: false, registerInstance: false });
13
+ return __normalize(boss.send(__normalize(input.queue), __normalize(input.payload), { db: db, retryLimit: 3, retryDelay: 10, retryBackoff: true, retryDelayMax: 300, expireInSeconds: 900, heartbeatSeconds: 30, deleteAfterSeconds: 0 }));
14
+ return null;
15
+ }
16
+ //# sourceMappingURL=transaction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.mjs","sources":["transaction.lango"],"sourcesContent":["import js \"pg-boss\" as pgBoss\n\nexport send(db, input)\n\nsend(db, input)\n boss = new pgBoss/PgBoss({\n db: db\n schema: input.schema\n migrate: false\n supervise: false\n schedule: false\n registerInstance: false\n })\n return boss.send(input.queue, input.payload, {\n db: db\n retryLimit: 3\n retryDelay: 10\n retryBackoff: true\n retryDelayMax: 300\n expireInSeconds: 900\n heartbeatSeconds: 30\n deleteAfterSeconds: 0\n })\n"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;;","x_lango_build":{"fingerprint":"3bac0d1c412db85d9aed379ee511bdea1a1487f12fc29254f5b6928915361478","outputHash":"27a42954414b9900da01f3c4be11db80f1b0bdd73d30e1282ef66ee6fdf6e8ed","mapHash":"87eef50ba0af79edefb98f112839da4737decead8400d98a3dbcbef1e6b87777"}}