|
| 1 | + |
| 2 | +# Django Process |
| 3 | + |
| 4 | +Its a reusable app for execute scrits in workflows with dependecies |
| 5 | + |
| 6 | +## Usage: |
| 7 | +* pip install django-process |
| 8 | +* add 'process' to installed apps |
| 9 | +* makemigrations and migrate them |
| 10 | +* create a Process and Tasks which belong to the process. |
| 11 | +(The Job is an instance executed of the process, JobTask is an instance executed of the Task you must not create manually any of them !) |
| 12 | +* (optional) you can create dependencies of the tasks for they to run sequentially, if you don't create dependencies the tasks will start all at once |
| 13 | +* execute python manage.py run_jobs |
| 14 | + |
| 15 | + |
| 16 | +# TIPS: |
| 17 | +## execution of the process |
| 18 | +just as simple as |
| 19 | +```pycon |
| 20 | +>>> python manage.py run_jobs |
| 21 | +``` |
| 22 | + |
| 23 | +## frequency of the process |
| 24 | +The process have a crontab-like configuration for set the frequency. |
| 25 | +Lets take the attribute minute for example. You can: |
| 26 | +* use * for all minutes |
| 27 | +* specify a list of minutes 1,3,5,8,25,59 |
| 28 | +* specify a range of minutes 1-30 |
| 29 | +* combine list and ranges example 1,3,5,8,4-9 will be expanded to: 1,3,4,5,6,7,8,9 |
| 30 | +* for the moment it doesnt accept fractions using the / char |
| 31 | + |
| 32 | +you can use any of those above for the five attributes just like a crontab. |
| 33 | +##### the start job process runs each minute while the tasks manager its always online. |
| 34 | + |
| 35 | + |
| 36 | +## render process or job object as an workflow diagram |
| 37 | +in your html code you can render a Process as an image workflow |
| 38 | +* {% load process_diagram %} in your html for use the diagram templatetag |
| 39 | +* {% include "process/dj-process.html" %} in your html for include the CSS and JS |
| 40 | +* {{ object|diagram }} to render the object |
| 41 | +```html |
| 42 | +{% load process_diagram %} |
| 43 | +<!DOCTYPE html> |
| 44 | +<html lang="en"> |
| 45 | +<head> |
| 46 | + {% include "process/dj-process.html" %} |
| 47 | + <meta charset="UTF-8"> |
| 48 | + <title>Title</title> |
| 49 | +</head> |
| 50 | + <body> |
| 51 | + {{ object|diagram }} |
| 52 | + </body> |
| 53 | +</html> |
| 54 | +``` |
| 55 | +this will return an output like this: |
| 56 | +{ img not loaded yet ! } |
| 57 | + |
| 58 | + |
| 59 | +## placing a task in an workflow diagram |
| 60 | +Task objects have two attributes: level & offset you can place a task in a workflow diagram using those attributes |
| 61 | +levels are vertical placement while offset are horizontal placements |
| 62 | +* level: the value for level starts on 0 you can create as many levels as you want in workflow diagram |
| 63 | +* offset: its a percentaje 0% will place your task in the middle 25% places to the right while -25% place the task to the left |
| 64 | + |
| 65 | + |
| 66 | +## creating a Job and its tasks |
| 67 | +The job needs a Process parent to be instanced: |
| 68 | +```pycon |
| 69 | +>>> process = Process.objects.all()[0] |
| 70 | +>>> job, tasks = Job.create(process) |
| 71 | +``` |
| 72 | +this will create the job for the process and also the tasks if the runner is online it will execute immediate |
| 73 | +all the tasks created sequentially if you have defined dependencies for them or all at once if you have not |
| 74 | + |
| 75 | + |
| 76 | +## reopen task and its childs |
| 77 | +you can reopen a task that has been executed already: |
| 78 | +```pycon |
| 79 | +>>> task = JobTask.objects.all()[0] |
| 80 | +>>> task.reopen(main=True) |
| 81 | +``` |
| 82 | +this will reopen the job task for execution again and it will set status awaiting for the childs in CASCADE |
| 83 | + |
| 84 | + |
| 85 | +## this short tutorial does not covers all the power for the app. I will be adding more examples |
| 86 | +## if you got doubts or questions don't hesitate send me a mail or create an issue im always online |
| 87 | + |
0 commit comments