Skip to content

Commit

Permalink
chore: fix ESLint errors (#1949)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey authored Feb 14, 2022
1 parent 898379e commit 411134f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
69 changes: 36 additions & 33 deletions examples/bullmq-task-queue/app/queues/notifier.server.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
import {Queue, Worker, QueueScheduler} from 'bullmq';
import { redis } from '~/utils/redis.server';
import { Queue, Worker, QueueScheduler } from "bullmq";

import { redis } from "~/utils/redis.server";

declare global {
var __notifierQueue: Queue | undefined;
var __notifierWorker: Worker | undefined;
var __notifierScheduler: QueueScheduler | undefined;
var __notifierQueue: Queue | undefined;
var __notifierWorker: Worker | undefined;
var __notifierScheduler: QueueScheduler | undefined;
}

let queue: Queue;
let worker: Worker;
let scheduler: QueueScheduler;

const QUEUE_NAME = 'notifier';
const QUEUE_NAME = "notifier";

type QueueData = {
emailAddress: string;
}
emailAddress: string;
};

// Bullmq queues are the storage container managing jobs.
queue = global.__notifierQueue || (global.__notifierQueue = new Queue<QueueData>(QUEUE_NAME, {
connection: redis,
}));
export const queue: Queue =
global.__notifierQueue ||
(global.__notifierQueue = new Queue<QueueData>(QUEUE_NAME, {
connection: redis
}));

// Workers are where the meat of our procssing lives within a queue.
// Workers are where the meat of our processing lives within a queue.
// They reach out to our redis connection and pull jobs off the queue
// in an order determined by factors such as job priority, delay, etc.
// The scheduler plays an important role in helping workers stay busy.
worker = global.__notifierWorker || (global.__notifierWorker = new Worker<QueueData>(QUEUE_NAME, async (job) => {
console.log(`Sending email to ${job.data.emailAddress}`);

// Delay 1 second to simulate sending an email, be it for user registration, a newsletter, etc.
await new Promise((resolve) => setTimeout(resolve, 1000));

console.log(`Email sent to ${job.data.emailAddress}`);
}, {
connection: redis,
}));
const worker: Worker =
global.__notifierWorker ||
(global.__notifierWorker = new Worker<QueueData>(
QUEUE_NAME,
async job => {
console.log(`Sending email to ${job.data.emailAddress}`);

// Delay 1 second to simulate sending an email, be it for user registration, a newsletter, etc.
await new Promise(resolve => setTimeout(resolve, 1000));

console.log(`Email sent to ${job.data.emailAddress}`);
},
{
connection: redis
}
));

// Schedulers are used to move tasks between states within the queue.
// Jobs may be queued in a delayed or waiting state, but the scheduler's
// job is to eventually move them to an active state.
scheduler = global.__notifierScheduler || (global.__notifierScheduler = new QueueScheduler(QUEUE_NAME, {
connection: redis,
}));

export {
queue
}
const scheduler: QueueScheduler =
global.__notifierScheduler ||
(global.__notifierScheduler = new QueueScheduler(QUEUE_NAME, {
connection: redis
}));
21 changes: 12 additions & 9 deletions examples/bullmq-task-queue/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ActionFunction, useTransition } from "remix";
import { Form, json, useActionData } from "remix";
import type { ActionFunction } from "remix";
import { Form, json, useActionData, useTransition } from "remix";

import { queue } from "~/queues/notifier.server";

export let action: ActionFunction = async ({ request }) => {
export const action: ActionFunction = async ({ request }) => {
const formData = await request.formData();
const email = formData.get("email");

if (!email || typeof email !== "string" || !email.includes('@')) {
if (!email || typeof email !== "string" || !email.includes("@")) {
return json("Invalid email!", { status: 400 });
}

Expand All @@ -15,14 +16,14 @@ export let action: ActionFunction = async ({ request }) => {
// the job to redis for our worker to later pick up.
await queue.add("notification email", {
emailAddress: email
})
});

return json(`Email queued for ${email}!`);
};

export default function () {
let actionMessage = useActionData<string>();
let transition = useTransition();
export default function Index() {
const actionMessage = useActionData<string>();
const transition = useTransition();

return (
<main>
Expand All @@ -33,7 +34,9 @@ export default function () {
<input name="email" />
</label>
<div>
<button type="submit">{transition.state === 'idle' ? 'Send' : 'Sending'}</button>
<button type="submit">
{transition.state === "idle" ? "Send" : "Sending"}
</button>
</div>
</Form>
{actionMessage ? (
Expand Down
2 changes: 1 addition & 1 deletion examples/bullmq-task-queue/app/utils/redis.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare global {
var __redis: RedisType | undefined;
}

let redisOptions: Redis.RedisOptions = {
const redisOptions: Redis.RedisOptions = {
maxRetriesPerRequest: null,
enableReadyCheck: false
}
Expand Down

0 comments on commit 411134f

Please sign in to comment.