Skip to Content
TutorialOrder Expiry Scheduler

Order Expiry Scheduler

https://editor.momen.app/tool/dK5wjNzNOkz/WEB?code=urAsbw5kqNaNt&ref=0562398

Introduction

  • Goal: Automatically change the status of an order from “Pending” to “Cancelled” if it remains unpaid for a specific duration.
  • Applicable Scenario: Order timeouts, membership expiration, meeting room release, or event registration deadlines.
  • Core Logic: Use a Scheduled Trigger to run a background Actionflow every minute, querying expired records and batch-updating their status.

Steps

Data Storage

  • Data Model: Create a table named order.
Field NameTypeNote
idBigIntUnique identifier (System default).
created_atTimestampRecord creation time (Used as the “Order Time”).
statusTextValues: Pending, Paid, Cancelled.

Logic Configuration (Actionflow)

Navigate to the Actionflow tab to build the automation logic.

Scheduled Trigger Configuration

  1. Create a new Actionflow named Order Status Auto-Update.
  2. In the Trigger panel, add a Schedule trigger.
  3. Start at / End at: Define the effective time range for this automation.
  4. Trigger frequency: Set to EVERY_MINUTE (for testing purposes) or your desired business interval.
  5. At which second: Specify an exact second.

Quota Usage Note: Every time the scheduled Actionflow runs, it consumes 1 run from your balance. You can track this by checking the “Number of remaining automated actionFlow” indicator in the top right corner of the editor. Please monitor your balance closely when configuring high-frequency triggers like EVERY_MINUTE.

Querying Expired Orders

Add a Query Data node to identify orders that need to be cancelled.

  1. Table: Select order.
  2. Filter Logic: Configure the conditions using the “And” operator:
    • status Equal to Pending.
    • created_at Less than or equal to DELTA formula.
  3. Formula Setting: Use the DELTA function to calculate the expiration threshold:
    • Original time: Current datetime.
    • Operation: Decrease.
    • Minute: 1 (This defines the 1-minute timeout).

Batch Updating Status

Use a loop to process the results from the query.

  1. Add Loop: Connect a Loop node to the Query node. Set the data source to the output of Query Unpaid Orders.
  2. Update Data: Inside the loop, add an Update Data node.
    • Table: order.
    • Filter: id Equal to Actionflow data -> Loop -> item -> id.
    • Parameters: Set status to a constant value: Cancelled.

Verification

To test the logic, go to the Data -> Database view and follow these steps to observe the time-sensitive behavior:

  1. Insert Test Data: Manually add two records.
    • Record A: status = Paid.
    • Record B: status = Pending. Note the exact created_at time (e.g., 12:33:10).
  2. First Execution Cycle:
    • Wait for the first scheduled trigger (e.g., at 12:33:53).
    • Since the time elapsed since creation (43 seconds) is less than the 1-minute threshold defined in the DELTA formula, the status will remain unchanged as Pending.
  3. Second Execution Cycle:
    • Wait for the next scheduled trigger (e.g., at 12:34:53).
    • Now that the elapsed time (1 minute and 43 seconds) exceeds the 1-minute threshold, the Actionflow will successfully query the record.
  4. Final Result: Refresh the database view. Record B’s status should now be updated to Cancelled, while Record A remains Paid.

⚠️

Because the trigger runs at a fixed interval (e.g., the 53rd second of every minute), a record might wait anywhere from 1 minute to 1 minute and 59 seconds before being processed, depending on exactly when it was created relative to the trigger cycle.

Last updated on