Add function to wait repetitive task to finish successfully when the DAG received a signal
dagu
A simple Airflow alternative to run workflows (DAGs) defined in declarative YAML format
dagu is a simple workflow engine to generate and executes DAGs (Directed acyclic graph) from YAML definiton. dagu comes with a web UI and REST API interfaces are also included.
Contents
- dagu
Motivation
Currently, my environment has many problems. Hundreds of complex cron jobs are registered on huge servers and it is impossible to keep track of the dependencies between them. If one job fails, I don't know which job to re-run. I also have to SSH into the server to see the logs and manually run the shell scripts one by one.
So I needed a tool that can explicitly visualize and manage the dependencies of the pipeline.
How nice it would be to be able to visually see the job dependencies, execution status, and logs of each job in a web browser, and to be able to rerun or stop a series of jobs with just a mouse click!
Why not existing tools, like Airflow?
I considered many potential tools such as Airflow, Rundeck, Luigi, DigDag, JobScheduler, etc.
But unfortunately, they were not suitable for my existing environment. Because they required a DBMS (Database Management System) installation, relatively high learning curves, and more operational overheads. We only have a small group of engineers in our office and use a less common DBMS.
Finally, I decided to build my own tool that would not require any DBMS server, any daemon process, or any additional operational burden and is easy to use. I hope that this tool will help people in the same situations.
Quick start
Installation
Download the binary from the Releases page and place it in your $PATH.
Download an example DAG definition
Download this example and place it in the current directory with extension *.yaml.
Start Web UI server
Start the server with dagu server and browse to http://localhost:8080 to explore the UI.
Running the DAG
Then you can start the example DAG from the Web UI.
Usage
dagu start [--params=<params>] <file>- run a DAGdagu status <file>- display the current status of the DAGdagu retry --req=<request-id> <file>- retry the failed/canceled DAGdagu stop <file>- stop a DAG execution by sending a TERM signaldagu dry [--params=<params>] <file>- dry-run a DAGdagu server- start a web server for web UI
Use cases
- ETL Pipeline
- Machine Learning model training
- Automated generation of reports
- Backups and other DevOps tasks
- Visualizing existing workflows
Features
- Simple command interface (See Usage)
- Simple configuration YAML format (See Simple example)
- Web UI to visualize, manage DAGs and watch logs
- Parameterization
- Conditions
- Automatic retry
- Cancellation
- Retry
- Parallelism limits
- Environment variables
- Repeat
- Basic Authentication
- E-mail notifications
- REST API interface
- onExit / onSuccess / onFailure / onCancel handlers
- Automatic history cleaning
User interface
-
DAGs: Overview of all DAGs in your environment.
-
Detail: Realtime status of the DAG.
-
Timeline: Timeline of each step in the DAG.
-
History: History of the execution of the DAG.
DAG definition
Minimal
A minimal DAG definition is as simple as:
name: minimal configuration # DAG's name
steps: # Steps inside the DAG
- name: step 1 # Step's name (should be unique within the file)
command: python main_1.py # Command and arguments to execute
- name: step 2
command: python main_2.py
depends:
- step 1 # [optional] Name of the step to depend on
Using environment variables
Environment variables can be defined and used throughout the file using env field.
name: example
env:
SOME_DIR: ${HOME}/batch
steps:
- name: some task in some dir
dir: ${SOME_DIR}
command: python main.py
Using DAG parameters
Parameters can be defined and referenced throughout a file using params field. Each parameter can be referenced as $1, $2, etc. Parameters can also be command substitutions or environment variables. You can override the default values of the parameters with the --params= parameter of the start command.
name: example
params: param1 param2
steps:
- name: some task with parameters
command: python main.py $1 $2
Using command substitution
You can use command substitution in field values. A string enclosed in backquotes (`) is evaluated as a command and replaced with the result of standard output.
name: minimal configuration
env:
TODAY: "`date '+%Y%m%d'`"
steps:
- name: hello
command: "echo hello, today is ${TODAY}"
All available fields
All of the following settings are available. By combining settings, you have granular control over how the workflow runs.
name: all configuration # DAG's name
description: run a DAG # DAG's description
env: # Environment variables
LOG_DIR: ${HOME}/logs
PATH: /usr/local/bin:${PATH}
logDir: ${LOG_DIR} # Log directory to write standard output
histRetentionDays: 3 # Execution history retention days (not for log files)
delaySec: 1 # Interval seconds between steps
maxActiveRuns: 1 # Max parallel number of running step
params: param1 param2 # Default parameters for the DAG that can be referred to by $1, $2, and so on
preconditions: # Precondisions for whether the DAG is allowed to run
- condition: "`echo 1`" # Command or variables to evaluate
expected: "1" # Expected value for the condition
mailOn:
failure: true # Send a mail when the DAG failed
success: true # Send a mail when the DAG finished
MaxCleanUpTimeSec: 300 # The maximum amount of time to wait after sending a TERM signal to running steps before killing them
handlerOn: # Handler on Success, Failure, Cancel, Exit
success:
command: "echo succeed" # Command to execute when the DAG execution succeed
failure:
command: "echo failed" # Command to execute when the DAG execution failed
cancel:
command: "echo canceled" # Command to execute when the DAG execution canceled
exit:
command: "echo finished" # Command to execute when the DAG execution finished
steps:
- name: som task # Step's name
description: some task # Step's description
dir: ${HOME}/logs # Working directory
command: python main.py $1 # Command and parameters
mailOn:
failure: true # Send a mail when the step failed
success: true # Send a mail when the step finished
continueOn:
failed: true # Continue to the next regardless of the step failed or not
skipped: true # Continue to the next regardless the preconditions are met or not
retryPolicy: # Retry policy for the step
limit: 2 # Retry up to 2 times when the step failed
repeatPolicy: # Repeat policy for the step
repeat: true # Boolean whether to repeat this step
intervalSec: 60 # Interval time to repeat the step in seconds
preconditions: # Precondisions for whether the step is allowed to run
- condition: "`echo 1`" # Command or variables to evaluate
expected: "1" # Expected Value for the condition
The global configuration file ~/.dagu/config.yaml is useful to gather common settings, such as the directory to write log files.
Examples
To check all examples, visit this page.
- Sample 1
name: example DAG
steps:
- name: "1"
command: echo hello world
- name: "2"
command: sleep 10
depends:
- "1"
- name: "3"
command: echo done!
depends:
- "2"
- Sample 2
name: example DAG
env:
LOG_DIR: ${HOME}/logs
logDir: ${LOG_DIR}
params: foo bar
steps:
- name: "check precondition"
command: echo start
preconditions:
- condition: "`echo $1`"
expected: foo
- name: "print foo"
command: echo $1
depends:
- "check precondition"
- name: "print bar"
command: echo $2
depends:
- "print foo"
- name: "failure and continue"
command: "false"
continueOn:
failure: true
depends:
- "print bar"
- name: "print done"
command: echo done!
depends:
- "failure and continue"
handlerOn:
exit:
command: echo finished!
success:
command: echo success!
failure:
command: echo failed!
cancel:
command: echo canceled!
- Complex example
name: complex DAG
steps:
- name: "Initialize"
command: "sleep 2"
- name: "Copy TAB_1"
description: "Extract data from TAB_1 to TAB_2"
command: "sleep 2"
depends:
- "Initialize"
- name: "Update TAB_2"
description: "Update TAB_2"
command: "sleep 2"
depends:
- Copy TAB_1
- name: Validate TAB_2
command: "sleep 2"
depends:
- "Update TAB_2"
- name: "Load TAB_3"
description: "Read data from files"
command: "sleep 2"
depends:
- Initialize
- name: "Update TAB_3"
command: "sleep 2"
depends:
- "Load TAB_3"
- name: Merge
command: "sleep 2"
depends:
- Update TAB_3
- Validate TAB_2
- Validate File
- name: "Check File"
command: "sleep 2"
- name: "Copy File"
command: "sleep 2"
depends:
- Check File
- name: "Validate File"
command: "sleep 2"
depends:
- Copy File
- name: Calc Result
command: "sleep 2"
depends:
- Merge
- name: "Report"
command: "sleep 2"
depends:
- Calc Result
- name: Reconcile
command: "sleep 2"
depends:
- Calc Result
- name: "Cleaning"
command: "sleep 2"
depends:
- Reconcile
Admin configurations
Environment variables
DAGU__DATA- path to directory for internal use by dagu (default :~/.dagu/data)DAGU__LOGS- path to directory for logging (default :~/.dagu/logs)
Web UI configuration
Please create ~/.dagu/admin.yaml.
host: <hostname for web UI address> # default value is 127.0.0.1
port: <port number for web UI address> # default value is 8080
dags: <the location of DAG configuration files> # default value is current working directory
command: <Absolute path to the dagu binary> # [optional] required if the dagu command not in $PATH
isBasicAuth: <true|false> # [optional] basic auth config
basicAuthUsername: <username for basic auth of web UI> # [optional] basic auth config
basicAuthPassword: <password for basic auth of web UI> # [optional] basic auth config
Global DAG configuration
Please create ~/.dagu/config.yaml. All settings can be overridden by individual DAG configurations.
Creating a global configuration is a convenient way to organize common settings.
logDir: <path-to-write-log> # log directory to write standard output
histRetentionDays: 3 # history retention days
smtp: # [optional] mail server configurations to send notifications
host: <smtp server host>
port: <stmp server port>
errorMail: # [optional] mail configurations for error-level
from: <from address>
to: <to address>
prefix: <prefix of mail subject>
infoMail:
from: <from address> # [optional] mail configurations for info-level
to: <to address>
prefix: <prefix of mail subject>
Architecture
FAQ
How to contribute?
Feel free to contribute in any way you want. Share ideas, submit issues, and create pull requests. You can start by improving this README.md or suggesting new features Thank you!
Where is the history data stored?
dagu's DAG execution history data is stored in plain JSON files in the path of the DAGU__DATA environment variable with extension *.dat. The default location is $HOME/.dagu/data.
Where is the log files stored?
Log files are stored in the path of the DAGU__LOGS environment variable. The default location is $HOME/.dagu/logs. You can override this setting by logDir option in a YAML file.
How long will the history data be stored?
The default retention period for execution history is 7 days. This setting can be changed with histRetentionDays option in a YAML file.
Is it possible to retry a DAG from a specific step?
You can change the status of any task to a failed status. Then, when the job is retried, the tasks after the failed node will be executed.
Does it have a scheduler function?
No, there is no scheduler functionality so far. It is intended to be used with cron.
GoDoc
https://pkg.go.dev/github.com/yohamta/dagu
License
This project is licensed under the GNU GPLv3 - see the LICENSE.md file for details









