Skip to content

Commit

Permalink
refactor(proc): modify the HTTP methods for start and restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Nov 14, 2023
1 parent e1272ce commit cea3b33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ The default IP is `127.0.0.1` and port is `8606`.
Here is a simple example.

```bash
curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep1", "cmd": "sleep 5", "type": "once", "replica": 2, "user": "guest"}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep1", "cmd": "sleep 5", "type": "once", "replica": 2, "user": "guest"}'
```

Using a PUT HTTP request to start up a new process.
Using a POST HTTP request to start up a new process.

`name` is the task name. One task is a group of same processes. In this example, we will start up two process to run `sleep 5`.

Expand All @@ -70,7 +70,7 @@ Using a PUT HTTP request to start up a new process.
Let's take a look at another example.

```bash
curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep2", "cmd": "sleep 5", "type": "once", "replica": 2, "deps": ["sleep1"]}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep2", "cmd": "sleep 5", "type": "once", "replica": 2, "deps": ["sleep1"]}'
```

`deps` indicates the list of task names that this task depends on.
Expand All @@ -82,7 +82,7 @@ The meaning of "dependency" is that when a task is going to be executed, if it f
A cron job example.

```bash
curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep2", "cmd": "sleep 5", "type": "cron", "cron": "* * * * *", "replica": 2}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep2", "cmd": "sleep 5", "type": "cron", "cron": "* * * * *", "replica": 2}'
```

This task will be executed every minute.
Expand All @@ -104,7 +104,7 @@ curl -v -XDELETE http://127.1:8606/proc?name=sleep1
Let's restart task `sleep2`.

```bash
curl -v -XPOST http://127.1:8606/proc?name=sleep2
curl -v -XPUT http://127.1:8606/proc?name=sleep2
```

Restart will stop this task and start it again. And restart is only working on the tasks those are not stopped by `curl -v -XDELETE http://127.1:8606/proc?name=<proc_name>`.
Expand Down Expand Up @@ -150,21 +150,21 @@ You can find Meproc's log files and corresponding task process output log files
We start up Meproc, and run the commands that given below:

```bash
curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep1", "cmd": "sleep 5", "type": "once", "replica": 2}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep1", "cmd": "sleep 5", "type": "once", "replica": 2}'

curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep2", "cmd": "sleep 5", "type": "once", "replica": 2, "deps": ["sleep1"]}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep2", "cmd": "sleep 5", "type": "once", "replica": 2, "deps": ["sleep1"]}'

curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep3", "cmd": "sleep 5", "type": "once", "replica": 2, "deps": ["sleep1", "sleep2"]}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep3", "cmd": "sleep 5", "type": "once", "replica": 2, "deps": ["sleep1", "sleep2"]}'

curl -v http://127.1:8606/proc

curl -v -XDELETE http://127.1:8606/proc?name=sleep1

curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep1", "cmd": "sleep 5", "type": "once", "replica": 2}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep1", "cmd": "sleep 5", "type": "once", "replica": 2}'

curl -v -XPOST http://127.1:8606/proc?name=sleep1
curl -v -XPUT http://127.1:8606/proc?name=sleep1

curl -v -XPUT http://127.1:8606/proc -d '{"name": "sleep4", "cmd": "sleep 5", "type": "cron", "cron": "* * * * *", "replica": 2}'
curl -v -XPOST http://127.1:8606/proc -d '{"name": "sleep4", "cmd": "sleep 5", "type": "cron", "cron": "* * * * *", "replica": 2}'
```

We will see the output of Meproc like:
Expand Down
2 changes: 1 addition & 1 deletion meproc.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return;
} fi

Log('info', "Meproc v1.0.0. Listen on: " + Conf['ip'] + ':' + Conf['port']);
Log('info', "Meproc v1.0. Listen on: " + Conf['ip'] + ':' + Conf['port']);

Eval('@/http.m');

Expand Down
4 changes: 2 additions & 2 deletions proc.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
if (method == 'GET') {
return this.list();
} else if (method == 'POST') {
return this.restart();
} else if (method == 'PUT') {
return this.start();
} else if (method == 'PUT') {
return this.restart();
} else if (method == 'DELETE') {
return this.stop();
} fi
Expand Down

0 comments on commit cea3b33

Please sign in to comment.