retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.05k stars 652 forks source link

Tasks with server side running engine #125

Closed RobinFalko closed 6 years ago

RobinFalko commented 6 years ago

I have the engine server side and the editor client side. The generated JSON is sent between client and server on user request (button click).

Now I tried to implement the task example (key-event-node, key-code-node and alert-node) but I can't get my head around the client-server-communication in this case.

On one hand I still need to transfer the JSON and on the other hand I would need to send messages to the server to invoke the workers - Don't know if manually calling the workers is even possible.

Is there an example what could guide me here or isn't this possible yet at all?

-- Great engine btw! I really like it.

RobinFalko commented 6 years ago

Now I spent some more time and I'm a bit confused about the installation of the task-plugin. The editor will trigger the worker wrapping by listening to 'componentregister', but why is the editor responsible for manipulating a worker? Shouldn't this be done by the engine? I'm also wondering why Task is not exported/public. One could then handle "Task configuration" manually on the server side.

Source: https://github.com/retejs/task-plugin/blob/master/index.js

Ni55aN commented 6 years ago

The editor will trigger the worker wrapping by listening to 'componentregister', but why is the editor responsible for manipulating a worker? Shouldn't this be done by the engine?

Exactly! But in this case there no differences beetween

editor.use(TaskPlugin);
/// and
engine.use(TaskPlugin);

I'm also wondering why Task is not exported/public. One could then handle "Task configuration" manually on the server side.

Tasks are created during engine processing in isolation and do not require manual intervention (this is for the sake of ease of use, since you do not need to know how it works inside). Or do you have examples where it necessary?

RobinFalko commented 6 years ago

Thanks for your response. I didn't know that engine.use(TaskPlugin); should work. Having this* code on my server side gives me the errors:

Error:(94, 32) TS2339: Property 'use' does not exist on type 'Engine'. Error:(94, 36) TS2304: Cannot find name 'TaskPlugin'.

*

import {Component, Engine} from "rete/build/rete.engine";

export class MyClass {
    someFunc() {
        var engine = new Engine("myEngine@0.1.0");
        engine.use(TaskPlugin);
    }
}

For now I solved my issue by copying "task.js" to my project as "Task.ts", copying the initialization code and wrapping the worker if the component is "Taskable". Feels very hacky since I'm no javascript expert but ... it does it's job.

interface Taskable {
    name: string;
    task: any;
    worker: (node : any, inputs : any[][], outputs : any[]) => Promise<any> | any;
}
Ni55aN commented 6 years ago

Please make sure you are importing the actual version v1.0.0-alpha.2 and rete-task-plugin