Skip to content

Thekdar is module which will manage node child process , it will help us creating workers, distribute task across workers, kill workers or limit there work

Notifications You must be signed in to change notification settings

savetodrive/thekdar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thekdar Build Status

Thekdar is module which will manage node child process , it will help us creating workers, distribute task across workers, kill workers or limit there work.

Getting Started for contribution

- Clone this repo
- Run `npm install`
- Run `npm t` to see how it works

Example

const Thekdar = require("thekdar");
const events = Thekdar.events;
const Task = Thekdar.Tasks;

// Create new thekdar object
const thekdar = new Thekdar();

// Path of script to be executed and type of worker
    thekdar.addWorkerAddress(
      "./core/workers/fork.js",
       Task.TYPE_FORK
    );


  handleJobs(data, done) {
    // Create new task from Task class
    const task = new  Task();

    task.setData(data);

    // Set type of task like (fork, spawn)
    task.setType(Task.TYPE_FORK);

    try {
      // add task to thekdar
      const add = thekdar.addTask(task);

    } catch (error) {
      logger.error(error);
      logger.error(`Unable to completed job,
      Workers ${thekdar.getWorkers().size},
      tasks ${thekdar.getTasks().size}`);
      return done(error);
    }
  }

  _handleThekdarMessages() {
     thekdar.on("message", data => {
      switch (data.type) {
        case events.TASK_ERROR:
          break;
        case events.TASK_COMPLETE:
        case events.TASK_REMOVE:
          console.log(thekdar.getWorkers().size);
          console.log(thekdar.getTasks().size);
           break;
      }
    });
  }

About

Thekdar is module which will manage node child process , it will help us creating workers, distribute task across workers, kill workers or limit there work

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published