dagu icon indicating copy to clipboard operation
dagu copied to clipboard

Allow complex `precondition` conditions

Open yohamta opened this issue 7 months ago • 0 comments

Brief overview

We aim to support more complex conditions in the preconditions field.

Proposed solution: Inline script

We suggest allowing the use of JavaScript in the condition field.

Javascript

preconditions:
  - condition: "$EXIT_CODE == 1 || $EXIT_CODE == 2"
    expected: true

Alternative Approaches

Option 1: Functional Programming

preconditions:
  - condition: "(or (eq $EXIT_CODE 1) (eq $EXIT_CODE 2))"
    expected: true

Option 2: Logic Programming

preconditions:
  - condition: "member($EXIT_CODE, [1, 2])"
    expected: true

Alternative solution: operator field

preconditions:
  - condition: "$EXIT_CODE"
     operator: "ne"
    expected: "2"

When operator field is not provided, it will be handled as "eq". Valid values are as follows:

  • != or ne
  • == or eq
  • >= or ge
  • > or gt
  • <= or le
  • < or lt
  • OR or AND
  • conditions

Complex example that matches only when EXIT_CODE is neither 1 or 2:

preconditions:
    operator: "AND"
    conditions:
    - condition: "$EXIT_CODE"
       operator: "ne"
      expected: "1"
    - condition: "$EXIT_CODE"
       operator: "ne"
      expected: "2"

yohamta avatar Jul 04 '24 09:07 yohamta