https://github.com/rosbit/delay-tasks
a delayed tasks implementation
https://github.com/rosbit/delay-tasks
delayed-task golang
Last synced: 3 days ago
JSON representation
a delayed tasks implementation
- Host: GitHub
- URL: https://github.com/rosbit/delay-tasks
- Owner: rosbit
- Created: 2022-01-13T10:21:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-14T01:25:09.000Z (over 4 years ago)
- Last Synced: 2025-01-16T00:24:47.649Z (over 1 year ago)
- Topics: delayed-task, golang
- Language: Go
- Homepage:
- Size: 89.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# delay-tasks
An implementation of delayed tasks.

## Usage
```bash
$ git clone https://github.com/rosbit/delay-tasks
$ cd delay-tasks
$ make
```
An executable `delay-tasks` will be generated. Run it like the following:
```bash
$ CONF_FILE=./sample.conf.json ./delay-tasks
```
## API
### 1. Register category handler
- POST /handler/:cate
- Body:
```json
{"handler": "a http url"}
```
- Response
```json
{
"code": 200,
"msg": "OK"
}
```
- A handler must be implemented as an endpoint satisfy the following:
- method: POST
- BODY: a JSON, see params detail in Create/Update task.
```json
{
"cate": "task category",
"key": uint64, // task key in the category
"params": JSON, // params when adding task
"inAdvance": false|true // whether the task is run in advance.
}
```
### 2. Create/Update a delayed task in a category
- POST /task/:cate
- Body:
```json
{
"timestamp": in-seconds,
"key": uint64,
"params": {anything},
"handler": "using caterory handler if it is blank"
}
```
- Response
```json
{
"code": 200,
"msg": "OK"
}
```
### 3. Remove a delayed task in a category
- DELETE /task/:cate
- Body:
```json
{
"timestamp": in-seconds,
"key": uint64,
"exec": true|false // executing task before being removed if true.
}
```
- Response
```json
{
"code": 200,
"msg": "OK"
}
```
### 4. Get task
- GET /task/:cate/:key[?timestamp=xxx]
- Response
```json
{
"code": 200,
"msg": "OK",
"result": {
"timeToRun": xxxx,
"params": {JSON},
"handler": "http://handler"
}
}
```
### 5. List tasks
- GET /tasks
- Result will be dumped as Response.