Sha256: c1a885dffae07c97b0618d4f15e4b76b939b21cf7bf17ac81bf93d927b865b5c

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

require 'rubygems'
require 'celluloid'
require 'fileutils'

module Buildbox
  class Runner
    include Celluloid
    include Celluloid::Logger

    attr_reader :build

    def initialize(build)
      @build = build
    end

    def start
      info "Starting to build #{namespace}/#{@build.number} starting..."
      info "Running command: #{command}"

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

      build.output = ""
      result = Command.run(command, :directory => directory_path) do |chunk|
        build.output << chunk
      end

      build.output      = result.output
      build.exit_status = result.exit_status

      File.delete(script_path)

      info "#{namespace} ##{@build.number} finished with exit status #{result.exit_status}"
    end

    private

    def command
      export = environment.any? ? "export #{environment};" : ""

      "#{export} chmod +x #{script_path} && #{script_path}"
    end

    def directory_path
      @directory_path ||= Buildbox.root_path.join(namespace)
    end

    def script_path
      @script_path ||= Buildbox.root_path.join("buildbox-#{namespace.gsub(/\//, '-')}-#{@build.number}")
    end

    def namespace
      "#{@build.project.team.name}/#{@build.project.name}"
    end

    def environment
      @environment ||= Environment.new(@build.env)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
buildbox-0.2.2 lib/buildbox/runner.rb
buildbox-0.2.1 lib/buildbox/runner.rb
buildbox-0.2 lib/buildbox/runner.rb
buildbox-0.1.4 lib/buildbox/runner.rb