Sha256: f6c1b8e13ed4625d48874473d793ef37073c896c65cb22b245f84632c497d340

Contents?: true

Size: 1.93 KB

Versions: 5

Compression:

Stored size: 1.93 KB

Contents

require_relative '../feature/ruby/merge_gem'
require_relative '../feature/ruby/merge_gemfile'
require_relative '../feature/ruby/merge_worker'

module IronWorkerNG
  module Code
    class Ruby < IronWorkerNG::Code::Base
      include IronWorkerNG::Feature::Ruby::MergeGem::InstanceMethods
      include IronWorkerNG::Feature::Ruby::MergeGemfile::InstanceMethods
      include IronWorkerNG::Feature::Ruby::MergeWorker::InstanceMethods

      def create_runner(zip, init_code)
        zip.get_output_stream('runner.rb') do |runner|
          runner.write <<RUNNER
# iron_worker_ng-#{IronWorkerNG.version}

root = nil
payload_file = nil
task_id = nil

($*.length - 2).downto(0) do |i|
  root = $*[i + 1] if $*[i] == '-d'
  payload_file = $*[i + 1] if $*[i] == '-payload'
  task_id = $*[i + 1] if $*[i] == '-id'
end

Dir.chdir(root)

#{init_code}
$:.unshift("\#{root}")

def log(*args)
  puts *args
end

require 'json'

@iron_worker_task_id = task_id

@payload = File.read(payload_file)

parsed_payload = {}
begin
  parsed_payload = JSON.parse(@payload)
rescue
end

@iron_io_token = parsed_payload['token']
@iron_io_project_id = parsed_payload['project_id']
@params = parsed_payload['params'] || {}

require worker_file_name

worker_class = nil

begin
  worker_class = Kernel.const_get(worker_class_name)
rescue
end

unless worker_class.nil?
  worker_inst = worker_class.new

  class << worker_inst
    attr_accessor :iron_io_token
    attr_accessor :iron_io_project_id
    attr_accessor :iron_worker_task_id
    attr_accessor :params
  end

  worker_inst.iron_io_token = @iron_io_token
  worker_inst.iron_io_project_id = @iron_io_project_id
  worker_inst.iron_worker_task_id = @iron_worker_task_id
  worker_inst.params = @params

  worker_inst.run
end
RUNNER
        end
      end

      def runtime
        'ruby'
      end

      def runner
        'runner.rb'
      end
    end
  end
end

IronWorkerNG::Code::Base.register_type(:name => 'ruby', :klass => IronWorkerNG::Code::Ruby)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iron_worker_ng-0.1.7 lib/iron_worker_ng/code/ruby.rb
iron_worker_ng-0.1.6 lib/iron_worker_ng/code/ruby.rb
iron_worker_ng-0.1.5 lib/iron_worker_ng/code/ruby.rb
iron_worker_ng-0.1.4 lib/iron_worker_ng/code/ruby.rb
iron_worker_ng-0.1.3 lib/iron_worker_ng/code/ruby.rb