Skip to content

Commit

Permalink
Running Java workers through Ruby runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
iced committed Feb 19, 2012
1 parent 523e7b5 commit 5d61f77
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/iron_worker_ng/client.rb
Expand Up @@ -17,7 +17,7 @@ def upload(package)
File.unlink(zip_file)
end

def queue(package_name, params)
def queue(package_name, params = {})
@api.tasks_create(package_name, {:project_id => @api.project_id, :token => @api.token, :params => params})
end
end
Expand Down
16 changes: 4 additions & 12 deletions lib/iron_worker_ng/features/java/jar_merger.rb
Expand Up @@ -15,19 +15,11 @@ def hash_string
end

def bundle(zip)
Zip::ZipFile.open(@path) do |jar|
jar.entries.each do |entry|
next if entry.name.start_with?('META-INF')
zip.add(File.basename(@path), @path)
end

next unless zip.find_entry(entry.name).nil?

if entry.ftype == :directory
zip.mkdir(entry.name)
elsif entry.ftype == :file
zip.get_output_stream(entry.name) { |f| f.write(jar.read(entry.name)) }
end
end
end
def code_for_classpath
File.basename(@path)
end
end

Expand Down
18 changes: 5 additions & 13 deletions lib/iron_worker_ng/features/java/worker_merger.rb
Expand Up @@ -15,19 +15,11 @@ def hash_string
end

def bundle(zip)
Zip::ZipFile.open(@path) do |jar|
jar.entries.each do |entry|
next if entry.name.start_with?('META-INF')

next unless zip.find_entry(entry.name).nil?

if entry.ftype == :directory
zip.mkdir(entry.name)
elsif entry.ftype == :file
zip.get_output_stream(entry.name) { |f| f.write(jar.read(entry.name)) }
end
end
end
zip.add(File.basename(@path), @path)
end

def code_for_classpath
File.basename(@path)
end
end

Expand Down
32 changes: 30 additions & 2 deletions lib/iron_worker_ng/java_package.rb
Expand Up @@ -8,12 +8,40 @@ def initialize(worker_path = nil, worker_klass = nil)
merge_worker(worker_path, worker_klass) if (not worker_path.nil?) && (not worker_klass.nil?)
end

def create_runner(zip)
classpath_array = []

@features.each do |f|
if f.respond_to?(:code_for_classpath)
classpath_array << f.send(:code_for_classpath)
end
end

classpath = classpath_array.join(':')

zip.get_output_stream('runner.rb') do |runner|
runner.write <<RUNNER
# IronWorker NG #{File.read(File.dirname(__FILE__) + '/../../VERSION').gsub("\n", '')}
root = nil
($*.size - 2).downto(0) do |i|
root = $*[i + 1] if $*[i] == '-d'
end
Dir.chdir(root)
puts `java -cp #{classpath} #{worker.klass} \#{$*.join(' ')}`
RUNNER
end
end

def runtime
'java'
'ruby'
end

def runner
worker.klass
'runner.rb'
end
end
end

0 comments on commit 5d61f77

Please sign in to comment.