Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Next Gen Ruby gem for IronWorker
Ruby Shell PHP JavaScript Python Java

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


To run your code in cloud you need to do two things - upload code package to be executed and queue or schedule it for execution. While you can use REST APIs for that, it's always better to use IronWorker library created specificaly for your language of choice such as IronWorkerNG.

Preparing Environment

You'll need to register at and get your credintials to use IronWorkerNG. Each account can have unlimited number of project, so take advantage of it by creating separate projects for development, testing and production. Each project is identified by unique project_id and requiers access token to do any actions on it like uploading or queueing workers.

Also you'll need working ruby 1.9 interpreter and IronWorkerNG gem. Install it using following command.

gem install iron_worker_ng

It's recommended that you'll install typhoeus gem as well for faster API interaction.

gem install typhoeus

Creating Worker

IronWorkerNG ruby worker is common ruby code. It can be as simple as show below and as complex as you want.

puts "I'm worker"
puts "My task_id is #{@iron_worker_task_id}"
puts "I'm executing inside #{@iron_io_project_id} and was queued using #{@iron_io_token} token"
puts "I got '#{params}' parameters"

Everything your worker will output to stdout will be logged and available for your review when worker will finish execution.

Creating Code Package

As this code will be executed on the cloud, you'll need to supply it with all necessary gems and supplementary data. IronWorkerNG::Code::Ruby will help you to do this.

code =

code.merge_worker 'my_worker.rb'
code.merge_file '../lib/utils.rb'
code.merge_dir '../config'
code.merge_gem 'activerecord'

IronWorkerNG::Code::Ruby API

Please note that this API will help you to create code package but to upload it to IronWorker servers you'll need to use IronWorkerNG::Client API.

initialize(name = nil)

Will create new code package with specified name. If name is omited, camel-cased worker's file name will be used.

code =
code_with_name ='CoolWorker')


Will return code package name.



puts code.hash_string

Will return code package hash string. If you want prevent uploading unchanged code packages, you can use it to check if any changes were made. As it's verty efficient, it shouldn't cause any performace impact.

merge_file(path, dest = '')

code.merge_file '../config/database.yml' # will be in the same directory as worker
code.merge_file 'clients.csv', 'information/clients' # will be in information/clients subdirectory

Merges file located at path into the code package. You can use optional dest to set destination directory which will be automatically created.

merge_dir(path, dest = '')

Recursively merges directory located at path into the code package.

code.merge_dir '../config' # will be in the same directory as worker
code.merge_dir 'lib', 'utils' # will be in utils subdirectory, accessible as utils/lib

merge_worker(path, name = nil)

Merges worker located at path. If name is omited, camel-cased file name will be used. You can have only one worker merged per code package.

code.merge_worker 'my_worker.rb' # name will be MyWorker

merge_gem(name, version = '>= 0')

Merges gem with dependencies. Please note that gems which contains binary extensions will not be merged at the moment, however we have sane set of such gems preinstalled at IronWorker servers. You can use version constrains if you need specific gem version.

code.merge_gem 'activerecord'
code.merge_gem 'paperclip', '< 3.0.0,>= 2.1.0'

merge_gemfile(path, *groups)

Merges all gems from specified groups in Gemfile. Please note that it'll just merge gems and not auto require them when executing worker.

code.merge_gemfile '../Gemfile', 'common', 'worker' # merges gems from common and worker groups

Using IronWorker

When you have your code package you are ready to run it on IronWorker servers.

client = => IRON_IO_TOKEN', :project_id => 'IRON_IO_PROJECT_ID')
client.tasks.create('MyWorker', {:client => 'Joe'})

IronWorker::Client API

You can use IronWorkerNG::Client API to upload code packages, queue tasks, created schedules and more.

initialize(options = {})

Creates client object used for all interactions with IronWorker servers.

client = => 'IRON_IO_TOKEN', :project_id => 'IRON_IO_PROJECT_ID')

codes.list(options = {})

Returns array of information about uploaded codes. Visit for more information about options and code information object format. do |code|
  puts code.inspect


Returns information about uploaded code with specified code_id. Visit for more information about code information object format.



Uploads IronWorkerNG::Code::Ruby object to IronWorker servers.


Deletes code with specified code_id from IronWorker servers.'1234567890')

codes.revisions(code_id, options = {})

Returns array of revision information for code package with specified code_id. Visit for more information about options and revision information object.'1234567890').each do |revision|
  puts revision.inspect
end, options = {})

Download code package with specified id and returns it to you as array of bytes. Visit for more information about options.

data ='1234567890')

tasks.list(options = {})

Returns array of information about tasks. Visit for more information about options and task information object format.

client.tasks.list.each do |task|
  puts task.inspect


Returns information about task with specified task_id. Visit for more information about task information object format.

puts client.tasks.get('1234567890').code_name

tasks.create(code_name, params = {}, options = {})

Queues new task for code with specified code_name, passes params hash to it and returns task information object with only id field filled. Visit for more information about options.

task = client.tasks.create('MyWorker', {:client => 'Joe'}, {:delay => 180})


Cancels task with specified task_id.



Cancels all tasks for code package identified by specified code_id.



Returns full task log for task with specified task_id. Please note that log is available only when task completed execution.

puts client.tasks.log('1234567890')

tasks.set_progress(task_id, options = {})

Sets task progress information for task with specified task_id. Should be used from within worker to inform you about worker execution status which you'll get via tasks.get call. Visit for more information about options.

client.tasks.set_progress('1234567890', {:msg => 'Still running...'})

tasks.wait_for(task_id, options = {})

Waits while task identified by specified task_id executes. Options can containt :sleep parameter used to sleep between API invocations which defaults to 5 seconds. If block is provided, it'll be yielded after each API call with task information object as parameter.

client.tasks.wait_for('1234567890') do |task|
  puts task.msg

schedules.list(options = {})

Returns array of information about schedules. Visit for more information about options and schedule information object format.

client.schedules.list.each do |schedule|
  puts schedule.inspect


Returns information about schedule with specified schedule_id. Visit for more information about schedule information object format.

puts client.schedules.get('1234567890').last_run_time

schedules.create(code_name, params = {}, options = {})

Creates new schedule for code with specified code_name, passes params hash to it and returns schedule information object with only id field filled. Visit for more information about options.

schedule = client.schedules.create('MyWorker', {:client => 'Joe'}, {:start_at => + 3600})


Cancels schedule with specified schedule_id.

Something went wrong with that request. Please try again.