Skip to content

Commit

Permalink
rename Programs to Tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Nov 4, 2023
1 parent 6c0780e commit d5a3d7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<style>
body {
background-color: #f2f2f2;
}
</style>

# Meproc


Expand Down
2 changes: 1 addition & 1 deletion http.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

while (1) {
data = mq.recv('http', 1000);
!(sys.is_nil(data)) && Programs[data] && --(Programs[data]['running']);
!(sys.is_nil(data)) && Tasks[data] && --(Tasks[data]['running']);

cron_job_process();

Expand Down
34 changes: 17 additions & 17 deletions proc.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
S = Import('sys');
Str = Import('str');

Programs = [];
Tasks = [];
Delta = 0;

Proc {
Expand Down Expand Up @@ -80,7 +80,7 @@
@list() {
return J.encode(['code': 200, 'msg': 'OK', 'data': [
'running': S.exec(),
'tasks': Programs,
'tasks': Tasks,
]]);
}

Expand Down Expand Up @@ -108,15 +108,15 @@
return J.encode(['code': 400, 'msg': 'Invalid cron format']);
} fi
} fi
if (S.has(Programs, body['name']) && !(S.is_nil(Programs[body['name']]))) {
if (S.has(Tasks, body['name']) && !(S.is_nil(Tasks[body['name']]))) {
R['code'] = 403;
return J.encode(['code': 403, 'msg': 'Program exists, please stop it at first']);
} fi
if (!(S.has(body, 'cron')) && !(Start(body))) {
R['code'] = 400;
return J.encode(['code': 400, 'msg': 'Start failed']);
} fi
Programs[body['name']] = body;
Tasks[body['name']] = body;
return J.encode(['code': 200, 'msg': 'OK']);
}

Expand All @@ -127,12 +127,12 @@
return J.encode(['code': 400, 'msg': 'name is required']);
} fi
name = args['name'];
if (!(S.has(Programs, name)) || S.is_nil(Programs[name])) {
if (!(S.has(Tasks, name)) || S.is_nil(Tasks[name])) {
R['code'] = 403;
return J.encode(['code': 403, 'msg': 'Program not exists, please start it at first']);
} fi
Stop(name);
Programs[name] = nil;
Tasks[name] = nil;
return J.encode(['code': 200, 'msg': 'OK']);
}

Expand All @@ -143,12 +143,12 @@
return J.encode(['code': 400, 'msg': 'name is required']);
} fi
name = args['name'];
if (!(S.has(Programs, name)) || S.is_nil(Programs[name])) {
if (!(S.has(Tasks, name)) || S.is_nil(Tasks[name])) {
R['code'] = 403;
return J.encode(['code': 403, 'msg': 'Program not exists, please start it at first']);
} fi
Stop(name);
if (!(Start(Programs[name]))) {
if (!(Start(Tasks[name]))) {
R['code'] = 400;
return J.encode(['code': 400, 'msg': 'Start failed']);
} fi
Expand Down Expand Up @@ -204,7 +204,7 @@
}

@Stop(name) {
prog = Programs[name];
prog = Tasks[name];
if (Is_dep_running(prog))
return;
fi
Expand Down Expand Up @@ -259,18 +259,18 @@
n = S.size(list);
for (i = 0; i < n; ++i) {
name = Str.slice(list[i]['alias'], ':')[0];
if (!(S.has(Programs, name)) || !(Programs[name])) {
Log('error', "Task [" + name + "] is running but not in Programs");
if (!(S.has(Tasks, name)) || !(Tasks[name])) {
Log('error', "Task [" + name + "] is running but not in Tasks");
continue;
} fi
ret[name] = Programs[name];
ret[name] = Tasks[name];
}
return ret;
}

@Is_dep_running(prog) {
tasks = Get_running_tasks();
deps = Fetch_deps(prog, Programs);
deps = Fetch_deps(prog, Tasks);

n = S.size(deps);
for (i = 0; i < n; ++i) {
Expand All @@ -287,9 +287,9 @@
'run': [],
'all': [],
];
n = S.size(Programs);
n = S.size(Tasks);
for (i = 0; i < n; ++i) {
prog = Programs[i];
prog = Tasks[i];
if (prog && prog['run_flag']) {
tasks['all'][prog['name']] = prog;
} fi
Expand All @@ -313,9 +313,9 @@

running_tasks = Get_running_tasks();
now = S.time() / 60 * 60;
n = S.size(Programs);
n = S.size(Tasks);
for (i = 0; i < n; ++i) {
prog = Programs[i];
prog = Tasks[i];
if (prog && S.has(prog, 'cron') && (!(prog['run_flag'])) && !(S.has(running_tasks, prog['name'])) && (now - prog['last_time']) >= 60) {
next = S.cron(prog['cron'], now);
if (next < now + Delta + 16)
Expand Down

0 comments on commit d5a3d7d

Please sign in to comment.