Skip to content
Browse files

Now support params[:key] in addition to @params[:key] and version bump.

  • Loading branch information...
1 parent 00b6c7b commit a41d6a025fb026a35b95fca544212f69af86efe8 Andrew Kirilenko committed Mar 21, 2012
Showing with 18 additions and 9 deletions.
  1. +7 −7 README.md
  2. +1 −1 VERSION
  3. +1 −1 iron_worker_ng.gemspec
  4. +9 −0 lib/iron_worker_ng/code/ruby.rb
View
14 README.md
@@ -7,10 +7,10 @@ Visit http://iron.io for more details.
You can just put any code into worker or can create class with name matching file name (e.g MyWorker class in my_worker.rb) and run method.
```ruby
-require 'active_record'
+require 'active_record' # just in case
-# @params hash is available here
# do something fun
+puts params[:foo]
```
## Create Runner
@@ -22,15 +22,15 @@ client = IronWorkerNG::Client.new('IRON_IO_TOKEN', 'IRON_IO_PROJECT_ID')
code = IronWorkerNG::Code::Ruby.new
code.merge_worker 'path/to/my_worker.rb'
-code.merge_gem 'activerecord'
+code.merge_gem 'activerecord' # we are using it in our worker
# you can use hash_string to check if you need to reupload code
# note that hash_string check is fast while code upload can take a while (depends on how much things you merged)
puts code.hash_string
client.codes.create(code)
-client.tasks.create('MyWorker', 'foo' => 'bar')
+client.tasks.create('MyWorker', :foo => 'bar')
```
## CLI
@@ -39,9 +39,9 @@ Iron Worker NG got nice CLI tool bundled. Here is small example how to get your
```sh
% cat my_worker.rb
-puts "I got some params - #{@params.inspect}"
+puts "my name is #{params[:name]} and it is #{params[:it]}"
% iron_worker_ng codes.create --ruby-merge-worker my_worker.rb
-% TASK_ID=`iron_worker_ng tasks.create -n MyWorker -p name,worker -p some,value --print-id`
+% TASK_ID=`iron_worker_ng tasks.create -n MyWorker -p name,worker -p it,fun --print-id`
% iron_worker_ng tasks.log -t $TASK_ID --live
-I got some params - {"name"=>"worker", "some"=>"value"}
+my name is worker and it is fun
```
View
2 VERSION
@@ -1 +1 @@
-0.1.7
+0.1.8
View
2 iron_worker_ng.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = "iron_worker_ng"
- s.version = "0.1.7"
+ s.version = "0.1.8"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Andrew Kirilenko", "Iron.io, Inc"]
View
9 lib/iron_worker_ng/code/ruby.rb
@@ -49,6 +49,15 @@ def log(*args)
@iron_io_project_id = parsed_payload['project_id']
@params = parsed_payload['params'] || {}
+keys = @params.keys
+keys.each do |key|
+ @params[key.to_sym] = @params[key]
+end
+
+def params
+ @params
+end
+
require worker_file_name
worker_class = nil

0 comments on commit a41d6a0

Please sign in to comment.
Something went wrong with that request. Please try again.