feat: add async suffix eslint rule (#485)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { EVERY_MINUTE } from "../lib/cron-job/constants";
|
||||
import { createCronJob } from "../lib/cron-job/creator";
|
||||
import { queueWorker } from "../lib/queue/worker";
|
||||
import { queueWorkerAsync } from "../lib/queue/worker";
|
||||
|
||||
// This job processes queues, it runs every minute.
|
||||
export const queuesJob = createCronJob(EVERY_MINUTE).withCallback(async () => {
|
||||
await queueWorker();
|
||||
await queueWorkerAsync();
|
||||
});
|
||||
|
||||
@@ -39,7 +39,7 @@ export const createQueueClient = <TQueues extends Queues>(queues: TQueues) => {
|
||||
const queue = queueRegistry.get(name);
|
||||
if (!queue) return;
|
||||
|
||||
await queueChannel.add({
|
||||
await queueChannel.addAsync({
|
||||
name,
|
||||
data,
|
||||
executionDate:
|
||||
|
||||
@@ -6,15 +6,15 @@ import { queueRegistry } from "~/queues";
|
||||
* This function reads all the queue executions that are due and processes them.
|
||||
* Those executions are stored in the redis queue channel.
|
||||
*/
|
||||
export const queueWorker = async () => {
|
||||
export const queueWorkerAsync = async () => {
|
||||
const now = new Date();
|
||||
const executions = await queueChannel.filter((item) => {
|
||||
const executions = await queueChannel.filterAsync((item) => {
|
||||
return item.executionDate < now;
|
||||
});
|
||||
for (const execution of executions) {
|
||||
const queue = queueRegistry.get(execution.name);
|
||||
if (!queue) continue;
|
||||
await queue.callback(execution.data);
|
||||
await queueChannel.markAsDone(execution._id);
|
||||
await queueChannel.markAsDoneAsync(execution._id);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user