Giter Club home page Giter Club logo

hapi-agenda's Introduction

hapi-agenda

Installation

npm install hapi-agenda --save

Usage

server.register({
  register: require('hapi-agenda'),
  options: {
    mongoUrl: 'localhost:27017/hapi-agenda',
    jobs: __dirname + '/jobs', // path to directory containing job files
    processEvery: '5 seconds', // Defaults to 30 seconds. Lower numbers = higher db calls
    every: { // Runs these jobs
      'say-hello': '10 seconds',
      'here is a task': '30 seconds'
    }
  }
}, function(err) {
  // start server or other stuff
});

Job File:

Job name based on filename

hello-world.js

module.exports = function(data, done) {
  console.log('Hello world');
  done();
};

Job with options and custom name

customjob.js

module.exports = {
  name: 'here is a task',
  job: function(data, done) {
    console.log('hostname', this.info.host);
    done();
  },
  concurrency: 10,
  priority: 'high'
};

hapi-agenda's People

Contributors

jgallen23 avatar ecwillis avatar dawnerd avatar eluttine avatar

Stargazers

Anneka Goss avatar  avatar PaulZeng avatar Ashley Kyle Smith avatar Travis Kaufman avatar

Watchers

 avatar  avatar  avatar James Cloos avatar  avatar  avatar

hapi-agenda's Issues

Cannot read property 'name' of undefined

this occurs in mongoskin version included
node_modules\mongoskin\lib\utils.js
line 33

  var skinClassName = 'Skin' + NativeClass.name; <----here
  function SkinClass() {
    var args = __slice.call(arguments);
    this._construct_args = args;
    if(useNativeConstructor && arguments.length > 0) {
      args.unshift(null);

expose agenda object

create hapi plugin that exposes agenda object. We should pass in mongodb url.

JSON api

What about adding an option to expose a json api? should be in this module or separate? @dawnerd ?

limit data for log

When events go into something like good-mongodb, it errors out because we are logging the job class instance and it returns a max call stack size exceeded. Looks like we could just pass back the attrs

log { event: 'log',
  timestamp: 1418862364737,
  tags: [ 'agenda', 'complete' ],
  data:
   { agenda:
      { _name: undefined,
        _processEvery: 30000,
        _defaultConcurrency: 5,
        _maxConcurrency: 20,
        _definitions: [Object],
        _runningJobs: [],
        _jobQueue: [],
        _defaultLockLifetime: 600000,
        _db: [Object],
        _events: [Object],
        _processInterval: [Object],
        _nextScanAt: Wed Dec 17 2014 16:26:26 GMT-0800 (PST) },
     attrs:
      { name: 'email-error-digest',
        data: {},
        type: 'normal',
        priority: 0,
        nextRunAt: null,
        _id: 54921f1cef00780cf583b780,
        lastRunAt: Wed Dec 17 2014 16:26:04 GMT-0800 (PST),
        lastFinishedAt: Wed Dec 17 2014 16:26:04 GMT-0800 (PST),
        lockedAt: null },
     _scheduled: true },
  pid: 62732 }
[RangeError: Maximum call stack size exceeded]

pass in directory of tasks

  • loop over directory and define a task for each file.
  • file can either return function or object
  • if object, use name to name task, job as fn and pass other options as options in the define call
  • Use the name of the file as the task name unless the module returns an object and the name is defined in there.

Object - some-task.js - new job defined as 'here is a task'

module.exports = {
  name: 'here is a task',
  job: function(data, done) {
  },
  concurrency: 10
}

Fn - some-task.js - new job defined as 'some-task'

module.exports = function(data, done) {
}

any other things we should consider?

pass in option to auto run every

want to be able to pass in an object to the plugin that will auto run agenda.every. It will be used to auto set up maintenance tasks when the server starts up. Could look something like this:

{ 
  plugin: require('haps-agenda'), 
  options: {
    every: {
     '1 hour': 'some job name'
    }
  }
}

Specs for v1

Goals

  • process long running jobs
  • queue up after reaching a max concurrent jobs
  • be able to spin up multiple workers
  • get progress of job
  • jobs can log process
  • mongodb backed
  • be able to retry failed jobs
  • if app crashes, restart jobs in progress
  • future jobs - example: run a job at midnight, or run in 24 hours from some event
  • json API - maybe we just do this in a hapi plugin that uses this lib
  • job timeouts - job is marked fail after X seconds

Similar Libs

Use Cases

  • sending email
  • aggregating metrics
  • maintenance tasks
  • drip marketing campaigns
  • crunching numbers

log events

lets call server.log for each of the main events that agenda fires. We should pass as much info as agenda gives us

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.