Skip to content

Commit

Permalink
UPDATE as per nest-queue-strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak25 committed Dec 26, 2020
1 parent d9bf5e8 commit 6641973
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 183 deletions.
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ members of the project's leadership.
## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
<https://www.contributor-covenant.org/faq>
Binary file removed cover.png
Binary file not shown.
30 changes: 0 additions & 30 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,3 @@ export const events = {
jobProcessing: "sqb-queue::job-processing",
jobProcessed: "sqb-queue::job-processed",
};

export function OnJobFailed() {
return function (
target: Record<string, any>,
propertyKey: string,
descriptor: PropertyDescriptor
) {
ListensTo(events.jobFailed)(target, propertyKey, descriptor);
};
}

export function OnJobProcessing() {
return function (
target: Record<string, any>,
propertyKey: string,
descriptor: PropertyDescriptor
) {
ListensTo(events.jobProcessing)(target, propertyKey, descriptor);
};
}

export function OnJobProcessed() {
return function (
target: Record<string, any>,
propertyKey: string,
descriptor: PropertyDescriptor
) {
ListensTo(events.jobProcessed)(target, propertyKey, descriptor);
};
}
2 changes: 1 addition & 1 deletion lib/core/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './payloadBuilder';
export * from "./payloadBuilder";
8 changes: 6 additions & 2 deletions lib/core/payloadBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { InternalMessage, JobOptions, Message } from "../interfaces";
import {
InternalMessage,
JobOptions,
Message,
} from "@squareboat/nest-queue-strategy";
import { QueueMetadata } from "../metadata";

type Complete<T> = {
Expand Down Expand Up @@ -27,7 +31,7 @@ export class PayloadBuilder {
const config = QueueMetadata.getData();
payload.queue =
payload.connection != undefined
? config.connections[payload.connection].queue
? (config.connections[payload.connection].queue as string)
: undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ListensTo } from "@squareboat/nest-events";
import { JobOptions } from "@squareboat/nest-queue-strategy";
import "reflect-metadata";
import { events, JOB_NAME, JOB_OPTIONS } from "./constants";
import { JobOptions } from "./interfaces";

export function Job(job: string, options?: JobOptions) {
options = options || {};
Expand Down
1 change: 0 additions & 1 deletion lib/drivers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./sqs";
export * from "./sync";
63 changes: 0 additions & 63 deletions lib/drivers/sqs.ts

This file was deleted.

7 changes: 5 additions & 2 deletions lib/drivers/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { InternalMessage, QueueDriver } from "../interfaces";
import { DriverJob } from "../jobs";
import {
DriverJob,
InternalMessage,
QueueDriver,
} from "@squareboat/nest-queue-strategy";
import { QueueMetadata } from "../metadata";

export class SyncQueueDriver implements QueueDriver {
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./queue";
export * from "./decorators";
export * from "./jobrunner";
export * from "./worker";
export * from "@squareboat/nest-queue-strategy";
12 changes: 0 additions & 12 deletions lib/interfaces/driver.ts

This file was deleted.

5 changes: 1 addition & 4 deletions lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export * from './options';
export * from './message';
export * from './driver';
export * from './job';
export * from "./options";
1 change: 0 additions & 1 deletion lib/interfaces/job.ts

This file was deleted.

18 changes: 0 additions & 18 deletions lib/interfaces/message.ts

This file was deleted.

19 changes: 5 additions & 14 deletions lib/interfaces/options.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { ModuleMetadata, Type } from "@nestjs/common";
import { QueueDriver } from "@squareboat/nest-queue-strategy";

export interface SqsBrokerOption {
driver: "sqs";
profile: string;
apiVersion: string;
prefix: string;
queue: string;
suffix?: string;
region: string;
}

export interface SyncBrokerOption {
driver: "sync";
queue?: "sync";
export interface QueueDriverOptions {
driver: QueueDriver;
[key: string]: string | number | Record<string, any>;
}

export interface QueueOptions {
isGlobal?: boolean;
default: string;
connections: {
[key: string]: SqsBrokerOption | SyncBrokerOption;
[key: string]: QueueDriverOptions;
};
}

Expand Down
8 changes: 6 additions & 2 deletions lib/jobrunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { InternalMessage, ListenerOptions, QueueDriver } from "./interfaces";
import { DriverJob } from "./jobs";
import {
DriverJob,
InternalMessage,
QueueDriver,
} from "@squareboat/nest-queue-strategy";
import { ListenerOptions } from "./interfaces";
import { QueueMetadata } from "./metadata";
import { Dispatch } from "./queue";

Expand Down
5 changes: 0 additions & 5 deletions lib/jobs/driverJob.ts

This file was deleted.

2 changes: 0 additions & 2 deletions lib/jobs/index.ts

This file was deleted.

7 changes: 0 additions & 7 deletions lib/jobs/sqsJob.ts

This file was deleted.

5 changes: 3 additions & 2 deletions lib/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Inject, Injectable } from "@nestjs/common";
import { JobOptions } from "@squareboat/nest-queue-strategy";
import { QUEUE_OPTIONS } from "./constants";
import { QueueOptions, JobOptions, InternalMessage } from "./interfaces";
import { QueueOptions } from "./interfaces";

interface JobTarget {
options: JobOptions;
Expand All @@ -17,7 +18,7 @@ export class QueueMetadata {
QueueMetadata.data = data;
QueueMetadata.defaultOptions = {
connection: data.default,
queue: data.connections[data.default].queue,
queue: data.connections[data.default].queue as string,
delay: 10,
tries: 5,
timeout: 30,
Expand Down
2 changes: 1 addition & 1 deletion lib/queue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PayloadBuilder } from "./core";
import { Message } from "./interfaces";
import { QueueMetadata } from "./metadata";
import { QueueService } from "./service";
import { Message } from "@squareboat/nest-queue-strategy";

export class Queue {
static async dispatch(message: Message): Promise<void> {
Expand Down
10 changes: 4 additions & 6 deletions lib/service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Inject, Injectable } from "@nestjs/common";
import { QUEUE_OPTIONS } from "./constants";
import { SqsQueueDriver } from "./drivers/sqs";
import { QueueDriver, QueueOptions, SqsBrokerOption } from "./interfaces";
import { QueueOptions } from "./interfaces";
import { QueueMetadata } from "./metadata";
import { QueueDriver } from "@squareboat/nest-queue-strategy";

@Injectable()
export class QueueService {
private static connections: Record<string, any> = {};
private connectionDrivers = { sqs: SqsQueueDriver, sync: SqsQueueDriver };

constructor(@Inject(QUEUE_OPTIONS) private options: QueueOptions) {
for (const connName in this.options.connections) {
const connection = this.options.connections[connName];
QueueService.connections[connName] = new this.connectionDrivers[
connection.driver
](connection as SqsBrokerOption);
const driver: any = connection.driver;
QueueService.connections[connName] = new driver(connection);
}
}

Expand Down
11 changes: 5 additions & 6 deletions lib/worker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ListenerOptions, QueueDriver } from "./interfaces";
import { DriverJob } from "./jobs";
import { ListenerOptions } from "./interfaces";
import { QueueMetadata } from "./metadata";
import { QueueService } from "./service";
import { JobRunner } from "./jobrunner";
import { DriverJob, QueueDriver } from "@squareboat/nest-queue-strategy";

export class QueueWorker {
private options: ListenerOptions;
Expand All @@ -18,10 +18,9 @@ export class QueueWorker {

if (!this.options.queue) {
const data = QueueMetadata.getData();
this.options["queue"] =
data.connections[
this.options.connection || defaultOptions.connection
].queue;
this.options["queue"] = data.connections[
this.options.connection || defaultOptions.connection
].queue as string;
}
}

Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"@nestjs/core": "^6.7.0 || ^7.0.0"
},
"dependencies": {
"@squareboat/nest-events": "0.0.5",
"@squareboat/nest-queue-strategy": "0.0.2",
"aws-sdk": "^2.782.0"
}
}

0 comments on commit 6641973

Please sign in to comment.