@naanlang/naan 1.3.2 → 1.4.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.md +1 -1
- package/README.md +1 -1
- package/bin/index.js +2 -2
- package/dist/naan.min.js +4 -4
- package/frameworks/browser/sworker.js +23 -23
- package/frameworks/browser/terminals.nlg +25 -10
- package/frameworks/browser/ws_client.nlg +1 -1
- package/frameworks/client/psm_client.nlg +1 -1
- package/frameworks/client/relaycon.nlg +2 -1
- package/frameworks/common/preferences.nlg +1 -1
- package/frameworks/node/apiserver.nlg +3 -3
- package/frameworks/node/worker.nlg +103 -45
- package/frameworks/project/build.nlg +0 -1
- package/frameworks/project/jszip.js +0 -0
- package/frameworks/project/projects.nlg +1 -1
- package/frameworks/running/executors.nlg +64 -28
- package/frameworks/running/running.nlg +85 -3
- package/frameworks/running/taskexec.nlg +24 -4
- package/frameworks/storage/dbt_pouch.nlg +1 -1
- package/frameworks/storage/psm.nlg +11 -1
- package/lib/browser/env_web.js +6 -6
- package/lib/browser/env_webworker.js +2 -0
- package/lib/core/naanlib.js +4 -4
- package/lib/env_nodeworker.js +2 -0
- package/package.json +1 -1
- package/plugins/gitClient/gitutils.nlg +2 -2
- package/plugins/nodeLib/node_https.nlg +2 -2
- package/plugins/serviceAws/lambda_naan_control.nlg +3 -3
- package/plugins/serviceGC/gc_api.nlg +1 -1
- package/plugins/serviceGitHub/gitops.nlg +4 -3
- package/plugins/serviceGitHub/psm_github.nlg +1 -1
- package/plugins/serviceGitLab/gitops.nlg +2 -1
- package/plugins/serviceGitLab/psm_gitlab.nlg +1 -1
- package/plugins/serviceYC/yc_vm.nlg +1 -1
- package/test/test_02_context.nlg +1 -1
- package/test/test_07_lingo.nlg +3 -3
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
var CurrentCacheName = "Naanlang-1.
|
|
39
|
+
var CurrentCacheName = "Naanlang-1.4.0+1";
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
//
|
|
@@ -92,18 +92,18 @@ var terminated; // flag that this service worker
|
|
|
92
92
|
var pubVersion = event.data.hereIsMyVersion;
|
|
93
93
|
var sourceId = event.source.id; // client id of sender of message
|
|
94
94
|
msgPorts[sourceId] = msgport;
|
|
95
|
-
console.log("[1.
|
|
96
|
-
if (pubVersion != "1.
|
|
95
|
+
console.log("[1.4.0+1] received new msgport for", sourceId, pubID, "-", pubVersion);
|
|
96
|
+
if (pubVersion != "1.4.0+1") {
|
|
97
97
|
if (upgradeMsgPorts) { // if not activated
|
|
98
|
-
console.log("[1.
|
|
98
|
+
console.log("[1.4.0+1] update pending for", sourceId);
|
|
99
99
|
upgradeMsgPorts[sourceId] = msgport;
|
|
100
100
|
}
|
|
101
101
|
else {
|
|
102
102
|
msgport.postMessage({ // notify new version available
|
|
103
103
|
id: "upgrade",
|
|
104
|
-
version: "1.
|
|
104
|
+
version: "1.4.0+1"
|
|
105
105
|
});
|
|
106
|
-
console.log("[1.
|
|
106
|
+
console.log("[1.4.0+1] update sent for:", sourceId);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
Reaper(); // clean up obsolete info
|
|
@@ -134,10 +134,10 @@ var terminated; // flag that this service worker
|
|
|
134
134
|
msgport.onmessage = function(msg) {
|
|
135
135
|
msg = msg.data;
|
|
136
136
|
if (msg.id == "skipWaiting") { // try to activate this SW now
|
|
137
|
-
console.log("[1.
|
|
137
|
+
console.log("[1.4.0+1] attempting skipWaiting");
|
|
138
138
|
self.skipWaiting();
|
|
139
139
|
} else if (msg.id == "terminate") { // termiante this SW now
|
|
140
|
-
console.log("[1.
|
|
140
|
+
console.log("[1.4.0+1] terminated");
|
|
141
141
|
terminate();
|
|
142
142
|
} else if (msg.id == "abortURL") { // abort an I/O transaction
|
|
143
143
|
var href = new URL(msg.url).href;
|
|
@@ -150,7 +150,7 @@ var terminated; // flag that this service worker
|
|
|
150
150
|
} else if (msg.id == "response") // response from fetch request
|
|
151
151
|
processResponse(msg);
|
|
152
152
|
else if (msg.id == "text") // just log some text
|
|
153
|
-
console.log("[1.
|
|
153
|
+
console.log("[1.4.0+1] msg received:", msg.text);
|
|
154
154
|
};
|
|
155
155
|
|
|
156
156
|
// send text to IDE log
|
|
@@ -161,7 +161,7 @@ var terminated; // flag that this service worker
|
|
|
161
161
|
// don't clutter the log
|
|
162
162
|
msgport.postMessage({
|
|
163
163
|
id: "text",
|
|
164
|
-
text: "port received by 1.
|
|
164
|
+
text: "port received by 1.4.0+1",
|
|
165
165
|
});
|
|
166
166
|
*/
|
|
167
167
|
if (--pending === 0)
|
|
@@ -178,7 +178,7 @@ var terminated; // flag that this service worker
|
|
|
178
178
|
includeUncontrolled: true
|
|
179
179
|
}).then(function(clientList) {
|
|
180
180
|
clientList.every(function(client) {
|
|
181
|
-
console.log("[1.
|
|
181
|
+
console.log("[1.4.0+1] requesting new msgport for", client.id);
|
|
182
182
|
++pending;
|
|
183
183
|
client.postMessage({ // tell client(s) we need this fetch source
|
|
184
184
|
msg: "Naan_need_fetch_port",
|
|
@@ -224,12 +224,12 @@ function Reaper() {
|
|
|
224
224
|
clients[clientList[clidex].id] = clientList[clidex];
|
|
225
225
|
for (var sourceId in msgPorts)
|
|
226
226
|
if (!clients[sourceId]) {
|
|
227
|
-
console.log("[1.
|
|
227
|
+
console.log("[1.4.0+1] source gone:", sourceId);
|
|
228
228
|
delete msgPorts[sourceId]; // no longer a source
|
|
229
229
|
}
|
|
230
230
|
for (var clientId in fetchPorts)
|
|
231
231
|
if (!clients[clientId]) {
|
|
232
|
-
console.log("[1.
|
|
232
|
+
console.log("[1.4.0+1] client gone:", clientId);
|
|
233
233
|
delete fetchPorts[clientId]; // no longer a client
|
|
234
234
|
}
|
|
235
235
|
for (var fqdex = 0; fqdex < fetchQueue.length; ++fqdex) {
|
|
@@ -263,16 +263,16 @@ function ClearCaches() {
|
|
|
263
263
|
return (Promise.all(
|
|
264
264
|
cacheNames.map(function(cacheName) {
|
|
265
265
|
if (cacheName != CurrentCacheName) {
|
|
266
|
-
console.log('[1.
|
|
266
|
+
console.log('[1.4.0+1] deleting old cache:', cacheName);
|
|
267
267
|
return (caches.delete(cacheName));
|
|
268
268
|
}
|
|
269
269
|
})
|
|
270
270
|
));
|
|
271
271
|
}).then(function() { // claim all clients
|
|
272
|
-
console.log('[1.
|
|
272
|
+
console.log('[1.4.0+1] claiming clients');
|
|
273
273
|
return (self.clients.claim());
|
|
274
274
|
}).then(function() {
|
|
275
|
-
console.log('[1.
|
|
275
|
+
console.log('[1.4.0+1] clients claimed');
|
|
276
276
|
return (Promise.resolve(true));
|
|
277
277
|
});
|
|
278
278
|
return (promise);
|
|
@@ -315,7 +315,7 @@ function GetClientResponse(event, urlpath) {
|
|
|
315
315
|
msgport.postMessage({
|
|
316
316
|
id: "fetch",
|
|
317
317
|
seq: seqno,
|
|
318
|
-
version: "1.
|
|
318
|
+
version: "1.4.0+1",
|
|
319
319
|
request: {
|
|
320
320
|
method: event.request.method,
|
|
321
321
|
url: event.request.url
|
|
@@ -363,7 +363,7 @@ function GetClientResponse(event, urlpath) {
|
|
|
363
363
|
*/
|
|
364
364
|
|
|
365
365
|
self.addEventListener('install', function(event) {
|
|
366
|
-
console.log("[1.
|
|
366
|
+
console.log("[1.4.0+1] install");
|
|
367
367
|
self.skipWaiting();
|
|
368
368
|
});
|
|
369
369
|
|
|
@@ -376,20 +376,20 @@ self.addEventListener('install', function(event) {
|
|
|
376
376
|
*/
|
|
377
377
|
|
|
378
378
|
self.addEventListener('activate', function(event) {
|
|
379
|
-
console.log("[1.
|
|
379
|
+
console.log("[1.4.0+1] activate");
|
|
380
380
|
self.clients.matchAll({ // for debugging, list controlled clients
|
|
381
381
|
includeUncontrolled: true
|
|
382
382
|
}).then(function(clientList) {
|
|
383
383
|
var urls = clientList.map(function(client) {
|
|
384
384
|
return (client.url);
|
|
385
385
|
});
|
|
386
|
-
console.log('[1.
|
|
386
|
+
console.log('[1.4.0+1] matching clients:', urls.join(', '));
|
|
387
387
|
});
|
|
388
388
|
var promise = ClearCaches().then(function() {
|
|
389
389
|
for (var sourceId in upgradeMsgPorts) {
|
|
390
390
|
upgradeMsgPorts[sourceId].postMessage({ // notify new version available
|
|
391
391
|
id: "upgrade",
|
|
392
|
-
version: "1.
|
|
392
|
+
version: "1.4.0+1"
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
395
|
upgradeMsgPorts = false;
|
|
@@ -421,7 +421,7 @@ self.addEventListener('fetch', function(event) {
|
|
|
421
421
|
var promise;
|
|
422
422
|
var url = new URL(request.url);
|
|
423
423
|
var nocache = request.method != "GET"
|
|
424
|
-
|| url.search.length !== 0 && url.searchParams.get("naanver") !== "
|
|
424
|
+
|| url.search.length !== 0 && url.searchParams.get("naanver") !== "fae76573fc7eeb3020b11e0d88fe69d4"
|
|
425
425
|
|| request.headers.get('range');
|
|
426
426
|
if (url.pathname.startsWith("/run/")) {
|
|
427
427
|
nocache = true;
|
|
@@ -455,7 +455,7 @@ self.addEventListener('fetch', function(event) {
|
|
|
455
455
|
statusText: "Request Cancelled"
|
|
456
456
|
}));
|
|
457
457
|
}
|
|
458
|
-
console.log("[1.
|
|
458
|
+
console.log("[1.4.0+1] fetch failed", request.url, e);
|
|
459
459
|
return (new Response(undefined, {
|
|
460
460
|
status: 404,
|
|
461
461
|
statusText: "Fetch Failed"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
gWorkers;
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/*
|
|
@@ -431,9 +431,9 @@ closure TermHost(track, api, name, options, local target, nlregex, xtarg)
|
|
|
431
431
|
|
|
432
432
|
closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
433
433
|
{
|
|
434
|
-
global(js, window,
|
|
435
|
-
if !dictionary(
|
|
436
|
-
|
|
434
|
+
global(js, window, gWorkers)
|
|
435
|
+
if !dictionary(gWorkers)
|
|
436
|
+
gWorkers = {}
|
|
437
437
|
options = merge({
|
|
438
438
|
type: "Local"
|
|
439
439
|
}, options)
|
|
@@ -456,14 +456,15 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
456
456
|
// ### tell target we are closing (if needed)
|
|
457
457
|
})
|
|
458
458
|
listener = window
|
|
459
|
+
target.guid = 1
|
|
459
460
|
} else {
|
|
460
461
|
if not window.Worker
|
|
461
462
|
return (list(Error("Local environment does not support workers")))
|
|
462
463
|
target.worker = xnew(window.Worker, "env_webworker.js")
|
|
463
464
|
listener = target.worker
|
|
464
465
|
target.guid = UUID()
|
|
465
|
-
workers[target.guid] = target
|
|
466
466
|
}
|
|
467
|
+
gWorkers[target.guid] = target
|
|
467
468
|
|
|
468
469
|
// onmessage
|
|
469
470
|
// A message was received from the worker.
|
|
@@ -551,6 +552,8 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
551
552
|
id: "start",
|
|
552
553
|
state: false // resume state, if we have any
|
|
553
554
|
altcmd: options.startup.initcmds
|
|
555
|
+
workerID: target.workerID
|
|
556
|
+
workerGUID: target.guid
|
|
554
557
|
})
|
|
555
558
|
target.started = true
|
|
556
559
|
} else if msg.id == "targetsend" {
|
|
@@ -667,10 +670,21 @@ closure TermLocal(track, name, options, local target, nlregex, listener)
|
|
|
667
670
|
};
|
|
668
671
|
|
|
669
672
|
|
|
673
|
+
/*
|
|
674
|
+
* WorkerConnect
|
|
675
|
+
*
|
|
676
|
+
* Return the existing web worker for a workerGUID, or false if it does not exist.
|
|
677
|
+
*
|
|
678
|
+
*/
|
|
679
|
+
|
|
680
|
+
function WorkerConnect(workerGUID) {
|
|
681
|
+
gWorkers[workerGUID]
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
|
|
670
685
|
/*
|
|
671
686
|
* termMainProxy
|
|
672
687
|
*
|
|
673
|
-
* column positioning: // // !
|
|
674
688
|
* Make a browser proxy representing the main thread. This runs inside the worker and allows it
|
|
675
689
|
* to do remote execution with Main.
|
|
676
690
|
*
|
|
@@ -769,7 +783,7 @@ closure findIDEtarget(track, name, workerID, naancont, local target) {
|
|
|
769
783
|
*/
|
|
770
784
|
|
|
771
785
|
closure termIDE(track, name, workerID, naancont, title, local target, connected) {
|
|
772
|
-
global(
|
|
786
|
+
global(js, gWorkers)
|
|
773
787
|
target = findIDEtarget(track, name, workerID, naancont)
|
|
774
788
|
if target { // new naancont on existing target
|
|
775
789
|
target.updateController(naancont)
|
|
@@ -790,7 +804,7 @@ closure termIDE(track, name, workerID, naancont, title, local target, connected)
|
|
|
790
804
|
//
|
|
791
805
|
function replyHook(data) {
|
|
792
806
|
if data._guid
|
|
793
|
-
|
|
807
|
+
gWorkers[data._guid].worker.postMessage({
|
|
794
808
|
id: "targetreceive"
|
|
795
809
|
data: data
|
|
796
810
|
})
|
|
@@ -969,14 +983,15 @@ closure termInstallVirtualWatcher(track, naancont) {
|
|
|
969
983
|
*/
|
|
970
984
|
|
|
971
985
|
function termInit(local manifest) {
|
|
972
|
-
manifest = `(TermHost, TermLocal, termMainProxy, WorkerToMain, findIDEtarget,
|
|
973
|
-
termInstallVirtualWatcher, termInit)
|
|
986
|
+
manifest = `(TermHost, TermLocal, WorkerConnect, termMainProxy, WorkerToMain, findIDEtarget,
|
|
987
|
+
termIDE, termInstallVirtualWatcher, termInit)
|
|
974
988
|
|
|
975
989
|
Naan.module.build(module.id, "terminals", function(modobj, compobj) {
|
|
976
990
|
require("./browser.nlg")
|
|
977
991
|
compobj.manifest = manifest
|
|
978
992
|
modobj.exports.TermLocal = TermLocal
|
|
979
993
|
modobj.exports.TermHost = TermHost
|
|
994
|
+
modobj.exports.WorkerConnect = WorkerConnect
|
|
980
995
|
modobj.exports.WorkerToMain = WorkerToMain
|
|
981
996
|
})
|
|
982
997
|
} ();
|
|
@@ -51,7 +51,7 @@ closure WebSocket(options, local wsock) {
|
|
|
51
51
|
|
|
52
52
|
// onopen
|
|
53
53
|
// The WebSocket connection is now open.
|
|
54
|
-
wsock.ws.onopen = closure onopen(e
|
|
54
|
+
wsock.ws.onopen = closure onopen(e) {
|
|
55
55
|
pending.signal(list(false, { ok: true }))
|
|
56
56
|
options.onopen(e)
|
|
57
57
|
}
|
|
@@ -430,7 +430,7 @@ closure psmcFsView(api, rootpath, local view, pathmod) {
|
|
|
430
430
|
*/
|
|
431
431
|
|
|
432
432
|
closure psmcFsConnector(psm, api, local connClassID, connector, watch) {
|
|
433
|
-
global()
|
|
433
|
+
global(App)
|
|
434
434
|
connClassID = "NodeFS"
|
|
435
435
|
connector = new(object, this)
|
|
436
436
|
connector.psm = psm
|
|
@@ -43,7 +43,7 @@ wsMod;; // websocket module
|
|
|
43
43
|
|
|
44
44
|
closure RelayCon(host, secret, options, local relay, nlregex)
|
|
45
45
|
{
|
|
46
|
-
global(execsMod, wsMod)
|
|
46
|
+
global(App, execsMod, wsMod)
|
|
47
47
|
relay = new(object, this)
|
|
48
48
|
options = merge({
|
|
49
49
|
name: "NaanIDE Server"
|
|
@@ -301,6 +301,7 @@ function hocoInit(local manifest) {
|
|
|
301
301
|
manifest = `(RelayCon, hocoInit)
|
|
302
302
|
|
|
303
303
|
Naan.module.build(module.id, "relaycon", function(modobj, compobj) {
|
|
304
|
+
require("./client.nlg")
|
|
304
305
|
execsMod = require("../running/executors.nlg")
|
|
305
306
|
if js.w
|
|
306
307
|
wsMod = require("../browser/ws_client.nlg")
|
|
@@ -88,7 +88,7 @@ closure Preferences(nicc, dbname, local prefs, error, data) {
|
|
|
88
88
|
folder = "plugins/"
|
|
89
89
|
path = folder.concat("plugins.cfg")
|
|
90
90
|
pending = new(nonce)
|
|
91
|
-
nicc.api.readFile(path, function(error, req, event
|
|
91
|
+
nicc.api.readFile(path, function(error, req, event) {
|
|
92
92
|
if error
|
|
93
93
|
ErrorDebuglog("Can't read ".concat(path), error)
|
|
94
94
|
else
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
closure APIServer(options, local server, chroot) {
|
|
33
|
-
global(JSpath, js, bodyParser, express, psmServerMod, workerMod)
|
|
33
|
+
global(App, JSpath, js, bodyParser, express, psmServerMod, workerMod)
|
|
34
34
|
apisLoadLibs()
|
|
35
35
|
server = new(object, this)
|
|
36
36
|
server.app = express()
|
|
@@ -116,7 +116,7 @@ closure APIServer(options, local server, chroot) {
|
|
|
116
116
|
return (list(error))
|
|
117
117
|
}
|
|
118
118
|
server.hostfs = hostfs
|
|
119
|
-
workerMod.WorkerController(server)
|
|
119
|
+
server.workco = workerMod.WorkerController(server)
|
|
120
120
|
list(false, port)
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -550,7 +550,7 @@ closure WebSocketServer(server, local websocks) {
|
|
|
550
550
|
*/
|
|
551
551
|
|
|
552
552
|
closure WesCon(server, websocks, socket, request, local wescon) {
|
|
553
|
-
global()
|
|
553
|
+
global(js)
|
|
554
554
|
wescon = new(object, this)
|
|
555
555
|
wescon.socket = socket
|
|
556
556
|
wescon.info = {
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/*
|
|
14
|
+
* globals
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
gWorkers;
|
|
19
|
+
|
|
13
20
|
|
|
14
21
|
/*
|
|
15
22
|
* workCurrent
|
|
@@ -19,8 +26,8 @@
|
|
|
19
26
|
*/
|
|
20
27
|
|
|
21
28
|
closure workCurrent(workco, workerID, startup, local current) {
|
|
22
|
-
global()
|
|
23
|
-
current =
|
|
29
|
+
global(js)
|
|
30
|
+
current = require("../running/executors.nlg").ExecutorBase(workco, workerID, startup.name)
|
|
24
31
|
current.workerID = workerID
|
|
25
32
|
current.name = startup.name
|
|
26
33
|
current.links = []
|
|
@@ -94,6 +101,7 @@ closure workCurrent(workco, workerID, startup, local current) {
|
|
|
94
101
|
function ONmessageOut(data) {
|
|
95
102
|
if data._guid
|
|
96
103
|
return // already replied
|
|
104
|
+
current.execReceived(data)
|
|
97
105
|
sendAll({
|
|
98
106
|
id: "targetout",
|
|
99
107
|
data: data
|
|
@@ -153,7 +161,17 @@ closure workCurrent(workco, workerID, startup, local current) {
|
|
|
153
161
|
if current.links.length == 0
|
|
154
162
|
current.host.Detach(current.termif) // attached while one link is active
|
|
155
163
|
}
|
|
156
|
-
|
|
164
|
+
|
|
165
|
+
//
|
|
166
|
+
// target.PostMessage
|
|
167
|
+
//
|
|
168
|
+
// Post a message to the main thread.
|
|
169
|
+
//
|
|
170
|
+
current.PostMessage = function PostMessage(data) {
|
|
171
|
+
js.t.DispatchMessage(data)
|
|
172
|
+
list(false, { posted: true })
|
|
173
|
+
}
|
|
174
|
+
|
|
157
175
|
//
|
|
158
176
|
// msgin
|
|
159
177
|
//
|
|
@@ -188,6 +206,18 @@ closure workCurrent(workco, workerID, startup, local current) {
|
|
|
188
206
|
};
|
|
189
207
|
|
|
190
208
|
|
|
209
|
+
/*
|
|
210
|
+
* WorkerConnect
|
|
211
|
+
*
|
|
212
|
+
* Return the existing web worker for a workerGUID, or false if it does not exist.
|
|
213
|
+
*
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
function WorkerConnect(workerGUID) {
|
|
217
|
+
gWorkers[workerGUID]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
191
221
|
/*
|
|
192
222
|
* workMainProxy
|
|
193
223
|
*
|
|
@@ -270,13 +300,14 @@ closure WorkerToMain(local nideRunning, track) {
|
|
|
270
300
|
*
|
|
271
301
|
*/
|
|
272
302
|
|
|
273
|
-
closure workThread(workco, workerID, startup,
|
|
274
|
-
|
|
275
|
-
|
|
303
|
+
closure workThread(workco, workerID, startup, guid
|
|
304
|
+
local worker, options, subChannel, deathWatcher) {
|
|
305
|
+
global(js, threads, JSpath)
|
|
306
|
+
worker = require("../running/executors.nlg").ExecutorBase(workco, workerID, startup.name)
|
|
276
307
|
worker.name = startup.name
|
|
277
308
|
worker.workerID = workerID
|
|
278
309
|
worker.links = []
|
|
279
|
-
worker.guid = UUID()
|
|
310
|
+
worker.guid = guid || UUID()
|
|
280
311
|
|
|
281
312
|
// create our worker thread
|
|
282
313
|
|
|
@@ -346,6 +377,8 @@ closure workThread(workco, workerID, startup, local worker, options, subChannel,
|
|
|
346
377
|
state: false // resume state, if we have any
|
|
347
378
|
altcmd: false
|
|
348
379
|
dirpath: js.d
|
|
380
|
+
workerID: workerID
|
|
381
|
+
workerGUID: worker.guid
|
|
349
382
|
}
|
|
350
383
|
if startup.initcmds
|
|
351
384
|
startmsg.altcmd = startup.initcmds.concat("\n")
|
|
@@ -364,6 +397,8 @@ closure workThread(workco, workerID, startup, local worker, options, subChannel,
|
|
|
364
397
|
else {
|
|
365
398
|
if msg.id == "status"
|
|
366
399
|
worker.lastStatus = milliseconds()
|
|
400
|
+
else if msg.id == "targetout"
|
|
401
|
+
worker.execReceived(msg.data)
|
|
367
402
|
sendAll(msg) } // default is just return message to the client
|
|
368
403
|
})
|
|
369
404
|
|
|
@@ -401,6 +436,19 @@ closure workThread(workco, workerID, startup, local worker, options, subChannel,
|
|
|
401
436
|
removeLink(link)
|
|
402
437
|
}
|
|
403
438
|
|
|
439
|
+
//
|
|
440
|
+
// PostMessage
|
|
441
|
+
//
|
|
442
|
+
// Post a message to the main thread.
|
|
443
|
+
//
|
|
444
|
+
worker.PostMessage = function PostMessage(data) {
|
|
445
|
+
worker.msgport.postMessage({ // send data to worker
|
|
446
|
+
id: "targetin",
|
|
447
|
+
data: data
|
|
448
|
+
})
|
|
449
|
+
list(false, { posted: true })
|
|
450
|
+
}
|
|
451
|
+
|
|
404
452
|
//
|
|
405
453
|
// msgin
|
|
406
454
|
//
|
|
@@ -498,7 +546,7 @@ closure workLink(workco, conn, worker, sender, local link) {
|
|
|
498
546
|
*/
|
|
499
547
|
|
|
500
548
|
closure workController(api, local workco) {
|
|
501
|
-
global()
|
|
549
|
+
global(gWorkers)
|
|
502
550
|
workco = new(object, this)
|
|
503
551
|
workco.serverID = "Workers" // our serverID, used for communications
|
|
504
552
|
workco.workers = { } // dictionary of workers by workerID
|
|
@@ -559,12 +607,47 @@ closure workController(api, local workco) {
|
|
|
559
607
|
workco.workers[workerID] = undefined // it's like this worker has never been
|
|
560
608
|
}
|
|
561
609
|
|
|
562
|
-
//
|
|
610
|
+
// spawn
|
|
611
|
+
//
|
|
612
|
+
// Spawn a new worker with the specified configuration dictionary and optional GUID.
|
|
613
|
+
//
|
|
614
|
+
workco.spawn = closure spawn(workerID, config, guid, local worker) {
|
|
615
|
+
if !dictionary(gWorkers)
|
|
616
|
+
gWorkers = {}
|
|
617
|
+
worker = workco.workers[workerID]
|
|
618
|
+
if !worker { // create worker if needed
|
|
619
|
+
if workerID == "NideServer"
|
|
620
|
+
worker = workco.current = workCurrent(workco, workerID, config)
|
|
621
|
+
else
|
|
622
|
+
worker = workThread(workco, workerID, config, guid)
|
|
623
|
+
workco.uworkers[worker.guid] = worker
|
|
624
|
+
workco.workers[workerID] = worker
|
|
625
|
+
gWorkers[worker.guid] = worker }
|
|
626
|
+
if workerID == "NideServer"
|
|
627
|
+
workco.current.vitalUpdate({
|
|
628
|
+
id: "workerlist", // send the initial list of workers
|
|
629
|
+
workers: let(workers, workerID, worker) {
|
|
630
|
+
workers = { }
|
|
631
|
+
for `(workerID, worker) in workco.workers
|
|
632
|
+
workers[workerID] = {
|
|
633
|
+
name: worker.name
|
|
634
|
+
}
|
|
635
|
+
workers
|
|
636
|
+
}()
|
|
637
|
+
})
|
|
638
|
+
else {
|
|
639
|
+
worker.vitalWatch(termination)
|
|
640
|
+
workco.current.vitalUpdate({
|
|
641
|
+
id: "spawned", // note a new worker thread
|
|
642
|
+
name: config.name
|
|
643
|
+
workerID: workerID
|
|
644
|
+
}) }
|
|
645
|
+
}
|
|
646
|
+
|
|
563
647
|
// wsReceive
|
|
564
648
|
//
|
|
565
649
|
// Process a message from the websocket API.
|
|
566
650
|
//
|
|
567
|
-
|
|
568
651
|
workco.wsReceive = function wsReceive(message, conn, local worker, link, error) {
|
|
569
652
|
if !message.workerID
|
|
570
653
|
error = Error("workerID required", message.workerOp)
|
|
@@ -576,50 +659,25 @@ closure workController(api, local workco) {
|
|
|
576
659
|
if worker && message.payload {
|
|
577
660
|
if !link
|
|
578
661
|
makeLink(message, conn) // make sure we have a link for responses
|
|
579
|
-
worker.msgin(message.payload)
|
|
580
|
-
|
|
662
|
+
worker.msgin(message.payload) } // send message to worker
|
|
663
|
+
return }
|
|
581
664
|
else if message.workerOp == "echo" {
|
|
582
665
|
if worker && message.payload {
|
|
583
666
|
if !link
|
|
584
667
|
makeLink(message, conn) // make sure we have a link for responses
|
|
585
|
-
worker.echo(message.payload, link)
|
|
586
|
-
|
|
668
|
+
worker.echo(message.payload, link) } // echo message to other links
|
|
669
|
+
return }
|
|
587
670
|
else if message.workerOp == "spawn" {
|
|
588
|
-
|
|
589
|
-
if message.workerID == "NideServer"
|
|
590
|
-
worker = workco.current = workCurrent(workco, message.workerID, message.payload)
|
|
591
|
-
else
|
|
592
|
-
worker = workThread(workco, message.workerID, message.payload)
|
|
593
|
-
workco.uworkers[worker.guid] = worker
|
|
594
|
-
workco.workers[message.workerID] = worker }
|
|
671
|
+
spawn(message.workerID, message.payload, message.workerGUID)
|
|
595
672
|
if !link
|
|
596
673
|
makeLink(message, conn) // make sure we have a link for responses
|
|
597
|
-
if message.workerID == "NideServer"
|
|
598
|
-
workco.current.vitalUpdate({
|
|
599
|
-
id: "workerlist", // send the initial list of workers
|
|
600
|
-
workers: let(workers, workerID, worker) {
|
|
601
|
-
workers = { }
|
|
602
|
-
for `(workerID, worker) in workco.workers
|
|
603
|
-
workers[workerID] = {
|
|
604
|
-
name: worker.name
|
|
605
|
-
}
|
|
606
|
-
workers
|
|
607
|
-
}()
|
|
608
|
-
})
|
|
609
|
-
else {
|
|
610
|
-
worker.vitalWatch(termination)
|
|
611
|
-
workco.current.vitalUpdate({
|
|
612
|
-
id: "spawned", // note a new worker thread
|
|
613
|
-
name: message.payload.name
|
|
614
|
-
workerID: message.workerID
|
|
615
|
-
}) }
|
|
616
674
|
return }
|
|
617
675
|
else if message.workerOp == "terminate" {
|
|
618
676
|
if worker {
|
|
619
677
|
if !link
|
|
620
678
|
makeLink(message, conn) // make sure we have a link for responses
|
|
621
|
-
worker.terminate()
|
|
622
|
-
|
|
679
|
+
worker.terminate() } // echo message to other links
|
|
680
|
+
return }
|
|
623
681
|
error = Error("invalid parameters", message.workerOp, message.workerID)
|
|
624
682
|
}
|
|
625
683
|
ErrorDebuglog("workController.wsReceive error:", error)
|
|
@@ -663,13 +721,13 @@ closure workController(api, local workco) {
|
|
|
663
721
|
*/
|
|
664
722
|
|
|
665
723
|
function workInit(local manifest) {
|
|
666
|
-
manifest = `(workCurrent, workMainProxy, WorkerToMain, workThread, workLink,
|
|
667
|
-
workInit)
|
|
668
|
-
|
|
724
|
+
manifest = `(workCurrent, WorkerConnect, workMainProxy, WorkerToMain, workThread, workLink,
|
|
725
|
+
workController, workInit)
|
|
669
726
|
Naan.module.build(module.id, "worker", function(modobj, compobj) {
|
|
670
727
|
require("./node.nlg")
|
|
671
728
|
compobj.manifest = manifest
|
|
672
729
|
modobj.exports.WorkerController = workController
|
|
730
|
+
modobj.exports.WorkerConnect = WorkerConnect
|
|
673
731
|
modobj.exports.WorkerToMain = WorkerToMain
|
|
674
732
|
})
|
|
675
733
|
}();
|
|
@@ -1067,7 +1067,6 @@ closure Builder(rules, operation, fs, srcpath, destpath, track, local build, gro
|
|
|
1067
1067
|
//
|
|
1068
1068
|
function writeCatenate(writepath,
|
|
1069
1069
|
local template, entry, content, catsub, dozip, docat, fsoptions, zipmap, error, result) {
|
|
1070
|
-
debuglog("writeCatenate", writepath)
|
|
1071
1070
|
template = build.templates[writepath] // optional in some cases ### should warn in others
|
|
1072
1071
|
catsub = { }
|
|
1073
1072
|
for entry in catenates[writepath] { // error check and substitution build
|
|
File without changes
|
|
@@ -296,7 +296,7 @@ closure projConnector(projman, projtype, local connector, watch) {
|
|
|
296
296
|
*
|
|
297
297
|
* Nide.proj/
|
|
298
298
|
* nide_cliser.cfg - JSON definition of the project (see below)
|
|
299
|
-
* NaanIDE_version.txt - [default] substitution file defining 1.
|
|
299
|
+
* NaanIDE_version.txt - [default] substitution file defining 1.4.0+1 etc.
|
|
300
300
|
* NaanIDE_version_builds.txt - [default] contains current build number as decimal string
|
|
301
301
|
* build/ - [optional] default build output location
|
|
302
302
|
* NaanIDE.lic - [optional] defines Zulch Laboratories, Inc. and other license info
|