Skip to content

Commit

Permalink
refactor: code to improve readability and maintainability (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
code-xhyun authored May 19, 2024
1 parent 0a24f70 commit 7e9070c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
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

1 comment on commit 7e9070c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 51%
53.65% (543/1012) 38.79% (116/299) 46.79% (73/156)

Pulse Test Report

Tests Skipped Failures Errors Time
56 0 💤 0 ❌ 0 🔥 8.262s ⏱️

Please sign in to comment.