GithubHelp home page GithubHelp logo

Workflow introspection about workflow-es HOT 2 OPEN

oguimbal avatar oguimbal commented on August 19, 2024
Workflow introspection

from workflow-es.

Comments (2)

Duwab avatar Duwab commented on August 19, 2024 2

Hi!

To help those asking for the same question, here is an example of a simple logProgress function.

import { configureWorkflow, IWorkflowHost, WorkflowConfig, IWorkflowRegistry, TYPES, IPersistenceProvider, WorkflowStatus } from 'workflow-es';
// ...

export class HostModule {
    private workflowConfig: WorkflowConfig;

    constructor() {
        this.workflowConfig = configureWorkflow();
        this.workflowConfig.registerWorkflow(MyWorkflow1);
        this.workflowConfig.registerWorkflow(MyWorkflow2);
    }

    async logProgress(workflowId: string) {
        const container = await this.workflowConfig.getContainer();
        const persistence = container.get<IPersistenceProvider>(TYPES.IPersistenceProvider);
        const registry = container.get<IWorkflowRegistry>(TYPES.IWorkflowRegistry);

        const wf = await persistence.getWorkflowInstance(workflowId);
        const wfDefinition = await registry.getDefinition(wf.workflowDefinitionId, wf.version);
        console.log("\n\n\n------- wf introspection", `status=${this.getWorkflowStatusKey(wf.status)}`);
        console.log(wfDefinition.steps.map(step => `step(${step.id}): ${step.body.name}`));
        console.log(`execution pointers steps (${wf.executionPointers.length}) :`);
        console.log(wf.executionPointers.map((p, i) => `pointer n°${i} => step(${p.stepId})${p.active ? ' **active**' : ''}`));
    }

    private getWorkflowStatusKey(value: number): string {
        const statuses: { [key: string]: number } = {...WorkflowStatus};
        for (let key in statuses) {
            if (statuses[key] === value) {
                return key
            }
        }

        return "unknown";
    }
}

This will log something like this :

// HostModule.logProgress
------- wf introspection status=Runnable
[
  'step(0): ConfigurationTask',
  'step(1): Foreach',
  'step(2): AllocateResourcesTask',
  'step(3): Foreach',
  'step(4): SetupVaultsTask',
  'step(5): Foreach',
  'step(6): ServiceCheckTask',
  'step(7): ServiceDeployTask',
  'step(8): ServiceRestartTask',
  'step(9): NginxReloadTask',
  'step(10): Foreach',
  'step(11): ServiceCleanupTask'
]
execution pointers steps (16) :
[
  'pointer n°0 => step(0)',
  'pointer n°1 => step(1)',
  'pointer n°2 => step(2)',
  'pointer n°3 => step(2)',
  'pointer n°4 => step(2)',
  'pointer n°5 => step(3)',
  'pointer n°6 => step(4)',
  'pointer n°7 => step(4)',
  'pointer n°8 => step(4)',
  'pointer n°9 => step(5) **active**',
  'pointer n°10 => step(6)',
  'pointer n°11 => step(6)',
  'pointer n°12 => step(6)',
  'pointer n°13 => step(7) **active**',
  'pointer n°14 => step(7) **active**',
  'pointer n°15 => step(7) **active**'
]

The purpose of this is to give an idea of what to expect before diving into code. I hope someone would find it useful :D

from workflow-es.

danielgerlag avatar danielgerlag commented on August 19, 2024

Hi,

The Persistence Provider implementations do allow you to retrieve and inspect a single workflow. It would not be hard to add some additional methods to this class to enabled this across multiple workflows. This has been done on Workflow Core which is the sister project (.NET version) of this project.

You can use WorkflowConfig.getContainer to access to IoC container to access the implementation of this.

from workflow-es.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.