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: code to improve readability and maintainability #34

Merged
merged 1 commit into from
May 19, 2024
Merged
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
5 changes: 0 additions & 5 deletions src/cjs.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/job/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export const run: RunMethod = async function (this: Job) {
const { pulse } = this;
const definition = pulse._definitions[this.attrs.name];

// @TODO: this lint issue should be looked into: https://eslint.org/docs/rules/no-async-promise-executor
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
this.attrs.lastRunAt = new Date();
this.attrs.runCount = (this.attrs.runCount || 0) + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/pulse/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const database: DatabaseMethod = async function (this: Pulse, url, collec
if (cb) {
cb(error, null);
} else {
throw error;
throw new BaseError(error);
}
});

Expand Down
18 changes: 9 additions & 9 deletions src/pulse/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ export type DefineMethod = <T extends JobAttributesData>(
export const define: DefineMethod = function (this: Pulse, name, processor, options?) {
this._definitions[name] = {
fn: processor,
concurrency: (options as DefineOptions)?.concurrency || this._defaultConcurrency,
lockLimit: (options as DefineOptions)?.lockLimit || this._defaultLockLimit,
priority: (options as DefineOptions)?.priority || JobPriority.normal,
lockLifetime: (options as DefineOptions)?.lockLifetime || this._defaultLockLifetime,
concurrency: options?.concurrency || this._defaultConcurrency,
lockLimit: options?.lockLimit || this._defaultLockLimit,
priority: options?.priority || JobPriority.normal,
lockLifetime: options?.lockLifetime || this._defaultLockLifetime,
running: 0,
locked: 0,
shouldSaveResult: (options as DefineOptions)?.shouldSaveResult || false,
attempts: (options as DefineOptions)?.attempts || 0,
backoff: (options as DefineOptions)?.attempts && {
type: (options as DefineOptions)?.backoff?.type || 'exponential',
delay: (options as DefineOptions)?.backoff?.delay || 1000,
shouldSaveResult: options?.shouldSaveResult || false,
attempts: options?.attempts || 0,
backoff: options?.attempts && {
type: options?.backoff?.type || 'exponential',
delay: options?.backoff?.delay || 1000,
},
};

Expand Down
Loading