mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: add task.getDelay() method
This commit is contained in:
1 parent
775605f812
commit
5bbce72a68
6 files changed
+17
-4
No files matched your search
@@ -48,6 +48,13 @@ class TaskModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
static async getDelay(query?: FilterQuery<Task>) {
|
||||
const now = new Date();
|
||||
const [res] = await coll.find(query).sort({ executeAfter: 1 }).limit(1).toArray();
|
||||
if (res) return [Math.max(0, now.getTime() - res.executeAfter.getTime()), res.executeAfter];
|
||||
return [0, now];
|
||||
}
|
||||
|
||||
static async consume(query: any, cb: Function) {
|
||||
let isRunning = false;
|
||||
const interval = setInterval(async () => {
|
||||
|
||||
Reference in new issue
Block a user