npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iron_worker

v0.1.8

Published

Node client for IronWorker

Downloads

186

Readme

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: