API Reference

GET /api/workers

workers清单

Example request:

GET /api/workers HTTP/1.1
Host: localhost:5555

Example response:

    HTTP/1.1 200 OK
    Content-Length: 119
    Content-Type: application/json; charset=UTF-8

    {
"celery@worker1": {
    "completed_tasks": 0,
    "concurrency": 4,
    "queues": [
        "celery"
    ],
    "running_tasks": 0,
    "status": true
},
"celery@worker2": {
    "completed_tasks": 0,
    "concurrency": 4,
    "queues": [],
    "running_tasks": 0,
    "status": false
    }
    }

如下wroker.json是自己所应用的,点击这里查看[workers.json](ApiReference/workers.json)

## POST /api/worker/shutdown/(.+)

关闭worker

Example request:

POST /api/worker/shutdown/celery@worker2 HTTP/1.1
Content-Length: 0
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 29
Content-Type: application/json; charset=UTF-8

{
"message": "Shutting down!"
}

POST /api/worker/pool/restart/(.+)

重启worker池

Example request:

POST /api/worker/pool/restart/celery@worker2 HTTP/1.1
Content-Length: 0
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 56
Content-Type: application/json; charset=UTF-8

{
"message": "Restarting 'celery@worker2' worker's pool"
}

POST /api/worker/pool/grow/(.+)

增大worker池

Example request:

POST /api/worker/pool/grow/celery@worker2?n=3 HTTP/1.1
Content-Length: 0
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 58
Content-Type: application/json; charset=UTF-8

{
"message": "Growing 'celery@worker2' worker's pool by 3"
}

Query Parameters:

n – number of pool processes to grow, default is 1

其实相当于增加进程,如增加10个进程后的清单

...
"pool": {
        "processes": [
                3303,
                3304,
                3305,
                3306,
                3307,
                3308,
                3309,
                3310,
                3311,
                3312
        ],
"max-concurrency": 10,
"timeouts": [
        0,
        0
],
....

POST /api/worker/pool/shrink/(.+)

减少worker’s pool,与上对应

Example request:

POST /api/worker/pool/shrink/celery@worker2 HTTP/1.1
Content-Length: 0
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 60
Content-Type: application/json; charset=UTF-8

{
 "message": "Shrinking 'celery@worker2' worker's pool by 1"
}

Query Parameters:

n – number of pool processes to shrink, default is 1

POST /api/worker/pool/autoscale/(.+)

自动设置worker pool进程

Example request:

POST /api/worker/pool/autoscale/celery@worker2?min=3&max=10 HTTP/1.1
Content-Length: 0
Content-Type: application/x-www-form-urlencoded;        charset=utf-8
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 66
Content-Type: application/json; charset=UTF-8

{
"message": "Autoscaling 'celery@worker2' worker (min=3, max=10)"
}

Query Parameters:

min – minimum number of pool processes
max – maximum number of pool processes

POST /api/worker/queue/add-consumer/(.+)

开始从队列消耗

Example request:

POST /api/worker/queue/add-consumer/celery@worker2?queue=sample-queue
Content-Length: 0
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 40
Content-Type: application/json; charset=UTF-8

{
        "message": "add consumer sample-queue"
}

Query Parameters:

queue – the name of a new queue

POST /api/worker/queue/cancel-consumer/(.+)

停止队列消耗

Example request:

POST /api/worker/queue/cancel-consumer/celery@worker2?queue=sample-queue
Content-Length: 0
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 52
Content-Type: application/json; charset=UTF-8

{
 "message": "no longer consuming from sample-queue"
}

Query Parameters:

queue – the name of queue

GET /api/tasks

tasks 清单

Example request:

GET /api/tasks HTTP/1.1
Host: localhost:5555
User-Agent: HTTPie/0.8.0

Example response:

    HTTP/1.1 200 OK
    Content-Length: 1109
    Content-Type: application/json; charset=UTF-8
    Etag: "b2478118015c8b825f7b88ce6b660e5449746c37"
    Server: TornadoServer/3.1.1

    {
     "e42ceb2d-8730-47b5-8b4d-8e0d2a1ef7c9": {
    "args": "[3, 4]",
    "client": null,
    "clock": 1079,
    "eta": null,
    "exception": null,
    "exchange": null,
    "expires": null,
    "failed": null,
    "kwargs": "{}",
    "name": "tasks.add",
    "received": 1398505411.107885,
    "result": "'7'",
    "retried": null,
    "retries": 0,
    "revoked": null,
    "routing_key": null,
    "runtime": 0.01610181899741292,
    "sent": null,
    "started": 1398505411.108985,
    "state": "SUCCESS",
    "succeeded": 1398505411.124802,
    "timestamp": 1398505411.124802,
    "traceback": null,
    "uuid": "e42ceb2d-8730-47b5-8b4d-8e0d2a1ef7c9"
},
"f67ea225-ae9e-42a8-90b0-5de0b24507e0": {
    "args": "[1, 2]",
    "client": null,
    "clock": 1042,
    "eta": null,
    "exception": null,
    "exchange": null,
    "expires": null,
    "failed": null,
    "kwargs": "{}",
    "name": "tasks.add",
    "received": 1398505395.327208,
    "result": "'3'",
    "retried": null,
    "retries": 0,
    "revoked": null,
    "routing_key": null,
    "runtime": 0.012884548006695695,
    "sent": null,
    "started": 1398505395.3289,
    "state": "SUCCESS",
    "succeeded": 1398505395.341089,
    "timestamp": 1398505395.341089,
    "traceback": null,
    "uuid": "f67ea225-ae9e-42a8-90b0-5de0b24507e0"
    }
    }

Query Parameters:

  • limit – maximum number of tasks
  • workername – filter task by workername
  • taskname – filter tasks by taskname
  • state – filter tasks by state

GET /api/task/types

List (seen) task types

Example request:

GET /api/task/types HTTP/1.1
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 44
Content-Type: application/json; charset=UTF-8

{
"task-types": [
        "tasks.add",
        "tasks.sleep"
]
}

GET /api/task/info/(.*)

查看一个task详情

Example request:

GET /api/task/info/91396550-c228-4111-9da4-9d88cfd5ddc6 HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, compress
Host: localhost:5555

Example response:

    HTTP/1.1 200 OK
    Content-Length: 575
    Content-Type: application/json; charset=UTF-8

    {
"args": "[2, 2]",
"client": null,
"clock": 25,
"eta": null,
"exception": null,
"exchange": null,
"expires": null,
"failed": null,
"kwargs": "{}",
"name": "tasks.add",
"received": 1400806241.970742,
"result": "'4'",
"retried": null,
"retries": null,
"revoked": null,
"routing_key": null,
"runtime": 2.0037889280356467,
"sent": null,
"started": 1400806241.972624,
"state": "SUCCESS",
"succeeded": 1400806243.975336,
"task-id": "91396550-c228-4111-9da4-9d88cfd5ddc6",
"timestamp": 1400806243.975336,
"traceback": null,
"worker": "celery@worker1"
    }

POST /api/task/async-apply/(.+)

执行一个task

Example request:

POST /api/task/async-apply/tasks.add HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 16
Content-Type: application/json; charset=utf-8
Host: localhost:5555

{
         "args": [1, 2]
}

Example response:

HTTP/1.1 200 OK
Content-Length: 71
Content-Type: application/json; charset=UTF-8
Date: Sun, 13 Apr 2014 15:55:00 GMT

{
"state": "PENDING",
"task-id": "abc300c7-2922-4069-97b6-a635cc2ac47c"
}

Query Parameters:

  • args – a list of arguments
  • kwargs – a dictionary of arguments
  • options – a dictionary of apply_async keyword arguments

POST /api/task/send-task/(.+)

通过名称来执行task

Example request:

POST /api/task/send-task/tasks.add HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 16
Content-Type: application/json; charset=utf-8
Host: localhost:5555

{
        "args": [1, 2]
}

Example response:

HTTP/1.1 200 OK
Content-Length: 71
Content-Type: application/json; charset=UTF-8

{
        "state": "SUCCESS",
"task-id": "c60be250-fe52-48df-befb-ac66174076e6"
}

Query Parameters:

  • args – a list of arguments
  • kwargs – a dictionary of arguments

GET /api/task/result/(.+)

获取一个task结果

Example request:

GET /api/task/result/c60be250-fe52-48df-befb-ac66174076e6 HTTP/1.1
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 84
Content-Type: application/json; charset=UTF-8

{
"result": 3,
"state": "SUCCESS",
"task-id": "c60be250-fe52-48df-befb-ac66174076e6"
}

POST /api/task/timeout/(.+)

Change soft and hard time limits for a task

Example request:

POST /api/task/timeout/tasks.sleep HTTP/1.1
Content-Length: 44
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:5555

soft=30&hard=100&workername=celery%40worker1

Example response:

HTTP/1.1 200 OK
Content-Length: 46
Content-Type: application/json; charset=UTF-8

{
"message": "new rate limit set successfully"
}

Query Parameters:

workername – worker name

POST /api/task/rate-limit/(.+)

Change rate limit for a task

Example request:

POST /api/task/rate-limit/tasks.sleep HTTP/1.1
Content-Length: 41
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:5555

ratelimit=200&workername=celery%40worker1

Example response:

HTTP/1.1 200 OK
Content-Length: 61
Content-Type: application/json; charset=UTF-8

{
"message": "Revoked '1480b55c-b8b2-462c-985e-24af3e9158f9'"
}

Query Parameters:

workername – worker name

POST /api/task/revoke/(.+)

Revoke a task

Example request:

POST /api/task/revoke/1480b55c-b8b2-462c-985e-24af3e9158f9?terminate=true
Content-Length: 0
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:5555

Example response:

HTTP/1.1 200 OK
Content-Length: 61
Content-Type: application/json; charset=UTF-8

{
"message": "Revoked '1480b55c-b8b2-462c-985e-24af3e9158f9'"
}

Query Parameters:

terminate – terminate the task if it is running