To begin, we’ll set up new Go project, install ppacer, configure the ppacer
scheduler and executor within a single program, define new DAG that runs each
10 seconds, execute the program, and finally, explore the ppacer database.
Installing ppacer
Setting up scheduler and executor
Now, let’s proceed to initiate the scheduler and executor within a single
program. Start by creating a file named main.go with the following content:
In the main function, we parse Go files’ ASTs (to retrive the Task source
code, more on this later), initialize default Scheduler, setup and start an
executor in a separate goroutine, and finally, launch the scheduler’s HTTP
server to enable communication between executor(s), clients, users and the
scheduler.
At this point, we have not defined any DAGs yet, but the program should compile
and execute:
Upon running, you should see messages similar to the following:
The program will continue running indefinitely. You can terminate it for now.
Launching the program for the first time also sets up the two mentioned SQLite
databases for scheduler metadata and logs.
Defining Task and DAG
Now, let’s create our first DAG. In ppacer DAGs are directed acyclic graphs
composed of Tasks. Let’s
start by defining a Task:
Next, we’ll define a simple DAG with two tasks start and finish, both of
printTask type. You can place type definition and function either in main.go
file or any other *.go file within the same directory.
We can now add this DAG to the dag.Registry in our main function, like
so:
Just in case you don’t have goimports setup in your environment, please make
sure you added new imports after we added new DAG implementation (goimports
does it automatically):
Rebuild and rerun the program:
Every 10 seconds, you should see scheduler logs and our messages from
printTask on the console’s standard output.
You can observe the output for a while, then stop the program. This time,
databases should contain data.
Exploring scheduler database
While a frontend for ppacer is not yet available, you can directly explore the
scheduler database.