diff --git a/README.md b/README.md index 94a4338..d4446d1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/controllers/proc.m b/controllers/proc.m index af9743c..9b20c97 100644 --- a/controllers/proc.m +++ b/controllers/proc.m @@ -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,], @@ -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 } } diff --git a/coroutines/task.m b/coroutines/task.m index da68e70..6b3dca6 100644 --- a/coroutines/task.m +++ b/coroutines/task.m @@ -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;