项目作者: eCollect

项目描述 :
Ordered pararallel asynchronous tasks.
高级语言: JavaScript
项目地址: git://github.com/eCollect/pateka.git
创建时间: 2018-10-16T07:46:34Z
项目社区:https://github.com/eCollect/pateka

开源协议:MIT License

下载




pateka - ordered parallel asynchronous tasks

travis npm version Coverage Status Known Vulnerabilities MIT Licence

Installation

  1. $ npm install pateka

Usage

Creating a new pateka. By default a pateka will be created with (parallel) 256 tracks, each track than will be filled with async tasks based on their routing key. Tasks in the same track ( same routing key ) will be run in order, tracks will be run in parallel.

  1. const Pateka = require('pateka');
  2. const Pateka = new Pateka();

Setting the number of (parallel) tracks

You can chnage the default number of tracks by passing a tracks option to the constructor.

  1. const Pateka = new Pateka({ tracks: 128 });

Adding tasks

Task are added with the add method. You will need to specify an id for the task, a task function, and a routingKey.

The routingKey will be used to spread tasks into tracks, ensuring that tasks with the same key are always run in the right order and sequence.

  1. pateka.add({
  2. routingKey: 'order-1234', // shared between tasks that needs tp be run in sequence
  3. id: '713973e256ab63505cba325344d30dbb', // unique for this task
  4. async task () {
  5. // do some work on this order
  6. }
  7. });
  8. pateka.add({
  9. routingKey: 'order-1234', // shared between tasks that needs tp be run in sequence
  10. id: ' 2cd96bc0d5b0d2e6520ef04fa9f887b9', // unique for this task
  11. async task () {
  12. // do some additional work on this order, after the other work has fhinished
  13. }
  14. });

Awaiting a task to be done

  1. await pateka.add({
  2. routingKey: 'order-1234', // shared between tasks that needs tp be run in sequence
  3. id: ' 2cd96bc0d5b0d2e6520ef04fa9f887b9', // unique for this task
  4. async task () {
  5. // do some additional work on this order, after the other work has fhinished
  6. }
  7. });

License

Copyright (c) 2018 eCollect AG.
Licensed under the MIT license.