Skip to content

Commit

Permalink
feat(bullmq): rename job decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
abenerd authored and Romakita committed Oct 16, 2023
1 parent edb67af commit 522cd5f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions packages/third-parties/bullmq/src/BullMQModule.spec.ts
Expand Up @@ -7,7 +7,7 @@ import "./BullMQModule";
import {BullMQModule} from "./BullMQModule";
import {type BullMQConfig} from "./config/config";
import {JobMethods} from "./contracts";
import {Job} from "./decorators";
import {JobController} from "./decorators";
import {JobDispatcher} from "./dispatchers";

jest.mock("bullmq", () => {
Expand Down Expand Up @@ -37,7 +37,7 @@ const bullmq = {
workerQueues: ["default", "foo"]
} as BullMQConfig;

@Job("cron", "default", {
@JobController("cron", "default", {
repeat: {
pattern: "* * * * *"
}
Expand All @@ -46,7 +46,7 @@ class CustomCronJob implements JobMethods {
handle() {}
}

@Job("regular", "default")
@JobController("regular", "default")
class RegularJob {
handle() {}
}
Expand Down
@@ -1,9 +1,9 @@
import {Job} from "./Job";
import {JobController} from "./JobController";
import {Store} from "@tsed/core";

describe("Job", () => {
describe("JobController", () => {
it("should set the proper store data", () => {
@Job("testjob")
@JobController("testjob")
class TestJob {}

const store = Store.from(TestJob).get("bullmq");
Expand All @@ -14,7 +14,7 @@ describe("Job", () => {
});

it("should allow settings a custom queue", () => {
@Job("testjob", "custom")
@JobController("testjob", "custom")
class CustomQueueJob {}

const store = Store.from(CustomQueueJob).get("bullmq");
Expand All @@ -23,7 +23,7 @@ describe("Job", () => {
});

it("should allow custom options to be set", () => {
@Job("testjob", "default", {
@JobController("testjob", "default", {
backoff: 69,
attempts: 42
})
Expand All @@ -38,7 +38,7 @@ describe("Job", () => {
});

it("should set type for cron jobs", () => {
@Job("testjob", "default", {
@JobController("testjob", "default", {
repeat: {count: 42}
})
class CustomCronJob {}
Expand Down
Expand Up @@ -2,7 +2,7 @@ import {StoreMerge, useDecorators} from "@tsed/core";
import {Injectable} from "@tsed/di";
import {JobsOptions} from "bullmq";

export function Job(name: string, queue: string = "default", opts: JobsOptions = {}) {
export function JobController(name: string, queue: string = "default", opts: JobsOptions = {}) {
return useDecorators(
StoreMerge("bullmq", {
name,
Expand Down
2 changes: 1 addition & 1 deletion packages/third-parties/bullmq/src/decorators/index.ts
Expand Up @@ -2,4 +2,4 @@
* @file Automatically generated by barrelsby.
*/

export * from "./Job";
export * from "./JobController";
@@ -1,18 +1,18 @@
import {InjectorService} from "@tsed/di";
import {JobDispatcher} from "./JobDispatcher";
import {JobMethods} from "../contracts";
import {Job} from "../decorators";
import {JobController} from "../decorators";
import {Queue} from "bullmq";
import {instance, mock, verify, when, objectContaining} from "ts-mockito";

@Job("example-job", "default", {
@JobController("example-job", "default", {
backoff: 69
})
class ExampleTestJob implements JobMethods {
handle(payload: {msg: string}) {}
}

@Job("queue-not-configured", "not-configured")
@JobController("queue-not-configured", "not-configured")
class NotConfiguredQueueTestJob implements JobMethods {
handle() {}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/third-parties/bullmq/src/index.ts
Expand Up @@ -6,6 +6,5 @@ export * from "./BullMQModule";
export * from "./config/config";
export * from "./contracts/JobMethods";
export * from "./contracts/JobStore";
export * from "./decorators/Job";
export * from "./decorators/JobController";
export * from "./dispatchers/JobDispatcher";
export * from "./processors/ProcessorFactory";

0 comments on commit 522cd5f

Please sign in to comment.