Skip to content

Node.js based forum software built for the modern web

add active flag to jobs

Barış Soner Uşaklı2187f160a94f
diff --git a/public/language/en-GB/admin/advanced/jobs.json b/public/language/en-GB/admin/advanced/jobs.json
index 764b7d2b9f..896b07930a 100644
--- a/public/language/en-GB/admin/advanced/jobs.json
+++ b/public/language/en-GB/admin/advanced/jobs.json
@@ -4,5 +4,6 @@
"schedule": "Schedule",
"next-run": "Next Run",
"last-duration": "Last Duration",
- "running": "Running"
+ "running": "Running",
+ "active": "Active"
}
\ No newline at end of file
diff --git a/public/openapi/read/admin/advanced/jobs.yaml b/public/openapi/read/admin/advanced/jobs.yaml
index 5e423ea8e5..4a85013493 100644
--- a/public/openapi/read/admin/advanced/jobs.yaml
+++ b/public/openapi/read/admin/advanced/jobs.yaml
@@ -32,4 +32,6 @@ get:
type: string
running:
type: boolean
+ active:
+ type: boolean
- $ref: ../../../components/schemas/CommonProps.yaml#/CommonProps
\ No newline at end of file
diff --git a/src/cron.js b/src/cron.js
index 2f59adf1af..02f75f2aba 100644
--- a/src/cron.js
+++ b/src/cron.js
@@ -10,10 +10,9 @@ const utils = require('./utils');
const jobs = Object.create(null);
-exports.deleteJobs = async function () {
+exports.markJobsInactive = async function () {
const jobs = await db.getSortedSetRange('cronJobs', 0, -1);
- await db.deleteAll(jobs.map(name => `cronJob:${name}`));
- await db.delete('cronJobs');
+ await db.setObject(jobs.map(name => `cronJob:${name}`), { active: 0 });
};
exports.addJob = async function (options) {
@@ -67,6 +66,7 @@ exports.addJob = async function (options) {
cronTimeHuman: cronstrue.toString(cronTime),
nextRun: job.nextDate().toMillis(),
running: runOnInit ? 1 : 0,
+ active: 1,
});
winston.verbose(`[cron/jobs] Registered job: ${name} (${cronTime})`);
return job;
@@ -77,6 +77,7 @@ exports.getJobs = async function () {
const jobs = await db.getObjects(jobNames.map(name => `cronJob:${name}`));
jobs.forEach((job) => {
if (job) {
+ job.active = parseInt(job.active, 10) === 1;
job.running = parseInt(job.running, 10) === 1;
job.duration = job.duration || 0;
job.durationReadable = formatDuration(job.duration);
diff --git a/src/start.js b/src/start.js
index 4e17ed2489..00a129e33f 100644
--- a/src/start.js
+++ b/src/start.js
@@ -35,7 +35,7 @@ start.start = async function () {
await sockets.init(webserver.server);
if (nconf.get('runJobs')) {
- await require('./cron').deleteJobs();
+ await require('./cron').markJobsInactive();
await require('./notifications').startJobs();
await require('./user').startJobs();
await require('./plugins').startJobs();
diff --git a/src/views/admin/advanced/jobs.tpl b/src/views/admin/advanced/jobs.tpl
index 4764f527be..8eafcce5cd 100644
--- a/src/views/admin/advanced/jobs.tpl
+++ b/src/views/admin/advanced/jobs.tpl
@@ -16,6 +16,7 @@
<th>[[admin/advanced/jobs:next-run]]</th>
<th class="text-end">[[admin/advanced/jobs:last-duration]]</th>
<th class="text-center">[[admin/advanced/jobs:running]]</th>
+ <th class="text-center">[[admin/advanced/jobs:active]]</th>
</tr>
</thead>
<tbody class="text-xs text-tabular">
@@ -25,7 +26,8 @@
<td>{./cronTimeHuman} <span class="text-secondary">({./cronTime})</span></td>
<td><span class="timeago" title="{./nextRunISO}"></span></td>
<td class="text-end">{./durationReadable}</td>
- <td class="text-center">{{{ if ./running }}}Yes{{{ else }}}No{{{ end }}}</td>
+ <td class="text-center">{{{ if ./running }}}<i class="fa-solid fa-circle text-success"></i>{{{ else }}}<i class="fa-solid fa-circle text-danger"></i>{{{ end }}}</td>
+ <td class="text-center text-sm">{{{ if ./active }}}<i class="fa-solid fa-check text-success"></i>{{{ else }}}<i class="fa-solid fa-times"></i>{{{ end }}}</td>
</tr>
{{{ end }}}
</tbody>