The ox_herd_example package illustrates how to get a very simple
application setup using ox_herd for job scheduling. Although you can
do many things with ox_herd, a simple way to think of it is a
pythonic replacement for the UNIX cron package.
That is, you can write simple python tasks and schedule them to run at
set intervals. The advantages of doing this with ox_herd include:
- Using python instead of cron and shell scripts.
- A nice flask web interface to your tasks.
- Ability to include that web interface as a flask blueprint in other flask projects.
- Ability to use the web interface to configure your cron schedule.
- Ability to use the web interface to see task results.
In this section, we describe how to use docker to do a simple demo of
how ox_herd can function as a pythonic cron.
To run this example, do the following:
git clone https://github.com/emin63/ox_herd_example- This will download the git repo from github.
cd ox_herd_exampledocker-compose up --build- This will build and start the docker image.
- Point your browser to
http://127.0.0.1:5000/login- Note that on windows, docker networking works differently and
you will have to do
docker-machine ipand use that IP address instead of 127.0.0.1.
- Note that on windows, docker networking works differently and
you will have to do
- Login with user
test_userand enter the password printed in the terminal where you started docker.- The
app.pyshould print a random password to the screen so that only you can see it to keep things secure.
- The
- After you succesfully login, go to
http://127.0.0.1:5000/ox_herd/show_pluginsto see the plugins which are loaded.- Notice the
example_pluginswhich is loaded by the app.py file.
- Notice the
- Click on
example_pluginsto expand it and the click onCheckWeb.- This will take you to a form to configure the plugin.
- Set the name field to
test_cwand thequeue_nametodefaultand hit theGobutton.- You have now configured this plugin to run on the given cron schedule on the default
python rqworker queue.
- You have now configured this plugin to run on the given cron schedule on the default
- If you now go to the
Show_Scheduledlink athttp://127.0.0.1:5000/ox_herd/show_plugins, you should see your plugin has been schedule. - Click on your scheduled
test_cwjob and clickLaunch Job Copy.- This shows how you can force launching of a copy of the job outside of the regular cron schedule.
- Next, click the
List Taskslink athttp://127.0.0.1:5000/ox_herd/list_tasksand you should see an entry for your task.
This example illustrates a very simple demo of how you can use
ox_herd as a job scheduler. Our docker example sets up a new
machine, installs ox_herd, and creates a simple flask app in
ox_herd_example/app.py to use the ox_herd blueprint.
Next steps:
- As one next step, you could further customize the module used in
ox_herd_example/example_plugins.pyto provide more plugins so you have more jobs to schedule. - As another next step you could build a bigger flask application
using
ox_herdto do things like download financial data, monitor your web site, do automated testing, etc.