Skip to content

orn0t/celery-tm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

Get latest sources from GitHub

git clone git://github.com/orn0t/celery-tm.git

Install project dependencies

cd celety-tm

pip install -r requirements.txt

Install and run message queue for Celery - Redis or RabbitMQ

If you are using Centos7:

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

sudo rpm -ivh epel-release-7-5.noarch.rpm

sudo yum -y updates
sudo yum install redis -y

sudo systemctl start redis.service

Or even on MacOS:

brew install redis

# starting on system load, not necessary:  
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Configuration

Check settings.py for parameters you need:

# Web API configuration
CELERY_TM_API_HOST = '127.0.0.1'
CELERY_TM_API_PORT = 5000

# Task schedule configuration
CELERY_TM_BROKER = 'redis://localhost:6379/0'
CELERY_TM_TIMEZONE = 'Europe/Kiev'

Running application

python app.py

celery -A worker worker 

celery -A beat beat

Using REST API for task management

Adding scheduled recurring task using cron-like syntax

POST /api/v1.0/schedule
data: {
  "function": "module.function_to_run",
  "schedule": "1/4 * * * *",
  "args": [1, 2, "other_argument"]
}

Result:

Status: 201 CREATED
{
  "function": "time.time",
  "schedule": "1 * * * *",
  "id": 2,
  "created": "Wed, 15 Mar 2017 14:06:21 -0000"
}

Adding new task that runs immediately and only once

POST /api/v1.0/schedule
data: {
  "function": "module.function_to_run",
  "schedule": "now"
}

Adding scheduled recurring task with simple fixed interval in seconds

POST /api/v1.0/schedule
data: {
  "function": "module.function_to_run",
  "schedule": "3000"
}

Removing task

DELETE /api/v1.0/schedule
data: {
  "id": 1
}

Result:

Status: 204

List all tasks

GET /api/v1.0/schedule

Result:

Status: 200
[
  {
    "function": "time.time",
    "schedule": "1 * * * *",
    "id": 1,
    "created": "Wed, 15 Mar 2017 16:44:07 -0000"
  }, 
  
  ...
   
]

Get task by id

GET /api/v1.0/schedule?id=2

Result:

Status: 200
[
  {
    "function": "time.time",
    "schedule": "1 * * * *",
    "id": 2,
    "created": "Wed, 15 Mar 2017 16:44:07 -0000"
  }
]

Get only recurring tasks

GET /api/v1.0/schedule?recurring=1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages