@isplay/worker 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 isplay contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @isplay/worker
2
+
3
+ Graphile Worker task list and local worker entrypoint for isplay.
4
+
5
+ It runs queued replay and experiment jobs against the local Postgres store.
@@ -0,0 +1,10 @@
1
+ import { type Runner, type TaskList } from "graphile-worker";
2
+ export type StartWorkerOptions = {
3
+ connectionString: string;
4
+ artifactsDir?: string;
5
+ concurrency?: number;
6
+ };
7
+ export declare function createTaskList(options: StartWorkerOptions): TaskList;
8
+ export declare const taskList: TaskList;
9
+ export declare function startWorker(options: StartWorkerOptions): Promise<Runner>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIlE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,QAAQ,CA0CpE;AAED,eAAO,MAAM,QAAQ,EAAE,QAGrB,CAAC;AAoCH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAM9E"}
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ import { run } from "graphile-worker";
2
+ import { IsplayStore } from "@isplay/postgres";
3
+ import { executeReplay, runExperiment } from "@isplay/server";
4
+ export function createTaskList(options) {
5
+ return {
6
+ "replay.run": async (payload, helpers) => {
7
+ const { jobId, replayId } = replayPayload(payload);
8
+ await withStore(options, async (store) => {
9
+ await store.updateDurableJob(jobId, { status: "running" });
10
+ await store.appendDurableJobEvent(jobId, "job.started", { replayId });
11
+ try {
12
+ const replay = await store.getReplay(replayId);
13
+ if (!replay)
14
+ throw new Error(`Replay not found: ${replayId}`);
15
+ const result = await executeReplay(store, replay);
16
+ const status = result.status === "error" ? "error" : "ok";
17
+ await store.updateDurableJob(jobId, { status, error: result.error });
18
+ await store.appendDurableJobEvent(jobId, status === "ok" ? "job.finished" : "job.failed", { replayId: result.id, replayStatus: result.status });
19
+ }
20
+ catch (error) {
21
+ const message = error instanceof Error ? error.message : String(error);
22
+ await store.updateDurableJob(jobId, { status: "error", error: message });
23
+ await store.appendDurableJobEvent(jobId, "job.failed", { replayId, error: message }, { retryable: false });
24
+ }
25
+ });
26
+ helpers.logger.info("Replay job finished", { jobId, replayId });
27
+ },
28
+ "experiment.run": async (payload, helpers) => {
29
+ const { jobId, experimentId } = experimentPayload(payload);
30
+ await withStore(options, async (store) => {
31
+ await store.updateDurableJob(jobId, { status: "running" });
32
+ await store.appendDurableJobEvent(jobId, "job.started", { experimentId });
33
+ try {
34
+ const result = await runExperiment(store, experimentId);
35
+ const status = result.status === "invalid" ? "error" : "ok";
36
+ await store.updateDurableJob(jobId, { status, error: status === "error" ? "Experiment completed invalid" : undefined });
37
+ await store.appendDurableJobEvent(jobId, status === "ok" ? "job.finished" : "job.failed", { experimentId, experimentStatus: result.status });
38
+ }
39
+ catch (error) {
40
+ const message = error instanceof Error ? error.message : String(error);
41
+ await store.updateDurableJob(jobId, { status: "error", error: message });
42
+ await store.appendDurableJobEvent(jobId, "job.failed", { experimentId, error: message }, { retryable: false });
43
+ }
44
+ });
45
+ helpers.logger.info("Experiment job finished", { jobId, experimentId });
46
+ }
47
+ };
48
+ }
49
+ export const taskList = createTaskList({
50
+ connectionString: process.env.DATABASE_URL ?? "",
51
+ artifactsDir: process.env.ISPLAY_ARTIFACTS_DIR
52
+ });
53
+ async function withStore(options, fn) {
54
+ const store = new IsplayStore({
55
+ connectionString: options.connectionString,
56
+ artifactsDir: options.artifactsDir ?? process.env.ISPLAY_ARTIFACTS_DIR ?? ".isplay/artifacts"
57
+ });
58
+ await store.migrate();
59
+ try {
60
+ return await fn(store);
61
+ }
62
+ finally {
63
+ await store.close();
64
+ }
65
+ }
66
+ function replayPayload(payload) {
67
+ const record = objectPayload(payload);
68
+ return { jobId: stringPayload(record, "jobId"), replayId: stringPayload(record, "replayId") };
69
+ }
70
+ function experimentPayload(payload) {
71
+ const record = objectPayload(payload);
72
+ return { jobId: stringPayload(record, "jobId"), experimentId: stringPayload(record, "experimentId") };
73
+ }
74
+ function objectPayload(payload) {
75
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
76
+ throw new Error("Expected object job payload.");
77
+ return payload;
78
+ }
79
+ function stringPayload(payload, key) {
80
+ const value = payload[key];
81
+ if (typeof value !== "string")
82
+ throw new Error(`Expected ${key} in job payload.`);
83
+ return value;
84
+ }
85
+ ;
86
+ export async function startWorker(options) {
87
+ return run({
88
+ connectionString: options.connectionString,
89
+ concurrency: options.concurrency ?? 2,
90
+ taskList: createTaskList(options)
91
+ });
92
+ }
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAA8B,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQ9D,MAAM,UAAU,cAAc,CAAC,OAA2B;IACxD,OAAO;QACL,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;YACvC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;YACnD,MAAM,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;gBACvC,MAAM,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;gBAC3D,MAAM,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACtE,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;oBAC/C,IAAI,CAAC,MAAM;wBAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;oBAC9D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;oBAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,OAAO,C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AI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACvH,OAAO,OAAkC,CAAC;AAC5C,CAAC;AAED,SAAS,aAAa,CAAC,OAAgC,EAAE,GAAW;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,YAAY,GAAG,kBAAkB,CAAC,CAAC;IAClF,OAAO,KAAK,CAAC;AACf,CAAC;AAAA,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAA2B;IAC3D,OAAO,GAAG,CAAC;QACT,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC;QACrC,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC;KAClC,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@isplay/worker",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "@isplay/core": "0.3.0",
15
+ "@isplay/postgres": "0.3.0",
16
+ "@isplay/server": "0.3.0",
17
+ "graphile-worker": "^0.16.6"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/isplay/isplay.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/isplay/isplay/issues"
25
+ },
26
+ "homepage": "https://isplay.dev",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "sideEffects": false,
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "description": "Graphile Worker task handlers for durable isplay replay and experiment jobs.",
37
+ "license": "MIT",
38
+ "engines": {
39
+ "node": ">=22.5.0"
40
+ }
41
+ }