Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove redundant AC polyfill and use built-in UUID generator #3067

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@
"cron-parser": "^4.9.0",
"ioredis": "^5.4.1",
"msgpackr": "^1.11.2",
"node-abort-controller": "^3.1.1",
"semver": "^7.5.4",
"tslib": "^2.0.0",
"uuid": "^9.0.0"
"tslib": "^2.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
Expand All @@ -78,10 +76,9 @@
"@types/lodash.isarguments": "^3.1.7",
"@types/mocha": "^5.2.7",
"@types/msgpack": "^0.0.31",
"@types/node": "^12.20.25",
"@types/node": "^16.7.0",
"@types/semver": "^7.3.9",
"@types/sinon": "^10.0.13",
"@types/uuid": "^3.4.10",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^5.33.0",
"chai": "^4.3.4",
Expand Down
4 changes: 2 additions & 2 deletions src/classes/flow-producer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import { Redis, ChainableCommander } from 'ioredis';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import {
FlowJob,
FlowQueuesOpts,
Expand Down Expand Up @@ -324,7 +324,7 @@ export class FlowProducer extends EventEmitter {
const queueOpts = queuesOpts && queuesOpts[node.queueName];

const jobsOpts = queueOpts?.defaultJobOptions ?? {};
const jobId = node.opts?.jobId || v4();
const jobId = node.opts?.jobId || randomUUID();

return trace<Promise<JobNode>>(
this.telemetry,
Expand Down
4 changes: 2 additions & 2 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import {
BaseJobOptions,
BulkJobOptions,
Expand Down Expand Up @@ -152,7 +152,7 @@ export class Queue<
ResultType = ExtractResultType<DataTypeOrJob, DefaultResultType>,
NameType extends string = ExtractNameType<DataTypeOrJob, DefaultNameType>,
> extends QueueGetters<JobBase<DataTypeOrJob, ResultType, NameType>> {
token = v4();
token = randomUUID();
jobsOpts: BaseJobOptions;
opts: QueueOptions;

Expand Down
7 changes: 2 additions & 5 deletions src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import * as fs from 'fs';
import { URL } from 'url';
import { Redis } from 'ioredis';
import * as path from 'path';
import { v4 } from 'uuid';

// Note: this Polyfill is only needed for Node versions < 15.4.0
import { AbortController } from 'node-abort-controller';
import { randomUUID } from 'crypto';

import {
GetNextJobOptions,
Expand Down Expand Up @@ -244,7 +241,7 @@ export class Worker<
this.opts.lockRenewTime =
this.opts.lockRenewTime || this.opts.lockDuration / 2;

this.id = v4();
this.id = randomUUID();

if (processor) {
if (typeof processor === 'function') {
Expand Down
3 changes: 0 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Cluster, Redis } from 'ioredis';

// Note: this Polyfill is only needed for Node versions < 15.4.0
import { AbortController } from 'node-abort-controller';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { CONNECTION_CLOSED_ERROR_MSG } from 'ioredis/built/utils';
Expand Down
6 changes: 3 additions & 3 deletions tests/test_bulk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { default as IORedis } from 'ioredis';
import { after, beforeEach, describe, it, before } from 'mocha';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import { Queue, QueueEvents, Worker, Job } from '../src/classes';
import { removeAllQueueData, delay } from '../src/utils';

Expand All @@ -18,7 +18,7 @@ describe('bulk jobs', () => {
});

beforeEach(async function () {
queueName = `test-${v4()}`;
queueName = `test-${randomUUID()}`;
queue = new Queue(queueName, { connection, prefix });
});

Expand Down Expand Up @@ -66,7 +66,7 @@ describe('bulk jobs', () => {

it('should allow to pass parent option', async () => {
const name = 'test';
const parentQueueName = `parent-queue-${v4()}`;
const parentQueueName = `parent-queue-${randomUUID()}`;
const parentQueue = new Queue(parentQueueName, { connection, prefix });

const parentWorker = new Worker(parentQueueName, null, {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { default as IORedis } from 'ioredis';
import { after } from 'lodash';
import { beforeEach, describe, it, after as afterAll } from 'mocha';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import {
FlowProducer,
Queue,
Expand All @@ -25,7 +25,7 @@ describe('Cleaner', () => {
});

beforeEach(async () => {
queueName = `test-${v4()}`;
queueName = `test-${randomUUID()}`;
queue = new Queue(queueName, { connection, prefix });
queueEvents = new QueueEvents(queueName, { connection, prefix });
await queueEvents.waitUntilReady();
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('Cleaner', () => {

describe('when parent has pending children in different queue', async () => {
it('keeps parent in waiting-children', async () => {
const childrenQueueName = `test-${v4()}`;
const childrenQueueName = `test-${randomUUID()}`;
const childrenQueue = new Queue(childrenQueueName, {
connection,
prefix,
Expand Down Expand Up @@ -605,7 +605,7 @@ describe('Cleaner', () => {
describe('when parent belongs to different queue', async () => {
describe('when parent has more than 1 pending children', async () => {
it('deletes each children until trying to move parent to wait', async () => {
const parentQueueName = `test-${v4()}`;
const parentQueueName = `test-${randomUUID()}`;
const parentQueue = new Queue(parentQueueName, {
connection,
prefix,
Expand Down Expand Up @@ -661,7 +661,7 @@ describe('Cleaner', () => {

describe('when parent has only 1 pending children', async () => {
it('moves parent to wait to try to process it', async () => {
const parentQueueName = `test-${v4()}`;
const parentQueueName = `test-${randomUUID()}`;
const parentQueue = new Queue(parentQueueName, {
connection,
prefix,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_concurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../src/classes';
import { delay, removeAllQueueData } from '../src/utils';
import { beforeEach, describe, it, after as afterAll } from 'mocha';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import { expect } from 'chai';
import * as ProgressBar from 'progress';
import { after } from 'lodash';
Expand All @@ -24,7 +24,7 @@ describe('Concurrency', () => {
});

beforeEach(async () => {
queueName = `test-${v4()}`;
queueName = `test-${randomUUID()}`;
await new IORedis().flushall();
});

Expand Down
4 changes: 2 additions & 2 deletions tests/test_connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { default as IORedis, RedisOptions } from 'ioredis';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import {
Queue,
Job,
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('connection', () => {
});

beforeEach(async function () {
queueName = `test-${v4()}`;
queueName = `test-${randomUUID()}`;
queue = new Queue(queueName, { connection, prefix });
});

Expand Down
4 changes: 2 additions & 2 deletions tests/test_delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { after } from 'lodash';
import { describe, beforeEach, it, before, after as afterAll } from 'mocha';
import { expect } from 'chai';
import { default as IORedis } from 'ioredis';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import { Queue, Job, Worker, QueueEvents } from '../src/classes';
import { removeAllQueueData, delay } from '../src/utils';

Expand All @@ -20,7 +20,7 @@ describe('Delayed jobs', function () {
});

beforeEach(async function () {
queueName = `test-${v4()}`;
queueName = `test-${randomUUID()}`;
queue = new Queue(queueName, { connection, prefix });
await queue.waitUntilReady();
});
Expand Down
14 changes: 7 additions & 7 deletions tests/test_events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { default as IORedis } from 'ioredis';
import { v4 } from 'uuid';
import { randomUUID } from 'crypto';
import { expect } from 'chai';
import { after } from 'lodash';
import { beforeEach, describe, it, before, after as afterAll } from 'mocha';
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('events', function () {
});

beforeEach(async function () {
queueName = `test-${v4()}`;
queueName = `test-${randomUUID()}`;
queue = new Queue(queueName, { connection, prefix });
queueEvents = new QueueEvents(queueName, { connection, prefix });
await queue.waitUntilReady();
Expand All @@ -47,7 +47,7 @@ describe('events', function () {

describe('when autorun option is provided as false', function () {
it('emits waiting when a job has been added', async () => {
const queueName2 = `test-${v4()}`;
const queueName2 = `test-${randomUUID()}`;
const queue2 = new Queue(queueName2, { connection, prefix });
const queueEvents2 = new QueueEvents(queueName2, {
autorun: false,
Expand All @@ -74,7 +74,7 @@ describe('events', function () {

describe('when run method is called when queueEvent is running', function () {
it('throws error', async () => {
const queueName2 = `test-${v4()}`;
const queueName2 = `test-${randomUUID()}`;
const queue2 = new Queue(queueName2, { connection, prefix });
const queueEvents2 = new QueueEvents(queueName2, {
autorun: false,
Expand Down Expand Up @@ -857,7 +857,7 @@ describe('events', function () {
prefix,
});
const name = 'parent-job';
const childrenQueueName = `children-queue-${v4()}`;
const childrenQueueName = `children-queue-${randomUUID()}`;

const childrenWorker = new Worker(
childrenQueueName,
Expand Down Expand Up @@ -1244,7 +1244,7 @@ describe('events', function () {
});

it('should trim events manually', async () => {
const queueName = 'test-manual-' + v4();
const queueName = 'test-manual-' + randomUUID();
const trimmedQueue = new Queue(queueName, { connection, prefix });

await trimmedQueue.add('test', {});
Expand All @@ -1270,7 +1270,7 @@ describe('events', function () {

describe('when publishing custom events', function () {
it('emits waiting when a job has been added', async () => {
const queueName2 = `test-${v4()}`;
const queueName2 = `test-${randomUUID()}`;
const queueEventsProducer = new QueueEventsProducer(queueName2, {
connection,
prefix,
Expand Down
Loading