@rip-lang/swarm 1.2.8 → 1.2.10
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/README.md +5 -1
- package/lib/worker.mjs +0 -1
- package/package.json +2 -2
- package/swarm.rip +3 -22
package/README.md
CHANGED
|
@@ -83,7 +83,11 @@ rip jobs.rip -w 40 # 40 workers for I/O-heavy jobs
|
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
1. **`setup()`** runs once in the main thread — creates task files and
|
|
86
|
-
returns an optional context object (auth tokens, config, paths)
|
|
86
|
+
returns an optional context object (auth tokens, config, paths).
|
|
87
|
+
**Important:** the context must be plain data (strings, numbers,
|
|
88
|
+
booleans, arrays, plain objects). Class instances, functions, HTTP
|
|
89
|
+
clients, sockets, and other complex objects cannot be cloned for
|
|
90
|
+
worker threads — use `fetch` inside `perform()` instead
|
|
87
91
|
2. **N worker threads** are spawned — each loads your script and gets
|
|
88
92
|
the `perform` function. Workers are long-lived and process many tasks
|
|
89
93
|
3. Tasks are dispatched from `.swarm/todo/` to workers via message passing
|
package/lib/worker.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rip-lang/swarm",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "Parallel job runner with worker threads — setup once, swarm many",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "swarm.rip",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"author": "Steve Shreeve <steve.shreeve@gmail.com>",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"rip-lang": "^3.13.
|
|
38
|
+
"rip-lang": "^3.13.4"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"swarm.rip",
|
package/swarm.rip
CHANGED
|
@@ -202,17 +202,8 @@ export swarm = (opts = {}) ->
|
|
|
202
202
|
workerPath = join(dirname(new URL(import.meta.url).pathname), 'lib', 'worker.mjs')
|
|
203
203
|
scriptPath = resolve(process.argv[1] or '')
|
|
204
204
|
|
|
205
|
-
# find rip-loader for workers (
|
|
206
|
-
loaderPath =
|
|
207
|
-
try
|
|
208
|
-
loaderPath = join(dirname(require.resolve('rip-lang')), '..', 'rip-loader.js')
|
|
209
|
-
catch
|
|
210
|
-
# fall back to global install
|
|
211
|
-
try
|
|
212
|
-
globalDir = join(process.env.HOME or '', '.bun', 'install', 'global', 'node_modules', 'rip-lang')
|
|
213
|
-
loaderPath = join(globalDir, 'rip-loader.js') if existsSync(join(globalDir, 'rip-loader.js'))
|
|
214
|
-
catch
|
|
215
|
-
null
|
|
205
|
+
# find rip-loader for workers (NODE_PATH ensures require.resolve works)
|
|
206
|
+
loaderPath = try join(dirname(require.resolve('rip-lang')), '..', 'rip-loader.js')
|
|
216
207
|
|
|
217
208
|
# state
|
|
218
209
|
live = 0
|
|
@@ -284,8 +275,7 @@ export swarm = (opts = {}) ->
|
|
|
284
275
|
cursor(true) unless quiet
|
|
285
276
|
write go(workers + 5, 1) unless quiet
|
|
286
277
|
console.error "\nswarm: #{msg.error}"
|
|
287
|
-
|
|
288
|
-
exit 1
|
|
278
|
+
exit(1)
|
|
289
279
|
when 'ready'
|
|
290
280
|
dispatchNext(w, slot)
|
|
291
281
|
when 'done'
|
|
@@ -313,15 +303,6 @@ export swarm = (opts = {}) ->
|
|
|
313
303
|
|
|
314
304
|
w.on 'exit', (code) ->
|
|
315
305
|
writeFileSync('.swarm/errors.log', "worker #{slot} exited with code #{code}, inflight: #{inflight[slot]}\n", { flag: 'a' }) if existsSync(_dir)
|
|
316
|
-
# startup failure — worker never became ready
|
|
317
|
-
if code isnt 0 and not info[slot]? and not fatal
|
|
318
|
-
fatal = true
|
|
319
|
-
cursor(true) unless quiet
|
|
320
|
-
write go(workers + 5, 1) unless quiet
|
|
321
|
-
console.error "\nswarm: worker #{slot} failed to start (exit code #{code})"
|
|
322
|
-
console.error "hint: run 'bun add @rip-lang/all' in your project directory"
|
|
323
|
-
console.error " check .swarm/errors.log for details"
|
|
324
|
-
exit 1
|
|
325
306
|
# if worker crashed mid-task, count the in-flight task as died
|
|
326
307
|
if inflight[slot]
|
|
327
308
|
move(inflight[slot], _died)
|