Sha256: f8c2050bdf998ec3b38df033e1c8b2f2e15ef6022114171e3856b8b62f8caefa

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'celluloid'
require 'fileutils'
require 'childprocess'

module Buildbox
  class Runner
    include Celluloid
    include Celluloid::Logger

    def self.start(build)
      runner = new(build)
      runner.start
      runner
    end

    def initialize(build)
      @build = build
    end

    def build_directory
      @build_directory ||= Buildbox.home_path.join(@build.namespace)
    end

    def start
      info "Starting to build #{@build.namespace}/#{@build.id} starting..."

      FileUtils.mkdir_p(build_directory)
      File.open(script_path, 'w+') { |file| file.write(@build.script) }
      File.chmod(0777, script_path)

      command = Command.new(script_path, :environment => @build.env, :directory => build_directory)

      @build.output     = ""
      @build.process    = command.process
      @build.started_at = Time.now.utc

      command.start { |chunk| @build.output << chunk }

      @build.output      = command.output
      @build.exit_status = command.exit_status

      File.delete(script_path)

      @build.finished_at = Time.now.utc

      info "#{@build.namespace} ##{@build.id} finished with exit status #{command.exit_status}"
    end

    private

    def script_path
      @script_path ||= Buildbox.home_path.join(script_name)
    end

    def script_name
      name = "#{@build.namespace.gsub(/\//, '-')}-#{@build.id}"
      name << ".bat" if ChildProcess.platform == :windows
      name
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
buildbox-0.6.2 lib/buildbox/runner.rb
buildbox-0.6.1 lib/buildbox/runner.rb
buildbox-0.7.beta1 lib/buildbox/runner.rb
buildbox-0.6 lib/buildbox/runner.rb
buildbox-0.6.beta3 lib/buildbox/runner.rb
buildbox-0.6.beta2 lib/buildbox/runner.rb
buildbox-0.6.beta1 lib/buildbox/runner.rb