@goodandready/dsh-cron 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api-helpers.js +22 -0
- package/lib/api.js +6 -0
- package/lib/client.js +554 -264
- package/lib/routes.js +21 -0
- package/lib/timeline.js +230 -0
- package/package.json +1 -1
package/lib/api-helpers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { calculate24hTimeline } from './timeline.js';
|
|
1
2
|
import { previewSchedule } from './scheduler.js';
|
|
2
3
|
import { sendJson, readBody, rejectCrossOrigin } from './http-utils.js';
|
|
3
4
|
|
|
@@ -76,3 +77,24 @@ export async function handleDryRunTask({ store, scheduler, req, res, id }) {
|
|
|
76
77
|
sendJson(res, 500, { ok: false, error: err.message });
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
|
|
81
|
+
export async function handleScheduleTimeline({ req, res, url, store, scheduler, apiToken: explicitToken }) {
|
|
82
|
+
const apiToken = explicitToken || store?.getSettings?.()?.apiToken;
|
|
83
|
+
if (rejectCrossOrigin(req, res, { apiToken })) return;
|
|
84
|
+
|
|
85
|
+
if (req.method !== 'GET') {
|
|
86
|
+
sendJson(res, 405, NOT_ALLOWED);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const hours = parseInt(url.searchParams.get('hours') || '24', 10);
|
|
91
|
+
const tasks = typeof store?.list === 'function' ? store.list() : [];
|
|
92
|
+
const maxConcurrent = store?.getSettings?.()?.maxConcurrent || 3;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const timeline = calculate24hTimeline({ tasks, maxConcurrent, hoursCount: hours });
|
|
96
|
+
sendJson(res, 200, { ok: true, timeline });
|
|
97
|
+
} catch (err) {
|
|
98
|
+
sendJson(res, 500, { ok: false, error: err.message });
|
|
99
|
+
}
|
|
100
|
+
}
|
package/lib/api.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
handleHeartbeatPing,
|
|
35
35
|
handleSchedulePreview,
|
|
36
36
|
handleDryRunTask,
|
|
37
|
+
handleScheduleTimeline,
|
|
37
38
|
} from './api-helpers.js';
|
|
38
39
|
|
|
39
40
|
export {
|
|
@@ -44,6 +45,7 @@ export {
|
|
|
44
45
|
handleHeartbeatPing,
|
|
45
46
|
handleSchedulePreview,
|
|
46
47
|
handleDryRunTask,
|
|
48
|
+
handleScheduleTimeline,
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
const NOT_FOUND = { ok: false, error: 'Task not found' };
|
|
@@ -91,6 +93,10 @@ export function createCronApiHandler(store, scheduler, collection) {
|
|
|
91
93
|
await handleSchedulePreview({ req, res, url, store });
|
|
92
94
|
return;
|
|
93
95
|
}
|
|
96
|
+
if (scope === 'schedule' && id === 'timeline-24h') {
|
|
97
|
+
await handleScheduleTimeline({ req, res, url, store, scheduler });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
94
100
|
|
|
95
101
|
if (!id) {
|
|
96
102
|
await handleTaskCollection({ store, scheduler, collection, req, res, url, scope, apiToken });
|