Skip to content

Commit

Permalink
feat(*): support melang task
Browse files Browse the repository at this point in the history
It will initiate a coroutine to execute the given Melang script file.
  • Loading branch information
Water-Melon committed Dec 15, 2023
1 parent f167bed commit 297c531
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ 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`.

`once` means that the processes in this task will only be executed once. And there are three values of `type` field:
`once` means that the processes in this task will only be executed once. And there are four values of `type` field:

- `once` means this task will only be executed once even if it exits unexpectedly.
- `daemon` means this task is a daemon, so if this process exits in any reason, it will be restarted.
- `cron` means this task is a cron job, it will contain a field named `cron` in task JSON.
- `user` indicates the user of the new process. Please make sure that Meproc has the permission to do this. `user` and `group` are NOT working on Windows.
- `melang` means that this task is a melang coroutine task. It will start a melang coroutine based on the provided script file path.


`user` indicates the user of the new process. Please make sure that Meproc has the permission to do this. `user` and `group` are NOT working on Windows.



Expand Down
5 changes: 4 additions & 1 deletion controllers/proc.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'body': [
['field': 'name', 'type': 'string', 'required': true],
['field': 'cmd', 'type': 'string', 'required': true],
['field': 'type', 'type': 'string', 'required': true, 'in': ['once', 'daemon', 'cron']],
['field': 'type', 'type': 'string', 'required': true, 'in': ['once', 'daemon', 'cron', 'melang']],
['field': 'cron', 'type': 'string', 'required': false, 'default': '* * * * *'],
['field': 'user', 'type': 'string', 'required': false,],
['field': 'group', 'type': 'string', 'required': false,],
Expand Down Expand Up @@ -256,6 +256,9 @@
Log('info', 'Task ' + prog['name'] + ' stopped');
for (i = 0; i < n; ++i) {
Kill(name + ':' + i);
if (type == 'melang')
Kill(type + ':' + name + ':' + i);
fi
}
}

Expand Down
15 changes: 14 additions & 1 deletion coroutines/task.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@

process_start_event = data;

s.exec(cmd, -1, data['pid'], conf['user'], conf['group'], alias);
if (type != 'melang') {
s.exec(cmd, -1, data['pid'], conf['user'], conf['group'], alias);
} else {
name = type + ':' + alias;
Eval(cmd, EVAL_DATA, false, name);

while (true) {
list = Eval();
if (!s.has(list, name))
break;
fi
s.msleep(1000);
}
}

process_stop_event = data;

Expand Down

0 comments on commit 297c531

Please sign in to comment.