Comparing version 1.0.5 to 1.0.6
@@ -5,2 +5,3 @@ module.exports = { | ||
TASK_REMOVE: 'task:remove', | ||
TASK_STOP: 'task:stop', | ||
TASK_COMPLETE: 'task:complete', | ||
@@ -7,0 +8,0 @@ WORKER_CREATE: 'worker:create', |
@@ -30,2 +30,7 @@ const uuid = require('uuid'); | ||
} | ||
getWorkerId() { | ||
return this._workerId | ||
} | ||
getId() { | ||
@@ -32,0 +37,0 @@ return this.id; |
@@ -9,3 +9,2 @@ const uuid = require('uuid'); | ||
const Worker = require('./Worker'); | ||
const differenceInMinutes = require('date-fns/difference_in_minutes'); | ||
@@ -222,3 +221,3 @@ class Thekdar extends EventEmitter { | ||
const workerTask = this._workerTaskLookup.get(tempWorkerId); | ||
const indexOfTask = workerTask.findIndex(id => taskId); | ||
const indexOfTask = workerTask.findIndex(id => id === taskId); | ||
if (indexOfTask > -1) { | ||
@@ -292,2 +291,10 @@ workerId = tempWorkerId; | ||
} | ||
stopTask(taskId) { | ||
const task = this._tasks.get(taskId); | ||
const worker = this._workers.get(task.getType()).get(task.getWorkerId()); | ||
worker.send(events.TASK_STOP, task); | ||
debug(`Task stopped: ${taskId}`); | ||
this.removeTask(taskId); | ||
} | ||
} | ||
@@ -294,0 +301,0 @@ Thekdar.MAX_TASK_PER_WORKER = 10; |
@@ -0,12 +1,23 @@ | ||
const { events } = require('../../index'); | ||
process.on('message', data => { | ||
// console.log(data); | ||
setTimeout(() => { | ||
process.send({ | ||
type: 'task:complete', | ||
taskId: data.task.id, | ||
workerId: data.workerId, | ||
data: {}, | ||
}); | ||
}, Math.round(Math.random() * 5000) + 3000); | ||
switch (data.type) { | ||
case events.TASK_ADD: | ||
timer = setTimeout(() => { | ||
process.send({ | ||
type: 'task:complete', | ||
taskId: data.task.id, | ||
workerId: data.workerId, | ||
data: {}, | ||
}); | ||
}, Math.round(Math.random() * 5000) + 3000); | ||
break; | ||
case events.TASK_STOP: | ||
clearTimeout(timer); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); |
{ | ||
"name": "thekdar", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "", | ||
@@ -14,3 +14,2 @@ "main": "index.js", | ||
"better-queue": "^3.8.7", | ||
"date-fns": "^1.29.0", | ||
"debug": "^3.1.0", | ||
@@ -17,0 +16,0 @@ "respawn": "^2.5.0", |
@@ -5,2 +5,7 @@ # Thekdar [![Build Status](https://travis-ci.org/savetodrive/thekdar.svg?branch=master)](https://travis-ci.org/savetodrive/thekdar) | ||
# Getting Started for contribution | ||
- Clone this repo | ||
- Run `npm install` | ||
- Run `npm t` to see how it works | ||
# Example | ||
@@ -7,0 +12,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
112775
4
14
581
63
- Removeddate-fns@^1.29.0
- Removeddate-fns@1.30.1(transitive)