How to use @node-ts/bus-workflow - 10 common examples

To help you get started, we’ve selected a few @node-ts/bus-workflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-ts / bus-starter / src / workflows / siren-test-workflow.ts View on Github external
sirenId
    )
    await this.bus.send(emailMaintenanceTeam)
    return {}
  }

  @Handles(
    SirenTestPassed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesSirenTestPassed (_: SirenTestPassed): Promise> {
    return this.complete()
  }

  @Handles(
    MaintenanceTeamEmailed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesMaintenanceTeamEmailed (_: MaintenanceTeamEmailed): Promise> {
    return this.complete({
      maintenanceEmailSent: true
    })
  }

}
github node-ts / bus-starter / src / workflows / siren-test-workflow.ts View on Github external
@Handles(
    SirenTestFailed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
    const emailMaintenanceTeam = new EmailMaintenanceTeam(
      'A siren has failed its test and requires maintenance',
      sirenId
    )
    await this.bus.send(emailMaintenanceTeam)
    return {}
  }

  @Handles(
    SirenTestPassed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesSirenTestPassed (_: SirenTestPassed): Promise> {
    return this.complete()
  }

  @Handles(
    MaintenanceTeamEmailed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesMaintenanceTeamEmailed (_: MaintenanceTeamEmailed): Promise> {
    return this.complete({
      maintenanceEmailSent: true
github node-ts / bus-starter / src / workflows / siren-test-workflow.ts View on Github external
export class SirenTestWorkflow extends Workflow {

  constructor (
    @inject(BUS_SYMBOLS.Bus) private readonly bus: Bus
  ) {
    super()
  }

  @StartedBy(SirenTestStarted)
  handlesSirenTestStarted ({ sirenId }: SirenTestStarted): Partial {
    return {
      sirenId
    }
  }

  @Handles(
    SirenTestFailed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
    const emailMaintenanceTeam = new EmailMaintenanceTeam(
      'A siren has failed its test and requires maintenance',
      sirenId
    )
    await this.bus.send(emailMaintenanceTeam)
    return {}
  }

  @Handles(
    SirenTestPassed,
    event => event.sirenId,
github node-ts / bus-starter / src / workflows / siren-test-workflow.ts View on Github external
import { Workflow, StartedBy, Handles } from '@node-ts/bus-workflow'
import { SirenTestWorkflowData } from './sirent-test-workflow-data'
import { SirenTestStarted, SirenTestFailed, SirenTestPassed, EmailMaintenanceTeam, MaintenanceTeamEmailed } from '../messages'
import { inject } from 'inversify'
import { BUS_SYMBOLS, Bus } from '@node-ts/bus-core'

export class SirenTestWorkflow extends Workflow {

  constructor (
    @inject(BUS_SYMBOLS.Bus) private readonly bus: Bus
  ) {
    super()
  }

  @StartedBy(SirenTestStarted)
  handlesSirenTestStarted ({ sirenId }: SirenTestStarted): Partial {
    return {
      sirenId
    }
  }

  @Handles(
    SirenTestFailed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
    const emailMaintenanceTeam = new EmailMaintenanceTeam(
      'A siren has failed its test and requires maintenance',
      sirenId
    )
github node-ts / bus / packages / bus-postgres / src / postgres-persistence.integration.ts View on Github external
it('should retrieve the item', async () => {
        mapping = new MessageWorkflowMapping (
          cmd => cmd.property1,
          'property1'
        )
        const results = await sut.getWorkflowData(
          TestWorkflowData,
          mapping,
          testCommand,
          messageOptions
        )
        expect(results).toHaveLength(1)
        dataV1 = results[0]
        expect(dataV1).toMatchObject({ ...workflowData, $version: 1 })
      })
github node-ts / bus / packages / bus-postgres / src / postgres-persistence.integration.ts View on Github external
describe('when saving new workflow data', () => {
    const workflowData = new TestWorkflowData()
    workflowData.$workflowId = uuid.v4()
    workflowData.$status = WorkflowStatus.Running
    workflowData.$version = 0
    workflowData.eventValue = 'abc'
    workflowData.property1 = 'something'

    beforeAll(async () => {
      await sut.saveWorkflowData(workflowData)
    })

    it('should add the row into the table', async () => {
      const result = await postgres.query('select count(*) from "workflows"."testworkflowdata"')
      const { count } = result.rows[0] as { count: string }
      expect(count).toEqual('1')
    })

    describe('when getting the workflow data by property', () => {
      const testCommand = new TestCommand(workflowData.property1)
github node-ts / bus-starter / src / index.ts View on Github external
async function initialize (): Promise {
  const workflowRegistry = container.get(BUS_WORKFLOW_SYMBOLS.WorkflowRegistry)
  workflowRegistry.register(SirenTestWorkflow, SirenTestWorkflowData)
  await workflowRegistry.initializeWorkflows()

  const bootstrap = container.get(BUS_SYMBOLS.ApplicationBootstrap)
  bootstrap.registerHandler(StartSirenTestHandler)
  bootstrap.registerHandler(EmailMaintenanceTeamHandler)

  await bootstrap.initialize(container)
}
github node-ts / bus / packages / bus-postgres / src / postgres-persistence.integration.ts View on Github external
beforeAll(async () => {
    container = new TestContainer()
    container.bind(BUS_POSTGRES_SYMBOLS.PostgresConfiguration).toConstantValue(configuration)
    bus = container.get(BUS_SYMBOLS.Bus)
    sut = container.get(BUS_WORKFLOW_SYMBOLS.Persistence)
    postgres = container.get(BUS_POSTGRES_INTERNAL_SYMBOLS.PostgresPool)

    workflows = container.get(BUS_WORKFLOW_SYMBOLS.WorkflowRegistry)
    workflows.register(TestWorkflow, TestWorkflowData)
    await workflows.initializeWorkflows()

    bootstrap = container.get(BUS_SYMBOLS.ApplicationBootstrap)
    await bootstrap.initialize(container)
  })
github node-ts / bus / packages / bus-postgres / src / postgres-persistence.integration.ts View on Github external
beforeAll(async () => {
    container = new TestContainer()
    container.bind(BUS_POSTGRES_SYMBOLS.PostgresConfiguration).toConstantValue(configuration)
    bus = container.get(BUS_SYMBOLS.Bus)
    sut = container.get(BUS_WORKFLOW_SYMBOLS.Persistence)
    postgres = container.get(BUS_POSTGRES_INTERNAL_SYMBOLS.PostgresPool)

    workflows = container.get(BUS_WORKFLOW_SYMBOLS.WorkflowRegistry)
    workflows.register(TestWorkflow, TestWorkflowData)
    await workflows.initializeWorkflows()

    bootstrap = container.get(BUS_SYMBOLS.ApplicationBootstrap)
    await bootstrap.initialize(container)
  })
github node-ts / bus-starter / src / application-container.ts View on Github external
constructor () {
    super()
    this.load(
      new LoggerModule(),
      new WinstonModule(),
      new BusModule(),
      new BusWorkflowModule(),
      new HandlersModule()
    )
  }
}