GithubHelp home page GithubHelp logo

vasilev / iron_worker_node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iron-io/iron_worker_node

0.0 1.0 0.0 42 KB

License: BSD 2-Clause "Simplified" License

Makefile 0.39% CoffeeScript 97.20% Shell 2.41%

iron_worker_node's Introduction

iron_worker_node is NODE.JS language binding for IronWorker.

IronWorker is a massively scalable background processing system. See How It Works

Getting Started

1. Install the gem:

npm install iron_worker

2. Setup your Iron.io credentials

3. Create an IronWorker Client object:

var iron_worker = require('iron_worker');
var worker = new iron_worker.Client();

Or pass in credentials:

var worker = new iron_worker.Client({token: "MY_TOKEN", project_id: "MY_PROJECT_ID"});

Creating a Worker

Here's an example worker:

console.log("Hello Node World!");

Upload code to server

Using CLI tool (preferred)

  • Get CLI tool
  • Download or create iron.json config file with project_id/password
  • Create HelloWorld.worker file, example:
runtime 'node'
exec 'HelloWorld.js'
  • Upload!
$ iron_worker upload HelloWorld

.worker syntax reference

Parsing payload, config within running worker

  • Add this library to list of dependencies (package.json):
  • Use it:
var iron_worker = require('iron_worker');
console.log(iron_worker.params());
console.log(iron_worker.config());
console.log(iron_worker.taskId());

Worker examples

You can find plenty of good worker examples here: iron_worker_examples

Queueing a Worker

worker.tasksCreate('HelloWorld', {}, {}, function(err,res){
  task_id = res.id;
  console.log("Pushed new task: task_id = "+task_id);
});

Worker should start in a few seconds.

If you need to pass some data you can use payload parameter

var payload = {first: 'Hello', second: 'World'};
var options = {priority: 1};
worker.tasksCreate('HelloWorld', payload, options, function(error, body) {});

Queueing Options

  • priority: Setting the priority of your job. Valid values are 0, 1, and 2. The default is 0.
  • timeout: The maximum runtime of your task in seconds. No task can exceed 3600 seconds (60 minutes). The default is 3600 but can be set to a shorter duration.
  • delay: The number of seconds to delay before actually queuing the task. Default is 0.
  • label: Optional text label for your task.
  • cluster: cluster name ex: "high-mem" or "dedicated". This is a premium feature for customers to have access to more powerful or custom built worker solutions. Dedicated worker clusters exist for users who want to reserve a set number of workers just for their queued tasks. If not set default is set to "default" which is the public IronWorker cluster.

Status of a Worker

To get the status of a task and other info, you can use the tasksGet() method.

worker.tasksCreate('HelloWorld', {}, {}, function(err,res){
  task_id = res.id;
  worker.tasksGet(task_id, function(error, res) {
    console.log("Full info about the task:\n"+JSON.stringify(res));
  });
});

Get Worker Log

Use any function that print text inside your worker to put messages to log.

worker.tasksCreate('HelloWorld', {}, {}, function(err,res){
  task_id = res.id;
  worker.tasksWaitForLog(task_id, {}, function (err, res) {
    worker.tasksLog(task_id, function (err, res) {console.log(res)});
  })
});

Scheduling a Worker

Like with tasksCreate

worker.schedulesCreate('HelloWorld', payload, {run_times: 10}, function(error, body) {});

Scheduling Options

  • run_every: The amount of time, in seconds, between runs. By default, the task will only run once. run_every will return a 400 error if it is set to less than 60.
  • end_at: The time tasks will stop being queued.
  • run_times: The number of times a task will run.
  • priority: Setting the priority of your job. Valid values are 0, 1, and 2. The default is 0. Higher values means tasks spend less time in the queue once they come off the schedule.
  • start_at: The time the scheduled task should first be run.
  • label: Optional text label for your task.
  • cluster: cluster name ex: "high-mem" or "dedicated".

Full Documentation

You can find more documentation here:

iron_worker_node's People

Contributors

alex-litvak avatar d-kononov avatar iced avatar jeroenpelgrims avatar juliangruber avatar pyeremenko avatar rkononov avatar sunloverz avatar thousandsofthem avatar treeder avatar

Watchers

 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.