Permalink
Browse files

Added remote gem build support.

  • Loading branch information...
treeder committed Jun 9, 2012
1 parent bd212e3 commit c18d6cadfd96cabed9a4a162ef05fb9389edc948
Showing with 61 additions and 45 deletions.
  1. +3 −8 Rakefile
  2. +7 −0 lib/iron_worker_ng/code/ruby.rb
  3. +31 −6 test/build_worker.rb
  4. +20 −31 test/test_builder.rb
View
@@ -8,21 +8,16 @@ task :test do
end
Jeweler::Tasks.new do |gem|
- begin
- Bundler.setup(:default, :development)
- rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
- end
-
gem.name = "iron_worker_ng"
gem.homepage = "https://github.com/iron-io/iron_worker_ruby_ng"
gem.description = %Q{New generation ruby client for IronWorker}
gem.summary = %Q{New generation ruby client for IronWorker}
gem.email = "info@iron.io"
gem.authors = ["Andrew Kirilenko", "Iron.io, Inc"]
gem.files.exclude('.document', 'Gemfile', 'Gemfile.lock', 'Rakefile', 'iron_worker_ng.gemspec', 'test/**/**', 'examples/**/**')
+ gem.add_dependency 'iron_core'
+ #gem.add_dependency 'typhoeus'
+ gem.required_ruby_version = '>= 1.9'
end
Jeweler::RubygemsDotOrgTasks.new
@@ -66,6 +66,13 @@ def iron_task_id
@iron_task_id
end
+begin
+ # load bundle if it's here
+ require_relative 'bundle/bundler/setup'
+ puts "loaded standalone bundle"
+rescue LoadError => ex
+end
+
require '#{File.basename(@exec.path)}'
unless #{@exec.klass == nil}
View
@@ -10,14 +10,16 @@
class WorkerFile
- attr_accessor :wruntime
- attr_accessor :wname
- attr_accessor :exec_file
- attr_accessor :files
- attr_accessor :build_command
+ attr_accessor :wruntime,
+ :wname,
+ :exec_file,
+ :files,
+ :gems,
+ :build_command
def initialize(raw)
@files = []
+ @gems = []
puts 'evaling'
eval(raw)
@@ -40,6 +42,10 @@ def file(s)
@files << s
end
+ def gem(s)
+ @gems << s
+ end
+
def build_command(s=nil)
if s
@build_command = s
@@ -93,11 +99,30 @@ def get_code_by_runtime(runtime)
end
end
+ code = get_code_by_runtime(worker_file.wruntime)
+
+ if worker_file.gems && worker_file.gems.size > 0
+ open("Gemfile", 'w') do |gemfile|
+ gemfile << "source 'http://rubygems.org'\n"
+ worker_file.gems.each do |gem|
+ gemfile << "gem '#{gem}'\n"
+ end
+ end
+
+ puts `ls -al`
+
+ # now build bundle
+ puts "building bundle"
+ puts `bundle install --standalone`
+ code.merge_dir 'bundle'
+ end
+
+
if worker_file.build_command
puts `#{worker_file.build_command}`
end
- code = get_code_by_runtime(worker_file.wruntime)
+
code.name = params['name'] || worker_file.wname
code.merge_exec worker_file.exec_file
worker_file.files.each do |f|
View
@@ -9,7 +9,6 @@ def test_build_worker
main_file = "hello.go"
name = "HelloGo"
-
code = IronWorkerNG::Code::Ruby.new('build_worker.rb')
code.merge_gem 'iron_worker_ng'
code.merge_file "workers/#{main_file}"
@@ -49,9 +48,23 @@ def test_ruby_build_from_github
# Usage would be via cli:
# iron_worker upload??? https://github.com/iron-io/iron_worker_examples/blob/master/ruby_ng/hello_worker/hello.worker
- worker_file_url = "https://github.com/iron-io/iron_worker_examples/blob/master/ruby_ng/hello_worker/hello.worker"
- name = "HelloRuby"
+ worker_file_url = "https://github.com/iron-io/iron_worker_examples/blob/master/ruby_ng/worker101/worker101.worker"
+ name = "RubyWorker101"
+
+ remote_build(name, worker_file_url)
+
+ # Now let's try queueing up a task for it
+ puts "Running #{name}..."
+ go_task_id = client.tasks.create(name, 'query' => 'bieber').id
+ task = client.tasks_wait_for(go_task_id)
+ assert_equal "complete", task.status
+ log = client.tasks_log(go_task_id)
+ puts "LOG START"
+ puts log
+ puts "LOG END"
+ end
+ def remote_build(name, worker_file_url)
code = IronWorkerNG::Code::Ruby.new('build_worker.rb')
code.merge_gem 'iron_worker_ng'
client.codes_create(code)
@@ -72,16 +85,9 @@ def test_ruby_build_from_github
assert_equal "complete", task.status
- puts "Running #{name}..."
- go_task_id = client.tasks.create(name).id
- task = client.tasks_wait_for(go_task_id)
- assert_equal "complete", task.status
- log = client.tasks_log(go_task_id)
- puts "LOG START"
- puts log
- puts "LOG END"
end
+
# This one not only gets the code from github, but compiles it too.
def test_go_build_from_github
@@ -91,34 +97,17 @@ def test_go_build_from_github
worker_file_url = "https://github.com/iron-io/iron_worker_examples/blob/master/go/hello_worker/hello.worker"
name = "HelloGoGithub"
- code = IronWorkerNG::Code::Ruby.new('build_worker.rb')
- code.merge_gem 'iron_worker_ng'
- client.codes_create(code)
-
- task_id = client.tasks.create('BuildWorker',
- client.api.options.merge(
- :name => name,
- :worker_file_url => worker_file_url
- )).id
-
- task = client.tasks_wait_for(task_id)
- assert task
- assert task.id == task_id
- log = client.tasks_log(task_id)
- puts "LOG START"
- puts log
- puts "LOG END"
-
- assert_equal "complete", task.status
+ remote_build(name, worker_file_url)
+ # Try queuing up a task for it
puts "Running #{name}..."
go_task_id = client.tasks.create(name).id
task = client.tasks_wait_for(go_task_id)
- assert_equal "complete", task.status
log = client.tasks_log(go_task_id)
puts "LOG START"
puts log
puts "LOG END"
+ assert_equal "complete", task.status
end
end

0 comments on commit c18d6ca

Please sign in to comment.