Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Latest commit

 

History

History
executable file
·
87 lines (75 loc) · 2.67 KB

task.md

File metadata and controls

executable file
·
87 lines (75 loc) · 2.67 KB

Creating A Python Task

A task in StarThinker is a python function that can be executed by the framework given a set of JSON parameters called a recipe. It is just python, with a thin project singleton wrapper that pulls parameters from the command line or passed in, saving developers the trouble of re-coding common tasks like scheduling, authentication, and UI integration.

1. Create a new task... ( rename hello to your task ):

starthinker/task/hello/__init__.py

starthinker/task/hello/run.py

def hello(config, task):
  print(task)

2. Thats it, the python code is integrated, now create a script to pass parameters to your task:

scripts/hello.json

{
  "tasks":[
    { "hello":{
        "auth":"user",
        "say":"Hello World"
      }
    }
  ]
}

3. Add authentication.

{
  "setup":{
    "project":"",
    "auth":{
      "client":{}
      "service":{}
      "user":{}
    }
  },
  "tasks":[
    { "hello":{
        "auth":"user",
        "say":"Hello World"
      }
    }
  ]
}

4. Execute your new task.

source starthinker_assets/development.sh

If autherntication supplied in recipe:

python starthinker/tool/recipe.py hello.json --verbose

If authentication supplied on command line:

python starthinker/tool/recipe.py hello.json -u $STARTHINKER_USER -s $STARTHINKER_SERVICE -p $STARTHINKER_PROJECT --verbose

5. Continue to the recipe tutorial...

Notes

  • The @project.from_parameters decorator is StarThinker. Everything else is just python.
  • Using the util library is optional but convenient.
  • Always check starthinker/task folder for task samples.
  • Always check scripts folder for script samples.
  • New scopes for user authentication can be added at starthinker/config.py.
  • You can remove scopes if you are not planning to use the tasks requiring them.
  • The Google API helper can be extended by adding an endpoint at starthinker/util/google_api/__init__.py.
  • It is best practice to provide at least one or more reference recipes for a task.
  • When develoing a new task, the first script should be a test script.
  • Even the credentials are optional, each script is pure python parameters not tied to any Cloud Service.
  • A script may call the same task multiple times with the same or different parameters.
  • A script may call multiple tasks.
  • Each task must have a unique name.

© 2019 Google LLC - Apache License, Version 2.0