Defining an event-driven job stream from the Dynamic Workload Console

You can define event-driven job streams from the Dynamic Workload Console.

About this task

The purpose of the following scenario is to show how to define a webhook event-driven job stream in the context of an example.

OrdinaryHero is an online store specializing in gym clothes. When a new order is placed, a webhook notification is sent to the accounting system to confirm payment registration. The webhook event contains a header named EventType, and the value of the header is NewOrder.

Upon completion of the purchase process, the IT team has developed a script named order_info that automatically sends an email to the warehouse, containing comprehensive order information:

#!/bin/bash

# Email configuration
recipient_email="warehouse@ordinaryhero.com"
subject="New order information"

# Process the webhook data
order_id="12345"
customer_name="Mike Lighthouse"
order_total="$100.00"
customer_address="2570 Lincoln Blvd #101, Venice, California, 90291"
customer_country="USA"

# Construct the email body
email_body="Order ID: $order_id\n"
email_body+="Customer name: $customer_name\n"
email_body+="Order total: $order_total\n"
email_body+="Customer address: $customer_address\n"
email_body+="Customer Country: $customer_country\n"

# Create the email message
email_message="To: $recipient_email\n"
email_message+="Subject: $subject\n"
email_message+="$email_body"

# Send the email using sendmail
echo -e "$email_message" | sendmail -t
The IT team has also defined an event source named EVT_SRC_ORDERS from Orchestration CLI.

The store owner wants to create a job stream that runs order_info script when the payment has been registered, providing order information to the warehouse and initiating the order delivery process. To expedite the process, the owner wants to automate the submission of the job stream upon receiving the webhook notification.

You can find the steps to automate such process below.

Procedure

  1. Create a job that runs the order_info script to send emails containing order information to the warehouse:
    1. From the Workspace area, click Create new + and select Job definition.
    2. From Choose job definition, select Executable.
    3. In General Info, select the Folder.
    4. In General Info, in Name, type send_mail_job.
    5. In General Info, select a Workstation.
    6. In Task, select Command and enter order_info in Command or script name.
    7. Save.
  2. Create a job stream and add send_mail_job to the job stream:
    1. From the Design menu, click Workload Designer page, and then select the engine.
    2. In Explore area, click Create new + and select Job stream.
    3. In General Info, select a Folder.
    4. In General Info, in Name, type warehouse_order.
    5. In General Info, select a Workstation.
    6. In Jobs, click Add job, and then search and select send_mail_job.
    7. Save.
  3. Add an event group to the warehouse_info job stream and define general information about it:
    1. In the Trigger row, click Add event group.
    2. In General Info, in Name, type online_order_trigger.
    3. Save.
  4. Add a webhook event to the online_order_trigger event group and provide webhook information:
    1. In the online_order_trigger event group row, click Add event.
    2. In Add event panel, select Webhook event received.
    3. In General info, in Event name, type payment_received.
    4. In General info, in Event source, specify EVT_SRC_ORDERS event source.
    5. In Method, select matches and then select POST from the drop-down menu.
    6. In Headers, in Key and value, type EventType, NewOrder.
    7. Save.

Results

Whenever a new order is placed, the warehouse_order job stream is activated through a webhook notification. Subsequently, the warehouse receives an email containing the order details, initiating the commencement of the order delivery process.