camunda-community-hub / zeebe-client-node-js

Node.js client library for Zeebe Microservices Orchestration Engine
https://camunda-community-hub.github.io/zeebe-client-node-js/
Apache License 2.0
152 stars 38 forks source link

[FEATURE REQUEST] Method for getting an list of deployed workflows #169

Closed marcelloti closed 4 years ago

marcelloti commented 4 years ago

This can be useful for checking if an workflow it's already deploy - by id or name:

Something like this: const deployedWorkflows = await ZbClient.WorkflowList();

marcelloti commented 4 years ago

For checking if it's already deployed currently I am doing this:

async function checkIfProcessExists(zb, processId) {
        let processExists = true;
        try {
            await zb.createWorkflowInstance({
                bpmnProcessId: processId,
                version: 0, // Putting version equals to zero in here apparently does nothing in "createWorkflowInstance" command
            });
        } catch (err) {
            processExists = false;
        }

        return processExists;
    }

[Edit]: "version: 0" it does something... So, it is not a solution...

jwulf commented 4 years ago

Zeebe prior to 0.18 had an API to listDeployedWorkflows, but it was removed.

I usually deploy on startup. Restarting a broker can cause that to be a problem, because you need to restart your client app to redeploy.

I have also dealt with it using something like this:

// Have to verify that this is how you test for this error
const notDeployed = err => err.message.indexOf('5:') === 0

function createWorkflowInstance(bpmnProcessId, variables) {
    return zbc.createWorkflowInstance(bpmnProcessId, variables)
        .catch(err => notDeployed(err) ? 
            deploy(bpmnProcessId).then(() => doIt(bpmnProcessId, variables)) :
            throw new Error(err))
}

function deploy(bpmnProcessId) {
    // Lookup your resources
    const model = ModelRepository.get(bpmnProcessId)
    return zbc.deployWorkflow(model.filename)
}
marcelloti commented 4 years ago

Hum... interesting... So, currently, for because some bug or update in broker container, if I had to restart the broker, I really need to redeploy all workflows ? I actually have notice this behaviour on zeebe monitor (all workflows dissapear) but I was thinking that was a bug/behaviour of Zeebe Monitor (not Zeebe). Actually, I already have been tested this scenario:

  1. I deployed a workflow (and then the workflow had appears on Zeebe Monitor)
  2. Then I restarted the broker
  3. Then I checked the Zeebe Monitor and workflow dissapear
  4. So, then I tried to run the workflow (with zeebe-node package) and the workflow worked anyway (Which had makes belive that it's a behavior of Zeebe Monitor and not of Zeebe Broker).

Anyway... there is a plan to reimplement the API (like in 0.18 version) in the future?

jwulf commented 4 years ago

Anyway... there is a plan to reimplement the API (like in 0.18 version) in the future?

No.

Simple Monitor stores its data in an in-memory H2 database, so restarting the container/app loses everything.

Zeebe stores the Event Log and a projection of the current state on disk, and rebuilds the current state on restart.

marcelloti commented 4 years ago

So... there really isn't a way I can use to "read" the Zeebe broker event log (even if I manually create code to read the contents of the "data" directory - for example ...), right ?

jwulf commented 4 years ago

The easiest way to do it is to run Elastic Search and the Elastic Search exporter, then query Elastic Search.

Have a look at https://github.com/zeebe-io/zeebe-docker-compose and hit up https://forum.zeebe.io if you have more questions about it.