PUT as POST for Django.
DJProcess provides an environment for running python code within your own data-center in a very configurable and secure manner. Plus: it comes with automatic documentation and service discovery. Furthermore you can even write code executable code and build complex business processes from your browser.
You can install it as a standalone solution, or you can add it to your existing Django Projects.
The official docker image ships with some predefined tasks
docker run toast38coza/djprocess
Inside the container, the following locations are relevant:
Tasks:
/code/djprocess/tasks/core/
** # A collection of core tasks provide by default/code/djprocess/tasks/custom/
** # put your custom tasks here and reference them via the pathValidations
/code/djprocess/validation/core/
** # A collection of core tasks provide by default/code/djprocess/validation/custom/
** # put your custom tasks here and reference them via the pathConfiguration:
All config variables (e.g.: Auth tokens etc) should be provided as environment variables.
Docs are at:
Tasks are atomic pieces of code (functions really). Tasks should do only one thing.
Creating a task:
Run: python manage.py create_task {module_name} {task_name}
. e.g.:
> python manage.py create_task foo bar
* Created: ./process/tasks/foo/__init__.py
* Created: ./process/tasks/foo/bar.py
* Created: ./process/tasks/foo/test_bar.py
In order to expose your task via the API, you will need to add it to process/registry.py
Now you will see your task in the registry endpoint at: /docs/registry/tasks/
Processes combine a number of tasks in a well defined way to provide useful functionality.
Processes are yml
files, and borrow a lot from Ansible in terms of how they are structured
Processes are stored in: process/processes/
.
A simple example process
---
name: HelloWorld
description: Prints hello world
payload: []
tasks:
- task: io.say_hello
A complete example process
---
name: SignupRequest
description: ...
payload:
- key: username
type: string
required: true
default: none
- key: password
type: string
required: true
validate:
- "validation.min_length:8"
# validations will receive the payload as the first argument
validations:
- validate_not_exists
tasks:
- task: account.create_user
args:
username: payload.username
password: payload.password
# register will add the response of the task to the state of
# the process. e.g.: the below will be accessible on: `state.user`
register: user
# same as tasks but are run in the background:
# meaning:
# 1: they don't block
# 2: if they fail, they do not fail the process
tasks_async:
- task: slack.send_notification
args:
message: "New user: {{state.user}}"
- task: account.send_welcome_email
args:
user: state.user
# sheduled tasks run at a specified time in the future
tasks_scheduled:
- task: account.send_follow_up_email
args:
user: state.user
schedule:
time: 5
period: days # one of: mins, hours, days
schedule: after # or before
object: state.user
field: signup_date
Process:
**POST /:process_id Create a process instance (e.g.: POST /hello-world
)
GET /: List processess
Documentation
DJProcess builds documentation for you as you go.