line

Shipping Workflow

The Shipping Workflow is triggered when the payment confirmation has been received. At this stage, several external events can be received. Here are the details:

Visual of Workflow

The flowchart of the shipping workflow is showing the different events you can receive that results in different scenarios.
line

Workflow Steps

  • Fulfill the shipment
  • At the same time, wait one week to receive external events about shipment
  • Either the order is fulfilled, in which case the tracking workflow is launched
  • Or the charge back event is received and it cancels the order from the shipment
  • Or the out of stock event is received and it alerts the user
  • In the case that no events are received, the alert is not fulfilled

Workflow Code

This workflow is the code that orchestrates the tasks through the Zenaton workflow engine and are then executed on your servers.

const { workflow, duration } = require("zenaton");

module.exports = workflow("ShippingWorkflow", {
  *handle(shipment) {
    this.shipment = shipment;
    
    yield this.run.task("Fulfill", this.shipment)

    const fulfilled = yield this.wait.event("Fulfilled").for(duration.weeks(1));

    if (fulfilled) {
      yield this.run.task("ProceedToTracking", this.shipment)
    } else {
      yield this.run.task("AlertNotFulfilled", this.shipment)
    }
  },
  *onEvent(eventName) {
    if (eventName === "ChargeBack") {
      yield this.run.task("CancelOrderFromShipment", this.shipment)
    }
    if (eventName === "OutOfStock") {
      yield this.run.task("ProcessOutOfStockQuantity", this.shipment)
    }
  },
});

Workflow Executions

View the real-time tasks executions of this workflow.
line