Sha256: 696178623aa9a6b12db4abd0ad87bb6c6b50f40e86df2d76c2b614fcc5fb0646

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'dply/stages_config'
require 'dply/remote_task'
require 'dply/logger'

module Dply
  class Dplyr

    include Logger

    attr_reader :stage, :argv
    def initialize(stage, argv)
      @stage = stage
      @argv = argv
    end

    def run
      global_switches = []
      global_switches << "--debug" if  logger.debug?
      case stage
      when 'dev'
        global_switches << "--no-config"
        system "drake #{global_switches.join(" ")} #{argv_str}"
      when 'local'
        system "drake #{global_switches.join(" ")} #{argv_str}"
      else
        run_remote_task
      end
    end

    def stage_data
      @stage_data ||= StagesConfig.new("stages.rb").get_stage(stage)
    end

    def hosts
      stage_data[:hosts]
    end

    def parallel_jobs
      stage_data[:parallel_runs]
    end

    def env_str
      str = ""
      stage_data[:env].each do |k,v|
        str << %(DPLY_#{k.upcase}="#{v}" )
      end
      str
    end

    def argv_str
      @argv_str ||= argv.join(' ')
    end

    def run_remote_task
      remote_task = ::Dply::RemoteTask.new(hosts, argv_str, parallel_jobs: parallel_jobs, env: env_str)
      remote_task.run
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dply-0.0.8 lib/dply/dplyr.rb
dply-0.0.7 lib/dply/dplyr.rb
dply-0.0.5 lib/dply/dplyr.rb