iron_worker

Node client for IronWorker

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 IronMQ 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"});

Here's an example worker:

console.log("Hello Node World!");
  • 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

You can find plenty of good worker examples here: iron_worker_examples

var task_id = worker.tasksCreate('HelloWorld');

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(errorbody) {});
  • 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.

To get the status of a worker, you can use the tasksGet() method.

var task_id = worker.tasksCreate('HelloWorld');
worker.tasksGet(task_id, function(errorbody) {});

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

var task_id = worker.tasksCreate('HelloWorld');
worker.tasksWaitFor(task_id, function (errres) {
    worker.tasksLog(task_id, function (errres) {console.log(res)});
})

Like with tasksCreate

worker.schedulesCreate('HelloWorld', payload, {run_times: 10}, function(errorbody) {});
  • 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: