Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into new_config_param

Conflicts:
	Gemfile.lock
  • Loading branch information...
commit 5873877c103529a3fea4cd2221f553333b038d98 2 parents 1f787fb + d65a45d
@treeder treeder authored
Showing with 422 additions and 270 deletions.
  1. +3 −0  .gitignore
  2. +29 −8 Gemfile.lock
  3. +10 −0 README.md
  4. +11 −0 examples/actionmailer_standalone/README.md
  5. +8 −0 examples/actionmailer_standalone/actionmailer_config_sample.json
  6. +4 −0 examples/actionmailer_standalone/actionmailer_standalone.worker
  7. +0 −8 examples/actionmailer_standalone/enqueue.rb
  8. +0 −14 examples/actionmailer_standalone/upload.rb
  9. +13 −10 examples/chargify_to_campfire_webhook_worker/README.md
  10. +5 −0 examples/chargify_to_campfire_webhook_worker/campfire_config_sample.json
  11. +4 −0 examples/chargify_to_campfire_webhook_worker/chargify_to_campfire.worker
  12. +10 −16 examples/chargify_to_campfire_webhook_worker/chargify_to_campfire_webhook_worker.rb
  13. +0 −19 examples/chargify_to_campfire_webhook_worker/upload.rb
  14. +0 −4 examples/chargify_to_campfire_webhook_worker/webhook_config_example.yml
  15. +7 −8 examples/email_worker/README.md
  16. +26 −0 examples/email_worker/email_config_sample.json
  17. +28 −74 examples/email_worker/email_worker.rb
  18. +0 −26 examples/email_worker/single_email_sender.rb
  19. +5 −2 iron_worker_ng.gemspec
  20. +15 −14 lib/iron_worker_ng.rb
  21. +13 −13 lib/iron_worker_ng/cli.rb
  22. +37 −18 lib/iron_worker_ng/client.rb
  23. +10 −10 lib/iron_worker_ng/code/base.rb
  24. +1 −1  lib/iron_worker_ng/code/binary.rb
  25. +1 −1  lib/iron_worker_ng/code/builder.rb
  26. +1 −1  lib/iron_worker_ng/code/go.rb
  27. +1 −1  lib/iron_worker_ng/code/java.rb
  28. +1 −1  lib/iron_worker_ng/code/mono.rb
  29. +1 −1  lib/iron_worker_ng/code/node.rb
  30. +1 −1  lib/iron_worker_ng/code/perl.rb
  31. +1 −1  lib/iron_worker_ng/code/php.rb
  32. +1 −1  lib/iron_worker_ng/code/python.rb
  33. +1 −1  lib/iron_worker_ng/code/ruby.rb
  34. +1 −1  lib/iron_worker_ng/code/runtime/java.rb
  35. +3 −3 lib/iron_worker_ng/code/runtime/python.rb
  36. +3 −3 lib/iron_worker_ng/code/runtime/ruby.rb
  37. +16 −0 lib/iron_worker_ng/compat.rb
  38. +7 −2 lib/iron_worker_ng/feature/python/merge_pip.rb
  39. +8 −4 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
  40. +1 −1  lib/iron_worker_ng/version.rb
  41. +19 −0 test/examples/README.md
  42. +36 −0 test/examples/test_example_actionmailer_standalone.rb
  43. +24 −0 test/examples/test_example_chargify_to_campfire_webhook.rb
  44. +54 −0 test/examples/test_example_email_worker.rb
  45. +1 −1  test/hello.rb
  46. +1 −1  test/quick_run.rb
View
3  .gitignore
@@ -5,3 +5,6 @@ pkg
iron.json
examples/github_to_hipchat_webhook_worker/webhook_config.yml
examples/worker101/twitter_config.json
+examples/actionmailer_standalone/actionmailer_config.json
+examples/chargify_to_campfire_webhook_worker/campfire_config.json
+examples/email_worker/email_config.json
View
37 Gemfile.lock
@@ -1,45 +1,66 @@
PATH
remote: .
specs:
- iron_worker_ng (0.14.0)
+ iron_worker_ng (0.15.0)
bundler (>= 1.2.0)
- iron_core (>= 0.4.2)
+ iron_core (>= 0.5.1)
rubyzip (>= 0.9.9)
GEM
remote: https://rubygems.org/
specs:
+ actionmailer (2.3.15)
+ actionpack (= 2.3.15)
+ actionpack (2.3.15)
+ activesupport (= 2.3.15)
+ rack (~> 1.1.3)
+ activesupport (2.3.15)
ansi (1.4.3)
builder (3.1.4)
+ faraday (0.8.4)
+ multipart-post (~> 1.1)
hashie (1.2.0)
- iron_core (0.4.4)
- rest (>= 2.1.1)
+ iron_cache (1.4.0)
+ iron_core (>= 0.5.1)
+ iron_core (0.5.1)
+ rest (>= 2.2.0)
mime-types (1.19)
- minitest (4.3.3)
- minitest-reporters (0.13.1)
+ minitest (4.4.0)
+ minitest-reporters (0.14.3)
ansi
builder
minitest (>= 2.12, < 5.0)
powerbar
+ multi_json (1.5.0)
+ multipart-post (1.1.5)
net-http-persistent (2.8)
powerbar (1.0.11)
ansi (~> 1.4.0)
hashie (>= 1.1.0)
- rake (10.0.2)
- rest (2.1.1)
+ rack (1.1.5)
+ rake (10.0.3)
+ rest (2.2.0)
net-http-persistent
rest-client (>= 0.3.0)
rest-client (1.6.7)
mime-types (>= 1.16)
rubyzip (0.9.9)
+ simple_oauth (0.2.0)
test-unit (2.5.3)
+ twitter (4.4.4)
+ faraday (~> 0.8, < 0.10)
+ multi_json (~> 1.0)
+ simple_oauth (~> 0.2)
PLATFORMS
ruby
DEPENDENCIES
+ actionmailer
+ iron_cache (>= 1.4.0)
iron_worker_ng!
minitest
minitest-reporters (>= 0.5.0)
rake
test-unit
+ twitter
View
10 README.md
@@ -340,6 +340,16 @@ Merge the exec located at `path`.
code.merge_exec 'my_worker.py'
```
+### merge_pip(name, version = '')
+### pip(name, version = '')
+
+Merge a pip package with dependencies. If any pip package contains native extensions, switch to full remote build. You can use version constrains if you need a specific pip package version.
+
+```ruby
+code.merge_pip 'iron_mq'
+code.merge_pip 'iron_worker', '0.2'
+```
+
# Upload Your Worker
When you have your code package, you are ready to upload and run it on the IronWorker cloud.
View
11 examples/actionmailer_standalone/README.md
@@ -0,0 +1,11 @@
+# action_mailer example
+
+This example shows how to send emails in worker.
+
+1. Be sure you've setup your Iron.io credentials, see main [README.md](https://github.com/iron-io/iron_worker_examples).
+2. Copy `actionmailer_config_sample.json` to `actionmailer_config.json` and edit it to set your gmail credentials.
+3. Run `iron_worker upload actionmailer_standalone` to upload worker.
+4. Run `iron_worker queue actionmailer_standalone --payload-file actionmailer_config.json`
+5. Look at [HUD](https://hud.iron.io) to view your tasks running, check logs, etc.
+
+Read the code in this directory to learn more about what happened.
View
8 examples/actionmailer_standalone/actionmailer_config_sample.json
@@ -0,0 +1,8 @@
+{
+ "gmail": {
+ "username": "you@gmail.com",
+ "password": "yourpwd"
+ },
+ "from": "you@gmail.com",
+ "to": ["you@gmail.com"]
+}
View
4 examples/actionmailer_standalone/actionmailer_standalone.worker
@@ -0,0 +1,4 @@
+exec 'actionmailer_worker.rb'
+file 'mailer.rb'
+dir 'mailer'
+gem 'actionmailer'
View
8 examples/actionmailer_standalone/enqueue.rb
@@ -1,8 +0,0 @@
-require 'iron_worker_ng'
-require_relative '../../ruby/examples_helper'
-
-config = ExamplesHelper.load_config
-
-client = IronWorkerNG::Client.new(:token => config['iw']['token'], :project_id => config['iw']['project_id'])
-
-client.tasks.create('ActionmailerWorker', :gmail => config['gmail'], :from => 'andrew@iron.io', :to => ['andrew@iron.io']) # I like receiving mails
View
14 examples/actionmailer_standalone/upload.rb
@@ -1,14 +0,0 @@
-require 'iron_worker_ng'
-require_relative '../../ruby/examples_helper'
-
-config = ExamplesHelper.load_config
-
-client = IronWorkerNG::Client.new(:token => config['iw']['token'], :project_id => config['iw']['project_id'])
-
-code = IronWorkerNG::Code::Ruby.new
-code.merge_worker 'actionmailer_worker.rb'
-code.merge_file 'mailer.rb' # merging mailer...
-code.merge_dir 'mailer' # ...and templates
-code.merge_gem 'actionmailer' # we need actionmailer gem merged as well
-
-client.codes.create(code)
View
23 examples/chargify_to_campfire_webhook_worker/README.md
@@ -1,13 +1,16 @@
-# Github Webhook Worker
+# Chargify Webhook Worker
-This shows how to kick off a worker from a webhook. This example uses Github's Service Hooks.
+This shows how to kick off a worker from a webhook. This example uses Chargify's webhooks.
-## Getting started
+1. Be sure you've setup your Iron.io credentials, see main [README.md](https://github.com/iron-io/iron_worker_examples).
+1. Copy or rename the campfire_config_example.json to campfire_config.json and edit it to set your campfire credentials.
+1. `iron_worker upload chargify_to_campfire`
+1. See webhook url `iron_worker webhook chargify_to_campfire`
+1. Set it in chargify (Settings -> Webhooks)
+1. Select types of events you want to be notified of.
+1. Click 'Save Webhook settings'
+1. Click 'Send a test Webhook'
+1. Check the worker status and logs in IronWorker at http://hud.iron.io to ensure it ran successfully.
+1. Check campfire for messages from webhook.
-- Copy or rename the webhook_config_example.yml to webhook_config.yml and edit it to set your hipchat credentials.
-- Upload the worker by running `upload.rb` in this directory and follow instruction it prints
-- Click Update Settings
-- Click Test Hook
-- Check the worker status and logs in IronWorker at http://hud.iron.io to ensure it ran successfully.
-
-That's it, now everytime someone pushes to your github repo, it'll execute the GithubWebhookWorker on IronWorker.
+That's it, now you'll be notified about selected chargify events in campfire.
View
5 examples/chargify_to_campfire_webhook_worker/campfire_config_sample.json
@@ -0,0 +1,5 @@
+{
+ "account": "sample",
+ "token": "12462462460f3456a3571e0456a7c5845f774674",
+ "room": "Room 1"
+}
View
4 examples/chargify_to_campfire_webhook_worker/chargify_to_campfire.worker
@@ -0,0 +1,4 @@
+exec 'chargify_to_campfire_webhook_worker.rb'
+gem 'broach'
+file 'campfire_config.json'
+full_remote_build true
View
26 examples/chargify_to_campfire_webhook_worker/chargify_to_campfire_webhook_worker.rb
@@ -1,27 +1,21 @@
require 'cgi'
-require 'yaml'
require 'broach'
# the payload we get from github needs to be decoded first
cgi_parsed = CGI::parse(payload)
puts "cgi_parsed: #{cgi_parsed.inspect}"
-# Then we can parse the json
-#parsed = JSON.parse(cgi_parsed)
-#puts "parsed: #{parsed.inspect}"
-parsed = cgi_parsed # seems to already be in a hash?
+event = cgi_parsed["event"][0]
-@event = parsed["event"][0]
-
-# Also parse the config we uploaded with this worker for our Hipchat stuff
-webhook_config = YAML.load_file('webhook_config.yml')
-puts "webhook_config: #{webhook_config.inspect}"
-
-campfire_config = webhook_config['campfire']
+# parse campfire config
+cfg = JSON.parse(File.read('campfire_config.json'))
+puts "campfire config: #{cfg.inspect}"
Broach.settings = {
- 'account' => campfire_config['account'],
- 'token' => campfire_config['token'],
- 'use_ssl' => true
+ 'account' => cfg['account'],
+ 'token' => cfg['token'],
+ 'use_ssl' => true
}
-Broach.speak(campfire_config['room'], @event)
+Broach.speak(cfg['room'], event)
+
+puts 'Done'
View
19 examples/chargify_to_campfire_webhook_worker/upload.rb
@@ -1,19 +0,0 @@
-require 'iron_worker_ng'
-require_relative '../../ruby/examples_helper'
-config = ExamplesHelper.load_config
-
-# Create an IronWorker client
-client = IronWorkerNG::Client.new(:token => config['iw']['token'], :project_id => config['iw']['project_id'])
-
-# Create our code package containing the webhook
-code = IronWorkerNG::Code::Ruby.new(:exec=>'chargify_to_campfire_webhook_worker.rb')
-code.merge_file 'webhook_config.yml'
-code.merge_gem 'broach'
-
-# Upload the code package
-client.codes.create(code)
-
-url = "https://worker-aws-us-east-1.iron.io/2/projects/#{config['iw']['project_id']}/tasks/webhook?code_name=#{code.name}&oauth=#{config['iw']['token']}"
-
-puts "Add the following url to Github Service Hooks, Post Receive URLs: "
-puts url
View
4 examples/chargify_to_campfire_webhook_worker/webhook_config_example.yml
@@ -1,4 +0,0 @@
-campfire:
- account: "account number"
- token: "token"
- room: "room name"
View
15 examples/email_worker/README.md
@@ -1,13 +1,12 @@
-# email_worker
+# email_worker example
This is simple example how to send email using IronWorker
-Command line tool reference could be found here - http://dev.iron.io/worker/reference/cli/
-## Getting started
-
-- Edit _config.yml (iw and email sections)
-- Upload the worker by running 'iron_worker upload email_worker' in this directory
-- run 'single_email_sender.rb'
+1. Be sure you've setup your Iron.io credentials, see main [README.md](https://github.com/iron-io/iron_worker_examples).
+2. Copy `email_config_sample.json` to `email_config.json` and edit it to set your credentials.
+3. Run `iron_worker upload email_worker` to upload worker.
+4. Run `iron_worker queue email_worker --payload-file email_config.json`
+5. Look at [HUD](https://hud.iron.io) to view your tasks running, check logs, etc.
That's it, now you should receive email.
-
+Read the code in this directory to learn more about what happened.
View
26 examples/email_worker/email_config_sample.json
@@ -0,0 +1,26 @@
+{
+ "smtp": {
+ "user_name": "you@gmail.com",
+ "password": "secret",
+ "enable_starttls_auto": true,
+ "authentication": "plain",
+ "address": "smtp.gmail.com",
+ "port": 587
+ // "address": "smtp.sendgrid.net",
+ // "port": 25
+ },
+
+ // uncomment and edit to put email details on iron_cache
+ // "iron": {
+ // "token": "Et1E98729890283837Fu34L3234",
+ // "project_id": "523412343249345435342349"
+ // },
+
+ // uncomment and edit to send email detail via http api
+ // "endpoint": "www.myservice.com/api/email_sent",
+
+ "from": "you@gmail.com",
+ "to": "you@gmail.com",
+ "subject": "hello from IronWorker",
+ "body": "hello me"
+}
View
102 examples/email_worker/email_worker.rb
@@ -1,87 +1,41 @@
-# Configures smtp settings to send email.
-def init_mail(username, password, domain, provider)
- puts "initializing provider"
- case provider
- when 'gmail'
- puts "Selected gmail as a provider"
- port = 587
- address = "smtp.gmail.com"
- when 'sendgrid'
- puts "Selected sendgrid as a provider"
- port = 25
- address = "smtp.sendgrid.net"
- end
- puts "Preparing mail configuration"
- mail_conf = {:address => address,
- :port => port,
- :domain => domain, #custom domain
- :user_name => username,
- :password => password,
- :authentication => 'plain',
- :enable_starttls_auto => true} #gmail require this option
- Mail.defaults do
- delivery_method :smtp, mail_conf
- end
- puts "Mail service configured"
+require 'mail'
+require 'rest'
+require 'iron_cache'
+
+# 'params' name is used in Mail widely
+pars = JSON.parse(payload, symbolize_names: true)
+
+# Configure smtp settings to send email.
+Mail.defaults do
+ delivery_method :smtp, pars[:smtp]
end
-def send_mail(to, from, subject, content)
- puts "Preparing email from:#{from},to:#{to},subject#{subject}"
+[pars[:to]].flatten.each do |to|
msg = Mail.new do
to to
- from from
- subject subject
- html_part do |m|
- content_type 'text/html'
- body content
- end
+ from pars[:from]
+ subject pars[:subject]
+ body pars[:body]
end
- puts "Mail ready, delivering"
details = msg.deliver
- puts "Mail delivered!"
- details
-end
-def update_message_status(email, message_details)
- puts "Updating user status via API endpoint"
- puts "Email:#{email},details:#{message_details.inspect}"
+ puts "email:#{to}, details:#{details.to_s}"
- #here is the example how you could send email details from this worker to your api
- require 'rest'
- puts "initializing client"
- web_client = Rest::Client.new # res gem already merged
- puts "sending api request"
- #just change google.com on your api endpoint
- web_client.get('http://google.com', {:email => email, :message_details => message_details})
-
- # or put email details in iron_cache
- if params['iw_token'] && params['iw_project_id']
- puts "Initializing cache"
- require 'iron_cache'
- cache = IronCache::Client.new(:token => params['iw_token'], :project_id => params['iw_project_id'])
- puts "Sending message details to cache"
- cache.items.put(email, {:timestamp => Time.now, :message_details => message_details.inspect}.to_json)
+ if pars[:endpoint]
+ # here is the example how you could send email details from this worker to your api
+ puts "initializing client"
+ web_client = Rest::Client.new
+ puts "sending api request"
+ web_client.get(pars[:endpoint], email: to, details: details.to_s)
end
-end
-
-# Sample worker that sends an email.
-puts "Worker started"
-
-require 'mail'
-
-init_mail(params['username'], params['password'], params['domain'], params['provider'])
-
-
-if params['to'].is_a? Array # check what is passed one email or array of emails
- puts "Array of #{params['to'].count} emails passed"
- params['to'].each do |email|
- message_details = send_mail(email, params['from'], params['subject'], params['content'])
- update_message_status(email, message_details)
+ # or put email details in iron_cache
+ if pars[:iron]
+ puts "initializing cache"
+ cache = IronCache::Client.new(pars[:iron])
+ puts "sending message details to cache"
+ cache.items.put(to, details.to_s)
end
-else
- message_details = send_mail(params['to'], params['from'], params['subject'], params['content'])
- update_message_status(email, message_details)
end
-puts "Worker finished"
+puts "worker finished"
View
26 examples/email_worker/single_email_sender.rb
@@ -1,26 +0,0 @@
-require 'yaml'
-require 'iron_worker_ng'
-
-# loading config from config file
-config_data = YAML.load_file '../../ruby/_config.yml'
-#also you could just create iron.json config file in your home directory and don't load anything
-
-# Create an IronWorker client
-client = IronWorkerNG::Client.new(:token => config_data['iw']['token'], :project_id => config_data['iw']['project_id'])
-
-email = config_data['email']
-#general params
-params = {:username => email['username'],
- :password => email['password'],
- :domain => email['domain'],
- :provider => 'gmail'
-}
-#individual params
-params.merge!({
- :from => email['from'],
- :to => [email['to'],email['to']],
- :subject => 'sample',
- :content => 'HEY ITs a body'
- })
-#launching worker
-client.tasks.create("email_worker", params)
View
7 iron_worker_ng.gemspec
@@ -14,9 +14,9 @@ Gem::Specification.new do |gem|
gem.version = IronWorkerNG::VERSION
gem.required_rubygems_version = '>= 1.3.6'
- gem.required_ruby_version = Gem::Requirement.new('>= 1.9')
+ gem.required_ruby_version = Gem::Requirement.new('>= 1.8')
- gem.add_runtime_dependency 'iron_core', '>= 0.4.2'
+ gem.add_runtime_dependency 'iron_core', '>= 0.5.1'
gem.add_runtime_dependency 'bundler', '>= 1.2.0'
gem.add_runtime_dependency 'rubyzip', '>= 0.9.9'
@@ -24,4 +24,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'minitest'
gem.add_development_dependency 'minitest-reporters', '>= 0.5.0'
gem.add_development_dependency 'rake'
+ gem.add_development_dependency 'twitter'
+ gem.add_development_dependency 'actionmailer'
+ gem.add_development_dependency 'iron_cache', '>= 1.4.0'
end
View
29 lib/iron_worker_ng.rb
@@ -1,14 +1,15 @@
-require_relative 'iron_worker_ng/version'
-require_relative 'iron_worker_ng/fetcher'
-require_relative 'iron_worker_ng/client'
-require_relative 'iron_worker_ng/code/base'
-require_relative 'iron_worker_ng/code/ruby'
-require_relative 'iron_worker_ng/code/binary'
-require_relative 'iron_worker_ng/code/java'
-require_relative 'iron_worker_ng/code/node'
-require_relative 'iron_worker_ng/code/mono'
-require_relative 'iron_worker_ng/code/python'
-require_relative 'iron_worker_ng/code/php'
-require_relative 'iron_worker_ng/code/go'
-require_relative 'iron_worker_ng/code/perl'
-require_relative 'iron_worker_ng/code/builder'
+require 'iron_worker_ng/version'
+require 'iron_worker_ng/compat'
+require 'iron_worker_ng/fetcher'
+require 'iron_worker_ng/client'
+require 'iron_worker_ng/code/base'
+require 'iron_worker_ng/code/ruby'
+require 'iron_worker_ng/code/binary'
+require 'iron_worker_ng/code/java'
+require 'iron_worker_ng/code/node'
+require 'iron_worker_ng/code/mono'
+require 'iron_worker_ng/code/python'
+require 'iron_worker_ng/code/php'
+require 'iron_worker_ng/code/go'
+require 'iron_worker_ng/code/perl'
+require 'iron_worker_ng/code/builder'
View
26 lib/iron_worker_ng/cli.rb
@@ -44,7 +44,7 @@ def client
project = client.projects.get
- log "Project '#{project.name}' with id='#{project.id}'"
+ log "Project '#{project.name}' with id='#{project._id}'"
end
@client
@@ -78,7 +78,7 @@ def upload(name, params, options)
log 'Code package is building'
log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{builder_task_id}' for more info"
else
- code_id = client.codes.create(code, options).id
+ code_id = client.codes.create(code, options)._id
code_info = client.codes.get(code_id)
log "Code package uploaded with id='#{code_id}' and revision='#{code_info.rev}'"
@@ -91,7 +91,7 @@ def queue(name, params, options)
log_group "Queueing task"
- id = client.tasks.create(name, params[:payload] || params['payload'], options).id
+ id = client.tasks.create(name, params[:payload] || params['payload'], options)._id
log "Code package '#{name}' queued with id='#{id}'"
log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{id}' for more info"
@@ -102,7 +102,7 @@ def schedule(name, params, options)
log_group "Scheduling task"
- id = client.schedules.create(name, params[:payload] || params['payload'], options).id
+ id = client.schedules.create(name, params[:payload] || params['payload'], options)._id
log "Code package '#{name}' scheduled with id='#{id}'"
log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/scheduled_jobs/#{id}' for more info"
@@ -113,7 +113,7 @@ def retry(task_id, params, options)
log_group "Retrying task with id='#{task_id}'"
- retry_task_id = client.tasks.retry(task_id, options).id
+ retry_task_id = client.tasks.retry(task_id, options)._id
log "Task retried with id='#{retry_task_id}'"
log "Check 'https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{retry_task_id}' for more info"
@@ -202,20 +202,20 @@ def info_code(name, params, options)
code = codes.find { |code| code.name == name }
unless code
- log_name "Code package with name='#{name}' not found"
+ log "Code package with name='#{name}' not found"
exit 1
end
data = []
- data << ['id', code.id]
+ data << ['id', code._id]
data << ['name', code.name]
data << ['revision', code.rev]
data << ['uploaded', parse_time(code.latest_change) || '-']
data << ['max concurrency', code.max_concurrency || '-']
data << ['retries', code.retries || '-']
data << ['retries delay', code.retries_delay || '-']
- data << ['info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code.id}"]
- data << ['tasks info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{code.id}/activity"]
+ data << ['info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/code/#{code._id}"]
+ data << ['tasks info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{code._id}/activity"]
display_table(data)
end
@@ -228,7 +228,7 @@ def info_task(task_id, params, options)
task = client.tasks.get(task_id)
data = []
- data << ['id', task.id]
+ data << ['id', task._id]
data << ['code package', task.code_name]
data << ['code revision', task.code_rev]
data << ['status', task.status]
@@ -237,7 +237,7 @@ def info_task(task_id, params, options)
data << ['started', parse_time(task.start_time) || '-']
data << ['finished', parse_time(task.end_time) || '-']
data << ['payload', task.payload]
- data << ['info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{task.id}"]
+ data << ['info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/jobs/#{task._id}"]
display_table(data)
end
@@ -250,14 +250,14 @@ def info_schedule(schedule_id, params, options)
schedule = client.schedules.get(schedule_id)
data = []
- data << ['id', schedule.id]
+ data << ['id', schedule._id]
data << ['code package', schedule.code_name]
data << ['status', schedule.status]
data << ['created', parse_time(schedule.created_at) || '-']
data << ['next start', parse_time(schedule.next_start) || '-']
data << ['run count', schedule.run_count || '-']
data << ['payload', schedule.payload]
- data << ['info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/scheduled_jobs/#{schedule.id}"]
+ data << ['info', "https://hud.iron.io/tq/projects/#{client.api.project_id}/scheduled_jobs/#{schedule._id}"]
display_table(data)
end
View
55 lib/iron_worker_ng/client.rb
@@ -2,7 +2,7 @@
require 'json'
require 'base64'
-require_relative 'api_client'
+require 'iron_worker_ng/api_client'
module IronWorkerNG
class ClientProxyCaller
@@ -74,14 +74,16 @@ def codes_list(options = {})
result
else
- @api.codes_list(options)['codes'].map { |c| OpenStruct.new(c) }
+ @api.codes_list(options)['codes'].map { |c| OpenStruct.new(c.merge('_id' => c['id'])) }
end
end
def codes_get(code_id)
IronCore::Logger.debug 'IronWorkerNG', "Calling codes.get with code_id='#{code_id}'"
- OpenStruct.new(@api.codes_get(code_id))
+ c = @api.codes_get(code_id)
+ c['_id'] = c['id']
+ OpenStruct.new(c)
end
def codes_create(code, options = {})
@@ -97,16 +99,16 @@ def codes_create(code, options = {})
if code.remote_build_command.nil? && (not code.full_remote_build)
res = @api.codes_create(code.name, container_file, 'sh', '__runner__.sh', options)
else
- builder_code_name = code.name + (code.name[0].upcase == code.name[0] ? '::Builder' : '::builder')
+ builder_code_name = code.name + (code.name[0 .. 0].upcase == code.name[0 .. 0] ? '::Builder' : '::builder')
@api.codes_create(builder_code_name, container_file, 'sh', '__runner__.sh', options)
builder_task = tasks.create(builder_code_name, :code_name => code.name, :client_options => @api.options.to_json, :codes_create_options => options.to_json)
- builder_task = tasks.wait_for(builder_task.id)
+ builder_task = tasks.wait_for(builder_task._id)
if builder_task.status != 'complete'
- log = tasks.log(builder_task.id)
+ log = tasks.log(builder_task._id)
File.unlink(container_file)
@@ -118,6 +120,7 @@ def codes_create(code, options = {})
File.unlink(container_file)
+ res['_id'] = res['id']
OpenStruct.new(res)
end
@@ -129,7 +132,7 @@ def codes_create_async(code, options = {})
if code.remote_build_command.nil? && (not code.full_remote_build)
res = @api.codes_create(code.name, container_file, 'sh', '__runner__.sh', options)
else
- builder_code_name = code.name + (code.name[0].upcase == code.name[0] ? '::Builder' : '::builder')
+ builder_code_name = code.name + (code.name[0 .. 0].upcase == code.name[0 .. 0] ? '::Builder' : '::builder')
@api.codes_create(builder_code_name, container_file, 'sh', '__runner__.sh', options)
@@ -137,11 +140,12 @@ def codes_create_async(code, options = {})
File.unlink(container_file)
- return builder_task.id
+ return builder_task._id
end
File.unlink(container_file)
+ res['_id'] = res['id']
OpenStruct.new(res)
end
@@ -156,7 +160,7 @@ def codes_delete(code_id)
def codes_revisions(code_id, options = {})
IronCore::Logger.debug 'IronWorkerNG', "Calling codes.revisions with code_id='#{code_id}' and options='#{options.to_s}'"
- @api.codes_revisions(code_id, options)['revisions'].map { |c| OpenStruct.new(c) }
+ @api.codes_revisions(code_id, options)['revisions'].map { |c| OpenStruct.new(c.merge('_id' => c['id'])) }
end
def codes_download(code_id, options = {})
@@ -168,13 +172,15 @@ def codes_download(code_id, options = {})
def tasks_list(options = {})
IronCore::Logger.debug 'IronWorkerNG', "Calling tasks.list with options='#{options.to_s}'"
- @api.tasks_list(options)['tasks'].map { |t| OpenStruct.new(t) }
+ @api.tasks_list(options)['tasks'].map { |t| OpenStruct.new(t.merge('_id' => t['id'])) }
end
def tasks_get(task_id)
IronCore::Logger.debug 'IronWorkerNG', "Calling tasks.get with task_id='#{task_id}'"
- OpenStruct.new(@api.tasks_get(task_id))
+ t = @api.tasks_get(task_id)
+ t['_id'] = t['id']
+ OpenStruct.new(t)
end
def tasks_create(code_name, params = {}, options = {})
@@ -182,7 +188,9 @@ def tasks_create(code_name, params = {}, options = {})
res = @api.tasks_create(code_name, params.is_a?(String) ? params : params.to_json, options)
- OpenStruct.new(res['tasks'][0])
+ t = res['tasks'][0]
+ t['_id'] = t['id']
+ OpenStruct.new(t)
end
def tasks_create_legacy(code_name, params = {}, options = {})
@@ -190,7 +198,9 @@ def tasks_create_legacy(code_name, params = {}, options = {})
res = @api.tasks_create(code_name, params_for_legacy(code_name, params), options)
- OpenStruct.new(res['tasks'][0])
+ t = res['tasks'][0]
+ t['_id'] = t['id']
+ OpenStruct.new(t)
end
def tasks_cancel(task_id)
@@ -244,7 +254,9 @@ def tasks_retry(task_id, options = {})
res = @api.tasks_retry(task_id, options)
- OpenStruct.new(res['tasks'][0])
+ t = res['tasks'][0]
+ t['_id'] = t['id']
+ OpenStruct.new(t)
end
def schedules_list(options = {})
@@ -256,7 +268,9 @@ def schedules_list(options = {})
def schedules_get(schedule_id)
IronCore::Logger.debug 'IronWorkerNG', "Calling schedules.get with schedule_id='#{schedule_id}"
- OpenStruct.new(@api.schedules_get(schedule_id))
+ s = @api.schedules_get(schedule_id)
+ s['_id'] = s['id']
+ OpenStruct.new(s)
end
def schedules_create(code_name, params = {}, options = {})
@@ -264,7 +278,9 @@ def schedules_create(code_name, params = {}, options = {})
res = @api.schedules_create(code_name, params.is_a?(String) ? params : params.to_json, options)
- OpenStruct.new(res['schedules'][0])
+ s = res['schedules'][0]
+ s['_id'] = s['id']
+ OpenStruct.new(s)
end
def schedules_create_legacy(code_name, params = {}, options = {})
@@ -272,7 +288,9 @@ def schedules_create_legacy(code_name, params = {}, options = {})
res = @api.schedules_create(code_name, params_for_legacy(code_name, params), options)
- OpenStruct.new(res['schedules'][0])
+ s = res['schedules'][0]
+ s['_id'] = s['id']
+ OpenStruct.new(s)
end
def schedules_cancel(schedule_id)
@@ -286,8 +304,9 @@ def schedules_cancel(schedule_id)
def projects_get
IronCore::Logger.debug 'IronWorkerNG', "Calling projects.get"
- res =@api.projects_get
+ res = @api.projects_get
+ res['_id'] = res['id']
OpenStruct.new(res)
end
View
20 lib/iron_worker_ng/code/base.rb
@@ -1,13 +1,13 @@
require 'fileutils'
-require_relative 'container/base'
-require_relative 'container/zip'
-require_relative 'container/dir'
-require_relative '../feature/base'
-require_relative '../feature/common/merge_exec'
-require_relative '../feature/common/merge_file'
-require_relative '../feature/common/merge_dir'
-require_relative '../feature/common/merge_deb'
+require 'iron_worker_ng/code/container/base'
+require 'iron_worker_ng/code/container/zip'
+require 'iron_worker_ng/code/container/dir'
+require 'iron_worker_ng/feature/base'
+require 'iron_worker_ng/feature/common/merge_exec'
+require 'iron_worker_ng/feature/common/merge_file'
+require 'iron_worker_ng/feature/common/merge_dir'
+require 'iron_worker_ng/feature/common/merge_deb'
module IronWorkerNG
module Code
@@ -80,10 +80,10 @@ def initialize(*args, &block)
@full_remote_build = true
end
- eval(content)
-
@base_dir = File.dirname(worker_file) == '.' ? '' : File.dirname(worker_file) + '/'
+ eval(content)
+
break
end
end
View
2  lib/iron_worker_ng/code/binary.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/binary'
+require 'iron_worker_ng/code/runtime/binary'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/builder.rb
@@ -1,4 +1,4 @@
-require_relative '../feature/ruby/merge_gem'
+require 'iron_worker_ng/feature/ruby/merge_gem'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/go.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/go'
+require 'iron_worker_ng/code/runtime/go'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/java.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/java'
+require 'iron_worker_ng/code/runtime/java'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/mono.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/mono'
+require 'iron_worker_ng/code/runtime/mono'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/node.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/node'
+require 'iron_worker_ng/code/runtime/node'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/perl.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/perl'
+require 'iron_worker_ng/code/runtime/perl'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/php.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/php'
+require 'iron_worker_ng/code/runtime/php'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/python.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/python'
+require 'iron_worker_ng/code/runtime/python'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/ruby.rb
@@ -1,4 +1,4 @@
-require_relative 'runtime/ruby'
+require 'iron_worker_ng/code/runtime/ruby'
module IronWorkerNG
module Code
View
2  lib/iron_worker_ng/code/runtime/java.rb
@@ -1,4 +1,4 @@
-require_relative '../../feature/java/merge_jar'
+require 'iron_worker_ng/feature/java/merge_jar'
module IronWorkerNG
module Code
View
6 lib/iron_worker_ng/code/runtime/python.rb
@@ -1,5 +1,5 @@
-require_relative '../../feature/python/merge_pip_dependency'
-require_relative '../../feature/python/merge_pip'
+require 'iron_worker_ng/feature/python/merge_pip_dependency'
+require 'iron_worker_ng/feature/python/merge_pip'
module IronWorkerNG
module Code
@@ -10,7 +10,7 @@ module Python
def runtime_run_code(local = false)
<<RUN_CODE
-PYTHONPATH=`pwd`/__pips__ python #{File.basename(@exec.path)} "$@"
+PATH=`pwd`/__pips__/bin:$PATH PYTHONPATH=`pwd`/__pips__ python -u #{File.basename(@exec.path)} "$@"
RUN_CODE
end
end
View
6 lib/iron_worker_ng/code/runtime/ruby.rb
@@ -1,9 +1,9 @@
require 'tmpdir'
require 'fileutils'
-require_relative '../../feature/ruby/merge_gem_dependency'
-require_relative '../../feature/ruby/merge_gemfile'
-require_relative '../../feature/ruby/merge_gem'
+require 'iron_worker_ng/feature/ruby/merge_gem_dependency'
+require 'iron_worker_ng/feature/ruby/merge_gemfile'
+require 'iron_worker_ng/feature/ruby/merge_gem'
module IronWorkerNG
module Code
View
16 lib/iron_worker_ng/compat.rb
@@ -0,0 +1,16 @@
+require 'tmpdir'
+require 'fileutils'
+
+unless Dir.const_defined?(:Tmpname)
+ class Dir
+ class Tmpname
+ def self.make_tmpname(x, y)
+ n = ::Dir.mktmpdir(x + y)
+ FileUtils.rm_rf(n)
+
+ n.sub(::Dir.tmpdir, '')
+ end
+ end
+ end
+end
+
View
9 lib/iron_worker_ng/feature/python/merge_pip.rb
@@ -20,13 +20,18 @@ def bundle(container)
tmp_dir_name = ::Dir.tmpdir + '/' + ::Dir::Tmpname.make_tmpname('iron-worker-ng-', 'pips')
::Dir.mkdir(tmp_dir_name)
+ ::Dir.mkdir(tmp_dir_name + '/bin')
+ ::Dir.mkdir(tmp_dir_name + '/lib')
deps_string = @deps.map { |dep| dep.version == '' ? dep.name : dep.name + '==' + dep.version }.join(' ')
- install_command = 'pip install --upgrade --install-option="--install-purelib=' + tmp_dir_name + '" ' + deps_string
+ install_command = 'pip install --ignore-installed --install-option="--prefix=' + tmp_dir_name + '" ' + deps_string
system(install_command)
- container_add(container, '__pips__', tmp_dir_name, true)
+ packages_dir = Dir.glob(tmp_dir_name + '/lib/*python*').first + '/site-packages'
+
+ container_add(container, '__pips__/bin', tmp_dir_name + '/bin', true)
+ container_add(container, '__pips__', packages_dir , true)
FileUtils.rm_rf(tmp_dir_name)
end
View
12 lib/iron_worker_ng/feature/ruby/merge_gemfile.rb
@@ -23,13 +23,17 @@ def merge_gemfile(path, *groups)
IronCore::Logger.info 'IronWorkerNG', "Adding ruby gems dependencies from #{groups.join(', ')} group#{groups.length > 1 ? 's' : ''} of #{path}"
- specs = Bundler::Definition.build(path, path + '.lock', nil).specs_for(groups)
+ feature = IronWorkerNG::Feature::Ruby::MergeGemfile::Feature.new(self, path, groups)
- specs.each do |spec|
- merge_gem(spec.name, spec.version.to_s)
+ IronWorkerNG::Fetcher.fetch_to_file(feature.rebase(path)) do |gemfile|
+ specs = Bundler::Definition.build(gemfile, path + '.lock', nil).specs_for(groups)
+
+ specs.each do |spec|
+ merge_gem(spec.name, spec.version.to_s)
+ end
end
- @features << IronWorkerNG::Feature::Ruby::MergeGemfile::Feature.new(self, path, groups)
+ @features << feature
end
alias :gemfile :merge_gemfile
View
2  lib/iron_worker_ng/version.rb
@@ -1,5 +1,5 @@
module IronWorkerNG
- VERSION = '0.14.0'
+ VERSION = '0.15.0'
def self.version
VERSION
View
19 test/examples/README.md
@@ -0,0 +1,19 @@
+To sync examples with repo:
+1. install git@github.com:apenwarr/git-subtree.git
+2. split ng examples into separate branch
+```
+git clone git@github.com:iron-io/iron_worker_examples.git iw_examples
+cd iw_examples
+git subtree split --prefix ruby_ng --annotate="(split)" -b ruby_ng_split
+cd -
+```
+3. merge them into iron_worker_ng subtree
+```
+git clone git@github.com:iron-io/iron_worker_ruby_ng.git iw
+cd iw
+git remote add iw_examples ../iw_examples
+git fetch iw_examples
+git subtree merge -P examples --squash iw_examples/ruby_ng_split -m 'Updating examples subtree'
+git push origin master
+cd -
+```
View
36 test/examples/test_example_actionmailer_standalone.rb
@@ -0,0 +1,36 @@
+require_relative '../helpers'
+require 'rest'
+require 'net/imap'
+
+class ExampleActionMailerStandaloneTest < IWNGTest
+
+ def test_example
+ Dir.chdir 'examples/actionmailer_standalone' do
+ assert(cli('upload', 'actionmailer_standalone') =~ /Upload successful/)
+ assert(cli('queue', 'actionmailer_standalone',
+ payload_file: 'actionmailer_config.json') =~
+ /queued with id='(.*)'/)
+
+ # wait for delivery
+ client.tasks.wait_for($1)
+ sleep 10
+
+ config = JSON.parse(File.read('actionmailer_config.json'))['gmail']
+ begin
+ imap = Net::IMAP.new('imap.gmail.com',993,true)
+ imap.login(config['username'], config['password'])
+ imap.select('INBOX')
+ ids = imap.search(['SUBJECT', 'Sample subject'])
+ assert ids.size >= 1
+ id = ids.last
+ msg = imap.fetch(id, 'RFC822')
+ assert msg[0].attr['RFC822'] =~ /message sent using IronWorker/
+ imap.store(id, "+FLAGS", [:Deleted])
+ ensure
+ imap.logout
+ imap.disconnect
+ end
+ end
+ end
+
+end
View
24 test/examples/test_example_chargify_to_campfire_webhook.rb
@@ -0,0 +1,24 @@
+require_relative '../helpers'
+require 'rest'
+
+class ExampleChargifyToCampfireWebhookTest < IWNGTest
+
+ def test_example
+ Dir.chdir 'examples/chargify_to_campfire_webhook_worker' do
+ assert(cli('upload', 'chargify_to_campfire') =~ /Upload successful/)
+
+ assert(cli('webhook', 'chargify_to_campfire') =~ /^\s*(https.*)$/)
+ webhook = $1
+
+ rest = Rest::Client::new
+ resp = rest.post(webhook, body: "payload[chargify]=testing&id=6825503&event=test")
+ assert_equal 200, resp.code
+
+ task_id = JSON.parse(resp.body)['id']
+ client.tasks.wait_for(task_id)
+
+ assert client.tasks.log(task_id) =~ /^Done$/
+ end
+ end
+
+end
View
54 test/examples/test_example_email_worker.rb
@@ -0,0 +1,54 @@
+require_relative '../helpers'
+require 'rest'
+require 'iron_cache'
+require 'net/imap'
+require 'tempfile'
+
+class ExampleEmailWorkerTest < IWNGTest
+
+ def test_example
+ Dir.chdir 'examples/email_worker' do
+ assert(cli('upload', 'email_worker') =~ /Upload successful/)
+
+ cfg = JSON.parse(File.read('email_config.json'))
+
+ cache = IronCache::Client.new
+ cache.items.delete(cfg['to']) if cache.items.get(cfg['to'])
+
+ cfg['iron'] = { token: client.api.token,
+ project_id: client.api.project_id }
+ tmp = Tempfile.new(['email_config', '.json'])
+ tmp.write cfg.to_json
+ tmp.close
+
+ assert(cli('queue', 'email_worker',
+ payload_file: tmp.path) =~
+ /queued with id='(.*)'/)
+
+ # wait for delivery
+ client.tasks.wait_for($1)
+ sleep 10
+
+ begin
+ imap = Net::IMAP.new('imap.gmail.com',993,true)
+ imap.login(cfg['smtp']['user_name'], cfg['smtp']['password'])
+ imap.select('INBOX')
+ ids = imap.search(['SUBJECT', 'hello from IronWorker'])
+ assert ids.size >= 1
+ id = ids.last
+ msg = imap.fetch(id, 'RFC822')
+ assert msg[0].attr['RFC822'] =~ /hello me/
+ imap.store(id, "+FLAGS", [:Deleted])
+ ensure
+ imap.logout
+ imap.disconnect
+ end
+
+ cache = IronCache::Client.new
+ assert cache.items.get(cfg['to']).value =~ /hello me/
+
+ tmp.unlink
+ end
+ end
+
+end
View
2  test/hello.rb
@@ -1,3 +1,3 @@
-puts "hello"
+puts "hello worker!"
#raise "DOH!"
View
2  test/quick_run.rb
@@ -2,7 +2,7 @@
class QuickRun < IWNGTest
- N_TASKS = 1
+ N_TASKS = 100
def setup
super
Please sign in to comment.
Something went wrong with that request. Please try again.