Skip to content

Commit

Permalink
fix: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Feb 11, 2021
1 parent cf6f377 commit 7b9b477
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 97 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
"canonical",
"canonical/typescript"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"root": true,
"rules": {
"@typescript-eslint/explicit-module-boundary-types": 0,
"fp/no-events": 0
}
}
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage
dist
node_modules
/coverage
/dist
/node_modules
*.log
.*
!.babelrc
Expand Down
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test
coverage
/test
/coverage
.*
*.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type TaskInput = {
* @property getActiveTaskInstructions Returns list of tasks that are currently being executed. Used for concurrency control.
*/
type PlantonConfiguration = {
readonly getActiveTaskInstructions: (taskName: string) => TaskInstruction[];
readonly getActiveTaskInstructions: (taskName: string) => Promise<TaskInstruction[]>;
readonly tasks: TaskInput[]
};

Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@
"@types/set-interval-async": "^1.0.0",
"es6-error": "^4.1.1",
"promise-deferred": "^2.0.3",
"roarr": "^2.15.4",
"serialize-error": "^7.0.1"
"roarr": "^4.0.11",
"serialize-error": "^8.0.1"
},
"description": "Database-agnostic task scheduler.",
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/sinon": "^9.0.9",
"ava": "^3.14.0",
"@types/sinon": "^9.0.10",
"ava": "^3.15.0",
"coveralls": "^3.1.0",
"del-cli": "^3.0.1",
"delay": "^4.4.0",
"eslint": "^7.15.0",
"eslint-config-canonical": "^24.4.4",
"husky": "^4.3.5",
"lint-staged": "^10.5.3",
"delay": "^5.0.0",
"eslint": "^7.19.0",
"eslint-config-canonical": "^25.8.16",
"husky": "^5.0.9",
"lint-staged": "^10.5.4",
"nyc": "^15.1.0",
"semantic-release": "^17.3.0",
"sinon": "^9.2.1",
"semantic-release": "^17.3.8",
"sinon": "^9.2.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.2"
"typescript": "^4.1.5"
},
"engines": {
"node": ">=10"
Expand All @@ -54,7 +54,7 @@
"scheduler"
],
"license": "BSD-3-Clause",
"main": "./dist/index.js",
"main": "./dist/src/index.js",
"name": "planton",
"repository": {
"type": "git",
Expand All @@ -65,6 +65,6 @@
"lint": "eslint ./src ./test && tsc --noEmit",
"test": "ava --verbose --serial"
},
"typings": "./dist/index.d.ts",
"typings": "./dist/src/index.d.ts",
"version": "1.0.0"
}
18 changes: 9 additions & 9 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import ExtendableError from 'es6-error';
export class PlantonError extends ExtendableError {}

export class UnexpectedStateError extends PlantonError {
code: string;
public code: string;

constructor (message: string, code = 'UNEXPECTED_STATE_ERROR') {
public constructor (message: string, code = 'UNEXPECTED_STATE_ERROR') {
super(message);

this.code = code;
}
}

export class InvalidTaskConfigurationNameError extends UnexpectedStateError {
taskName: string;
public taskName: string;

constructor (taskName: string, message: string) {
public constructor (taskName: string, message: string) {
super(
message,
'INVALID_TASK_CONFIGURATION',
Expand All @@ -30,9 +30,9 @@ export class InvalidTaskConfigurationNameError extends UnexpectedStateError {
}

export class DuplicateTaskNameError extends UnexpectedStateError {
duplicateTaskName: string;
public duplicateTaskName: string;

constructor (duplicateTaskName: any) {
public constructor (duplicateTaskName: any) {
super(
'Task name is duplicate.',
'DUPLICATE_TASK_NAME',
Expand All @@ -43,11 +43,11 @@ export class DuplicateTaskNameError extends UnexpectedStateError {
}

export class UnexpectedTaskInstructionsError extends UnexpectedStateError {
taskName: string;
public taskName: string;

unexpectedTaskInstructions: any;
public unexpectedTaskInstructions: any;

constructor (taskName: string, unexpectedTaskInstructions: any) {
public constructor (taskName: string, unexpectedTaskInstructions: any) {
super(
'Unexpected task instructions.',
'UNEXPECTED_TASK_INSTRUCTIONS',
Expand Down
61 changes: 30 additions & 31 deletions src/factories/createPlanton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import delay from 'delay';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error
import Deferred from 'promise-deferred';
import {
serializeError,
Expand All @@ -26,13 +26,13 @@ const log = Logger.child({
type TaskInstruction = string;

type TaskEvent = {
readonly taskName: string;
readonly instruction: string;
readonly taskName: string,
readonly instruction: string,
};

type ErrorEvent = {
readonly taskName: string;
readonly error: Error;
readonly taskName: string,
readonly error: Error,
};

/**
Expand All @@ -41,10 +41,10 @@ type ErrorEvent = {
* @property limit A limit derived based on the value of `concurrency` and the number of `activeTaskInstructions` (CONCURRENCY - ACTIVE TASK INSTRUCTIONS = LIMIT).
*/
type ScheduleConfiguration = {
readonly activeTaskInstructions: TaskInstruction[];
readonly concurrency: number;
readonly limit: number;
readonly taskName: string;
readonly activeTaskInstructions: TaskInstruction[],
readonly concurrency: number,
readonly limit: number,
readonly taskName: string,
};

/**
Expand All @@ -67,28 +67,28 @@ type CalculateLimit = (concurrency: number, activeTaskInstructions: TaskInstruct
* @property name A unique name of the task. Used to identify task scheduler in errors and for tracking active task instructions (see `getActiveTaskInstructions`).
*/
type TaskInput = {
readonly calculateDelay?: CalculateDelay;
readonly calculateLimit?: CalculateLimit;
readonly concurrency?: number;
readonly name: string;
readonly schedule: Schedule;
readonly calculateDelay?: CalculateDelay,
readonly calculateLimit?: CalculateLimit,
readonly concurrency?: number,
readonly name: string,
readonly schedule: Schedule,
};

/**
* @property getActiveTaskInstructions Returns list of tasks that are currently being executed. Used for concurrency control.
*/
type PlantonConfiguration = {
readonly getActiveTaskInstructions: (taskName: string) => TaskInstruction[];
readonly tasks: TaskInput[]
readonly getActiveTaskInstructions: (taskName: string) => Promise<TaskInstruction[]>,
readonly tasks: TaskInput[],
};

type InternalTask = {
attemptNumber: number;
attemptNumber: number,

readonly concurrency: number;
readonly name: string;
readonly schedule: Schedule;
readonly terminate: () => void;
readonly concurrency: number,
readonly name: string,
readonly schedule: Schedule,
readonly terminate: () => Promise<void>,
};

type EventMap = {
Expand All @@ -97,9 +97,9 @@ type EventMap = {
};

type Planton = {
events: Emitter<EventMap>;
terminate: () => Promise<void>;
}
events: Emitter<EventMap>,
terminate: () => Promise<void>,
};

const defaultCalculateDelay: CalculateDelay = () => {
return 1_000;
Expand Down Expand Up @@ -127,9 +127,9 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {
}
}

const calculateDelay = inputTask.calculateDelay || defaultCalculateDelay;
const calculateDelay = inputTask.calculateDelay ?? defaultCalculateDelay;

const calculateLimit = inputTask.calculateLimit || defaultCalculateLimit;
const calculateLimit = inputTask.calculateLimit ?? defaultCalculateLimit;

const concurrency = inputTask.concurrency === undefined ? 1 : inputTask.concurrency;

Expand Down Expand Up @@ -157,11 +157,10 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {

let active = true;

// eslint-disable-next-line complexity
(async () => {
// eslint-disable-next-line no-unmodified-loop-condition
while (active) {
const calculatedDelay = await calculateDelay(task.attemptNumber || 0);
const calculatedDelay = await calculateDelay(task.attemptNumber ?? 0);

if (calculatedDelay) {
delayPromise = delay(calculatedDelay);
Expand Down Expand Up @@ -320,7 +319,7 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {
})();

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error
task.terminate = terminate;

tasks.push(task as InternalTask);
Expand All @@ -330,8 +329,8 @@ const createPlanton = (configuration: PlantonConfiguration): Planton => {
events,
terminate: async () => {
await Promise.all(
tasks.map((task) => {
return task.terminate();
tasks.map(async (task) => {
await task.terminate();
}),
);
},
Expand Down
13 changes: 4 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/* eslint-disable import/exports-last */

export type EventMap = Record<string, any>;

type EventKey<T extends EventMap> = string & keyof T;
type EventReceiver<T> = (parameters: T) => void;

export type Emitter<T extends EventMap> = {
on<K extends EventKey<T>>
(eventName: K, function_: EventReceiver<T[K]>): void;
off<K extends EventKey<T>>
(eventName: K, function_: EventReceiver<T[K]>): void;
emit<K extends EventKey<T>>
(eventName: K, parameters: T[K]): void;
}
on: <K extends EventKey<T>>(eventName: K, function_: EventReceiver<T[K]>) => void,
off: <K extends EventKey<T>>(eventName: K, function_: EventReceiver<T[K]>) => void,
emit: <K extends EventKey<T>>(eventName: K, parameters: T[K]) => void,
};
Loading

0 comments on commit 7b9b477

Please sign in to comment.