Skip to content

niki4/tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tasks

delayed tasks launch

Currently, under construction.

Command-line interface (CLI):

Built using only standard Python 3 library, only hardcore :-)

(venv)> python example_tasks.py mult --params "{'operands':[3,2,8]}"
48
(venv)> python example_tasks.py multiprint --params "{'msg':'foo','count':5}"
foo
foo
foo
foo
foo

HTTP Rest API

Built using Django and django-rest-framework.

To set solution up, run following commands (Linux):

  • Clone project
git clone https://github.com/niki4/tasks.git

Create and activate virtual environment in project directory

python3 -m venv ./venv
source venv/bin/activate

Install project requirements

pip install --upgrade pip
pip install -r requirements.txt

Set DJANGO_SECRET_KEY

export DJANGO_SECRET_KEY='blah'

Create DB and init tables

python3 manage.py migrate

In order to run CLI from Django process, we need to make sure target module with functions is executable

chmod +x example_tasks.py

Finally, run API server

python3 manage.py runserver

Now open a browser at http://127.0.0.1:8000/ and play with DRF UI.

Send request to http://127.0.0.1:8000/tasks/ endpoint with following body

{
  "task_name": "multiprint",
  "params": {"msg": "hello", "count": 2}
}

And you get a response with the task result:

{
  "result": "hello\nhello"
}

Alternatively, use curl to send requests.

Tasks requests and results are saved in DB, so you could always review them.

Stay tuned!

Releases

No releases published

Packages

No packages published

Languages