-
Notifications
You must be signed in to change notification settings - Fork 0
HTTP APIs
The URL for all APIs is the same.
http://ip:port/proc
For example
http://127.0.0.1:8606/proc
In the following subsection, we use the curl
command to show you the method, parameters and request body of the APIs.
curl -XPOST http://127.1:8606/proc -d '{"name": "task1", "cmd": "sleep 5", "type": "once", "replica": 2, "user": "guest", "deps": ["task0"]}'
To startup a task, you should send a POST request with a JSON body.
All fields of the JSON body are:
-
name
: the required string field that specifies the task name. -
type
the required string field that specifies the type of the task. There are three types:-
once
indicates that this task will be started and run only once. -
daemon
indicates that the processes of this task will be started and run as daemon processes. Which means each one of these processes will be started up again if it exits expectedly or unexpectedly. -
cron
indicates that this is a cron job. -
coroutine
indicates that this is a melang coroutine task.
-
-
cmd
: the required string field that specifies the melang script file path (iftype
ismelang
) or the shell command that task processes will execute. -
replica
the required integer field that specifies how many processes of this task. -
user
the optional string field that specifies the running user of the task's processes. -
group
the optional string field that specifies the running group of the task's processes. -
cron
the optional string field that specifies the cron-format expression. This field only takes effect whentype
iscron
. The default value of this field is* * * * *
. -
interval
the optional integer field that specifies the number of seconds between when the process exits and before it is started again. The default value is3
. -
deps
the optional string array that specifies all tasks on which this task depends.
curl -XPUT http://127.1:8606/proc?name=task1
We use a PUT
request to restart a task indicated by request argument name
.
If the task is running when you send this request, it will be stopped at first, and then started it up.
curl -XDELETE http://127.1:8606/proc?name=task1
We use a DELETE
request to stop a task indicated by request argument name
.
All running processes will be terminated with SIGTERM
signal.
curl -XGET http://127.1:8606/proc
This API will show you all tasks and all running processes.
The response body is a JSON, its format is:
{
"code": 200,
"msg": "OK",
"data": {
"running": [
{
"command": "sleep 5",
"pid": 4321,
"alias": "task1:0"
},
{
"command": "sleep 5",
"pid": 4322,
"alias": "task1:1"
}
],
"tasks": {
"task1": {
"name": "task1",
"cmd": "sleep 5",
"type": "once",
"replica": 2,
"user": "guest",
"deps": [
"task0"
],
"interval": 3,
"last_time": 1699958864,
"run_flag": false,
"start_time": 1699958864,
"running": 0,
"group": null
}
}
}
}
The running
field records the information of all current running processes.
The tasks
field records all tasks regardless running or not. It is an object. The key in this object is the task name, and the value is an object records the task information.