Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine/ script execution getService #414

Merged
merged 49 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ea46d11
fix(ms-old): correct import
FelipeTrost Sep 17, 2024
39ef5bc
feat(engine): initial code execution
FelipeTrost Sep 20, 2024
c4a1534
fix(engine/native-node): don't instantiate classes 2 times when child…
FelipeTrost Sep 22, 2024
d19bee1
fix(engine/native-script-execution): allow empty results and explicit…
FelipeTrost Sep 22, 2024
89a47fe
fix(engine/native-script-execution): exit with code 1 on failure
FelipeTrost Sep 22, 2024
5f7bdb0
fix(engine/native-script-execution): refactor middleware
FelipeTrost Sep 22, 2024
71b3729
fix(engine/native-script-execution): pass http port to childProcess
FelipeTrost Sep 22, 2024
d90cc74
fix(engine/native-script-execution): kill process
FelipeTrost Sep 24, 2024
f0bad48
fix(engine/native-script-execution): accept no result
FelipeTrost Sep 24, 2024
bada438
fix(engine/native-script-execution): function calls
FelipeTrost Sep 24, 2024
41d7876
refactor: error message
FelipeTrost Sep 24, 2024
bbc1a95
fix(engine/native-script-execution): turned functions from async to sync
FelipeTrost Sep 24, 2024
2daf900
fix(engine/native-script-execution): bpmn errors
FelipeTrost Sep 25, 2024
e555ee9
fix(engine/native-script-execution): setIntervalAsync and setTimeoutA…
FelipeTrost Sep 25, 2024
28ba57b
feat(engine/natve-express): include headers in request
FelipeTrost Sep 28, 2024
04a6c73
refactor(engine/native-script-execution): use network module
FelipeTrost Sep 28, 2024
b2cd718
fix(engine/subprocess-script-execution): correctly return fn call output
FelipeTrost Oct 3, 2024
4290bb1
refactor(engine/script-execution): moved script execution to universa…
FelipeTrost Oct 3, 2024
a07e242
fix(engine/messaging): call to undefined variable
FelipeTrost Oct 3, 2024
bb7ce6e
refactor(engine): optionally init subprocess script execution
FelipeTrost Oct 3, 2024
bb5ae51
refactor(engine/script-execution): don't use private classes
FelipeTrost Oct 3, 2024
6b243f3
removed dated todo comments
FelipeTrost Oct 14, 2024
ae80891
refactor(engine/script-execution): stopSubprocess
FelipeTrost Oct 14, 2024
4b919bc
refactor(engine/script-execution): multiple scripts per process instance
FelipeTrost Oct 15, 2024
8f54f10
Merge remote-tracking branch 'origin/main' into engine/script-execution
FelipeTrost Oct 15, 2024
5642164
feat(native-node-engine/child-process): sync or async return values
FelipeTrost Oct 29, 2024
0e8e33d
fix(engine-universal/script-execution): allow instance to start multi…
FelipeTrost Oct 29, 2024
124f600
feat(engine/e2e-tests): use ChildProcess script execution
FelipeTrost Oct 29, 2024
96cb063
fix(engine/build): use webpack supported syntax
FelipeTrost Oct 29, 2024
2366b4b
fix(engine/build): webpack node-loader for isolated-vm
FelipeTrost Oct 29, 2024
b9d8393
fix(engine/build): external dependency child_process
FelipeTrost Oct 29, 2024
dd456f3
fix(engine/script-execution): don't stop all scripts of a process onc…
FelipeTrost Nov 14, 2024
15b4f94
fix(engine/script-execution): don't stop all scripts of a process onc…
FelipeTrost Nov 14, 2024
bbfc584
refactor(engine/script-execution): renamed module
FelipeTrost Nov 16, 2024
f7b83bd
refactor: removed console.log
FelipeTrost Nov 16, 2024
edec5f3
refactor(engine/native-script-execution): setIntervalAsync
FelipeTrost Nov 16, 2024
f809bf7
feat(engine/script-execution): getService
FelipeTrost Nov 20, 2024
2a3cdd6
fix(engine/neo-engine-setup): correct function params
FelipeTrost Nov 20, 2024
e875810
chore(engine/neo-engine-setup): _ prefix for unused params
FelipeTrost Nov 20, 2024
001ec99
refactor(engine/neo-engine): make network service responses serializable
FelipeTrost Nov 20, 2024
782560d
fix(engine/neo-engine): network serializer handle case with no response
FelipeTrost Nov 20, 2024
7f6a5aa
refactor(engine/neo-engine): type
FelipeTrost Nov 20, 2024
a4ab9f6
Merge remote-tracking branch 'origin/main' into engine/script-execution2
FelipeTrost Nov 20, 2024
402d087
Merge branch 'main' into engine/script-execution2
FelipeTrost Nov 23, 2024
f95e001
format
FelipeTrost Nov 24, 2024
d564ec6
Merge branch 'main' into engine/script-execution2
FelipeTrost Nov 27, 2024
2cd7f26
Merge branch 'main' into engine/script-execution2
FelipeTrost Nov 29, 2024
dbafa9b
Merge branch 'main' into engine/script-execution2
FelipeTrost Dec 5, 2024
c57cf76
Merge branch 'main' into engine/script-execution2
OhKai Dec 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/engine/native/node/native-script-execution/src/childProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ context.global.setSync('_stdout_log', function (...args) {
// TODO: pass these in as a process argument

// TODO: setProgress(<number between 0 - 100>)
// TODO: getService('capabilities')
// TODO: getService('network')

const structure = {
log: ['get'],
Expand Down Expand Up @@ -104,6 +102,38 @@ for (const objName of Object.keys(structure)) {
}
}

function _callToService(serviceName, method, args) {
/**@type {import('isolated-vm').Reference} */
const call = $0;
return call.apply(null, [serviceName, method, JSON.stringify(args)], {
result: { promise: true, copy: true },
});
}
function _getService(serviceName) {
return new Proxy(
{},
{
get: function (_, method) {
return (...args) => callToService(serviceName, method, args);
},
},
);
}
context.evalClosureSync(
`
${_callToService.toString()}; globalThis["callToService"] = _callToService;
${_getService.toString()}; globalThis["getService"] = _getService;
`,
[
new ivm.Reference(function (serviceName, method, args) {
return callToExecutor('call', {
functionName: `getService.${serviceName}.${method}`,
args: [processId, processInstanceId, tokenId, ...JSON.parse(args)],
});
}),
],
);

const errorClasses = ['BpmnError', 'BpmnEscalation'];

for (const errorName of errorClasses)
Expand Down
62 changes: 45 additions & 17 deletions src/engine/universal/core/src/engine/neoEngineSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,54 @@ const NeoEngine = require('neo-bpmn-engine');
const system = require('@proceed/system');
const capabilities = require('@proceed/capabilities');

const allowedResponseKeys = [
'httpVersionMajor',
'httpVersionMinor',
'httpVersion',
'complete',
'rawHeaders',
'rawTrailers',
'joinDuplicateHeaders',
'aborted',
'upgrade',
'url',
'method',
'statusCode',
'statusMessage',
];
/** @param {{response: import('http').IncomingMessage, body: any}} response */
function networkResponseToSerializable(response) {
if (!response || !response.response) return response;
const filteredResponse = {};
for (const key of allowedResponseKeys) filteredResponse[key] = response.response[key];
return { response: filteredResponse, body: response.body };
}

module.exports = {
setupNeoEngine() {
// Register the modules which we wish to make use of in the script environment
NeoEngine.provideService('capabilities', {
startCapability: (processId, processInstanceId, capabilityName, args, callback) =>
startCapability: (_processId, _processInstanceId, _tokenId, capabilityName, args, callback) =>
capabilities.startCapability.call(capabilities, capabilityName, args, callback),
});
NeoEngine.provideService('network', {
get: (processId, processInstanceId, tokenId, url, options) => {
return system.http.request.call(system.http, url, {
get: async (_processId, _processInstanceId, _tokenId, url, options) => {
const response = await system.http.request.call(system.http, url, {
...options,
method: 'GET',
});
return networkResponseToSerializable(response);
},
post: (
processId,
processInstanceId,
tokenId,
post: async (
_processId,
_processInstanceId,
_tokenId,
url,
body,
contentType = 'text/plain',
options = {},
) => {
return system.http.request.call(system.http, url, {
const response = await system.http.request.call(system.http, url, {
...options,
body,
method: 'POST',
Expand All @@ -34,17 +58,18 @@ module.exports = {
'Content-Type': contentType,
},
});
return networkResponseToSerializable(response);
},
put: (
processId,
processInstanceId,
tokenId,
put: async (
_processId,
_processInstanceId,
_tokenId,
url,
body,
contentType = 'text/plain',
options = {},
) => {
return system.http.request.call(system.http, url, {
const response = await system.http.request.call(system.http, url, {
...options,
body,
method: 'PUT',
Expand All @@ -53,18 +78,21 @@ module.exports = {
'Content-Type': contentType,
},
});
return networkResponseToSerializable(response);
},
delete: (processId, processInstanceId, tokenId, url, options) => {
return system.http.request.call(system.http, url, {
delete: async (_processId, _processInstanceId, _tokenId, url, options) => {
const response = await system.http.request.call(system.http, url, {
...options,
method: 'DELETE',
});
return networkResponseToSerializable(response);
},
head: (processId, processInstanceId, tokenId, url, options) => {
return system.http.request.call(system.http, url, {
head: async (_processId, _processInstanceId, _tokenId, url, options) => {
const response = await system.http.request.call(system.http, url, {
...options,
method: 'HEAD',
});
return networkResponseToSerializable(response);
},
});
},
Expand Down
13 changes: 9 additions & 4 deletions src/engine/universal/system/src/script-execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,21 @@ class ScriptExecutor extends System {

try {
let target = req.process.dependencies;
for (const segment of functionName.split('.')) {
target = target[segment];
const segments = functionName.split('.');
for (let i = 0; i < segments.length; i++) {
const segment = segments[i];

if (segments[i - 1] === 'getService') target = target(segment);
else target = target[segment];

if (typeof target === 'undefined')
return { response: { error: 'Function not found' }, statusCode: 404 };
}

let result = target;
if (typeof target === 'function' || typeof target === 'object')
return { response: { result: await target(...args) } };
else return { response: { result: target } };
result = await target(...args);
return { response: { result } };
} catch (e) {
return { response: { error: `Error: ${e.message}` }, statusCode: 500 };
}
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20298,6 +20298,20 @@ simple-get@^4.0.0:
once "^1.3.1"
simple-concat "^1.0.0"

simple-concat@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f"
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==

simple-get@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-4.0.1.tgz#4a39db549287c979d352112fa03fd99fd6bc3543"
integrity sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==
dependencies:
decompress-response "^6.0.0"
once "^1.3.1"
simple-concat "^1.0.0"

simple-swizzle@^0.2.2:
version "0.2.2"
resolved "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz"
Expand Down
Loading