Skip to content
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/node": "^14.0.27",
"@types/puppeteer": "^3.0.1",
"@types/puppeteer-core": "^2.0.0",
"@types/underscore": "^1.11.3",
"coveralls": "^3.1.0",
"express": "^4.17.1",
"jest": "^24.9.0",
Expand Down
14 changes: 14 additions & 0 deletions src/Cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SystemMonitor from './SystemMonitor';
import { EventEmitter } from 'events';
import ConcurrencyImplementation, { WorkerInstance, ConcurrencyImplementationClassType }
from './concurrency/ConcurrencyImplementation';
import * as _ from 'underscore';

const debug = util.debugGenerator('Cluster');

Expand Down Expand Up @@ -404,6 +405,15 @@ export default class Cluster<JobData = any, ReturnData = any> extends EventEmitt
this.work();
}

private removeTask(id: any) {
try {
const findIndex = this.jobQueue.list.lastIndexOf(id)
findIndex !== -1 && this.jobQueue.list.splice(findIndex , 1)
} catch (error) {
console.log('error while removing task from queue >>>', JSON.stringify(error))
}
}

public async queue(
data: JobData,
taskFunction?: TaskFunction<JobData, ReturnData>,
Expand All @@ -418,6 +428,10 @@ export default class Cluster<JobData = any, ReturnData = any> extends EventEmitt
this.queueJob(data, taskFunction);
}

public removeTaskFromQueue(id: string) {
this.removeTask(id);
}

public execute(
data: JobData,
taskFunction?: TaskFunction<JobData, ReturnData>,
Expand Down
5 changes: 3 additions & 2 deletions src/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ export default class Job<JobData, ReturnData> {

private lastError: Error | null = null;
public tries: number = 0;

public url: string;
public constructor(
data?: JobData,
data?: any,
taskFunction?: TaskFunction<JobData, ReturnData>,
executeCallbacks?: ExecuteCallbacks,
) {
this.data = data;
this.taskFunction = taskFunction;
this.executeCallbacks = executeCallbacks;
this.url = data.url;
}

public getUrl(): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface QueueOptions {

export default class Queue<T> {

private list: T[] = [];
public list: T[] = [];
private delayedItems: number = 0;

public size(): number {
Expand Down