Hello world!

Create a new directory and put a file helloworld.py with the following automation script in it.

from freyja import Step, Automation
 
 
class HelloWorld(Step):
    def execute(self):
        print("Hello world!")
 
 
if __name__ == "__main__":
    Automation(HelloWorld).run()

This automation script consists of a single step called HelloWorld, which prints 'Hello world!" to the console.

As you can see, to turn a Python class into an automation step you need to inherit from the Step base class and implement its execute() function. To run this script, simply type:

$ python helloworld.py run

You should see the following output:

2019-03-18 13:36:16,546    INFO [  freyja.log:  68]: (MainThread  ) Logging configured
2019-03-18 13:36:16,547    INFO [freyja.graph: 362]: (MainThread  ) Process: 10232
2019-03-18 13:36:16,547    INFO [freyja.graph: 489]: (MainThread  ) Instantiating Step <HelloWorld "main">
2019-03-18 13:36:16,547    INFO [freyja.graph: 217]: (MainThread  ) Step <HelloWorld ("main")> queued for execution
2019-03-18 13:36:16,547    INFO [freyja.graph: 648]: (main        ) Initiating execution for for: Step <HelloWorld ("main")>
2019-03-18 13:36:16,548    INFO [freyja.graph: 658]: (main        ) Execution started for: Step <HelloWorld ("main")>
2019-03-18 13:36:16,548    INFO [freyja.graph: 664]: (main        ) RUNNING: main
Hello world!
2019-03-18 13:36:16,548    INFO [freyja.graph: 690]: (main        ) Execution finished for: Step <HelloWorld ("main")>
2019-03-18 13:36:16,548    INFO [freyja.graph: 114]: (Executor-main) Executor done
2019-03-18 13:36:16,549    INFO [freyja.graph: 406]: (MainThread  )
-----------------------------------------------------------------------
Execution summary:
    Steps instantiated: 1
    Steps incomplete:   0
    Steps executed:     1
    Steps failed:       0
-----------------------------------------------------------------------

Congratulations! You have successfully executed your first automation script.

Asynchronous execution

The first thing to pay attention to is the different messages for step instantiation and step execution in the execution log.

This is an important concept to understand and we will come back to this quite often: with the ADK, automation steps are not instantiated and executed at the same time. When you run an ADK script, steps are first instantiated and added to a dynamically built execution graph. Execution of steps in the graph then happens asynchronously in separate Python threads, one per step.

It is this separation of step instantiation and execution that allows us to execute automation steps in parallel whenever they do not depend on each other. We will come back to step dependencies later when looking at more elaborate examples.

Automation log file

When you run the above automation example, it creates a file named automation.log inside your current directory:

$ ls
automation.log  helloworld.py

This log file contains the same log messages you saw on your screen plus additional debug messages useful for troubleshooting.