Code Monkey home page Code Monkey logo

stevejobs's Introduction

Steve Jobs

The Simple Jobs Queue That Just Works

Run scheduled tasks with Steve Jobs, the simple jobs queue made just for Meteor. With tight MongoDB integration and fibers-based timing functions, this package is quick, reliable and effortless to use.

  • Jobs run on one server at a time
  • Jobs run predictably and consecutively
  • Jobs and their history are stored in MongoDB
  • Failed jobs are retried on server restart
  • No third party dependencies

The new 3.1 features repeating jobs and more improvements. It can run hundreds of jobs in seconds with minimal CPU impact, making it a reasonable choice for many applications. To get started, check out the documentation and the quick start below.

Developer Friendly GUI and API

In addition to a simple API, the Steve Jobs package offers an in-app development tool. After installing the main package, run the package command below and press Control + J in your app to open it.

meteor add msavin:sjobs-ui-blaze

Note: this package may be a little bit flakey, and might not work if audit-argument-checks is present. Unfortunately, I had lost the source code, and will probably rebuild the package once there is a good reason to do so.

Quick Start

First, install the package, and import if necessary:

meteor add msavin:sjobs
import { Jobs } from 'meteor/msavin:sjobs'

Then, write your background jobs like you would write your methods:

Jobs.register({
    "sendReminder": function (to, message) {
        var instance = this;

        var call = HTTP.put("http://www.magic.com/sendEmail", {
            to: to,
            message: message
        })

        if (call.statusCode === 200) {
            instance.success(call.result);
        } else {
            instance.reschedule({
                in: {
                    minutes: 5
                }
            });
        }
    }
});

Finally, schedule a background job like you would call a method:

Jobs.run("sendReminder", "[email protected]", "The future is here!");

One more thing: the function above will schedule the job to run on the moment that the function was called, however, you can delay it by passing in a special configuration object at the end:

Jobs.run("sendReminder", "[email protected]", "The future is here!", {
    in: {
        days: 3,
    }, 
    on: {
        hour: 9,
        minute: 42
    },
    priority: 9999999999
});

The configuration object supports date, in, on, priority, singular, unique, and data, all of which are completely optional. For more information, see the Jobs.run documentation.

Repeating Jobs

Compared to a CRON Job, the Steve Jobs package gives you much more control over how and when the job runs. To get started, you just need to create a job that replicates itself.

Jobs.register({
    "syncData": function () {
        var instance = this;

        var call = HTTP.put("http://www.magic.com/syncData")

        if (call.statusCode === 200) {
            instance.replicate({
                in: {
                    hours: 1
                }
            });
            
            // alternatively, you can use instance.remove to save storage
            instance.success(call.result);
        } else {
            instance.reschedule({
                in: {
                    minutes: 5
                }
            });
        }
    }
});

Then, you need to "kickstart" the queue by creating the first job to run. By using the singular flag, you can ensure that Meteor will only create the job if there is no pending or failed instance of it.

Meteor.startup(function () {
    Jobs.run("syncData", {
        singular: true
    })    
})

Documentation

Jobs.register and Jobs.run are all you need to get started, but that's only the beginning of what the package can do. To explore the rest of the functionality, jump into the documentation:


Steve Jobs is an MIT-licensed project, brought to you by Meteor Candy.

stevejobs's People

Contributors

msavin avatar banjerluke avatar chris-gong avatar justuswilhelm avatar stevenqzhang avatar mozfet avatar

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.