Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding simple example to cover more of ng

  • Loading branch information...
commit f19b59b7054842df43226370a781908703d0a4f3 1 parent 16511c9
Roman authored
1  Gemfile
View
@@ -13,4 +13,5 @@ end
group :test do
gem 'iron_worker_ng'
gem 'typhoeus'
+ gem 'pry'
end
10 Gemfile.lock
View
@@ -1,8 +1,9 @@
GEM
remote: http://rubygems.org/
specs:
+ coderay (1.0.6)
git (1.2.5)
- iron_worker_ng (0.1.14)
+ iron_worker_ng (0.2.0)
bundler (> 1.0.0)
json
rest
@@ -14,7 +15,12 @@ GEM
rake
rdoc
json (1.6.5)
+ method_source (0.7.1)
mime-types (1.18)
+ pry (0.9.8.4)
+ coderay (~> 1.0.5)
+ method_source (~> 0.7.1)
+ slop (>= 2.4.4, < 3)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
@@ -23,6 +29,7 @@ GEM
rest-client
rest-client (1.6.7)
mime-types (>= 1.16)
+ slop (2.4.4)
typhoeus (0.3.3)
mime-types
zip (2.0.2)
@@ -35,6 +42,7 @@ DEPENDENCIES
iron_worker_ng
jeweler (~> 1.8.3)
json
+ pry
rest
rest-client
typhoeus
5 examples/ruby/simple/Gemfile
View
@@ -0,0 +1,5 @@
+source 'http://rubygems.org'
+
+group :extra do
+ gem 'pry'
+end
3  examples/ruby/simple/sample_worker.rb
View
@@ -0,0 +1,3 @@
+require 'pry'
+require 'jeweler'
+puts "hello"
66 examples/ruby/simple/simple.rb
View
@@ -0,0 +1,66 @@
+require 'iron_worker_ng'
+
+# to run examples, you must specify iron.io authentication token and project id
+token, project_id = [ ENV['IRON_IO_TOKEN'], ENV['IRON_IO_PROJECT_ID'] ]
+raise("please set $IRON_IO_TOKEN and $IRON_IO_PROJECT_ID " +
+ "environment variables") unless token and project_id
+
+IronWorkerNG::Logger.logger.level = ::Logger::DEBUG
+
+# initializing api object with them
+client = IronWorkerNG::Client.new(:token => token,
+ :project_id => project_id,
+ # rest are optinal
+ :scheme => 'https',
+ :port => 443,
+ :api_version => 2,
+ :host => 'worker-aws-us-east-1.iron.io')
+
+# creating code bundle
+
+# if not specified, name default to worker name converted from underscore to camel style
+code = IronWorkerNG::Code::Ruby.new
+code.merge_worker('/sample_worker.rb')
+#> code.name == 'SampleWorker'
+
+# still can pass name in constructor
+code = IronWorkerNG::Code::Ruby.new('transmogrify')
+#> code.name == 'transmogrify'
+code.merge_worker(File.dirname(__FILE__) + '/sample_worker.rb')
+
+# once worker merged, following attempts will be ignored
+code.merge_worker('anything')
+#> code.worker.path.end_with? '/worker.rb'
+
+# if worker requires some gems, we
+
+# we can specify worker dependency on gem
+code.merge_gem('jeweler')
+# or on Gemfile, which is recommended
+code.merge_gemfile(File.dirname(__FILE__) + '/Gemfile',
+ :default, :extra)
+# all those dependencies will be resolved using bundler gem
+
+# upload code bundle to iron.io
+client.codes_create(code)
+
+# we can retrive code packages list
+codes = client.codes_list
+#> codes.map{|c| c.name}.include?('transmogrify')
+
+code_info = codes.find{|c| c.name == 'transmogrify'}
+# other way to get such info is codes.get:
+same_code_info = client.codes_get(code_info.id)
+#> same_code_info == code_info
+
+# create task to run the bundle
+task_id = client.tasks_create('transmogrify').id
+
+# wait for the task to finish
+client.tasks_wait_for(task_id)
+
+# retriving task log
+log = client.tasks_log(task_id) #> log == "hello\n" -- worker stdout is in log
+
+# cleanup
+client.codes_delete(code_info.id)
Please sign in to comment.
Something went wrong with that request. Please try again.