Sha256: bfe1274a90195dfe3e3cf3cfb0039c8696a9721d2b26a920b457eff1a0aeed32

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

require 'celluloid'
require 'fileutils'

module Buildbox
  class Runner
    include Celluloid
    include Celluloid::Logger

    def initialize(build)
      @build = build
    end

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

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

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

      @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 directory_path
      @directory_path ||= Buildbox.root_path.join(@build.namespace)
    end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
buildbox-0.4.2 lib/buildbox/runner.rb
buildbox-0.4.1 lib/buildbox/runner.rb
buildbox-0.4 lib/buildbox/runner.rb
buildbox-0.3.9.1 lib/buildbox/runner.rb
buildbox-0.3.9 lib/buildbox/runner.rb
buildbox-0.3.8 lib/buildbox/runner.rb
buildbox-0.3.7 lib/buildbox/runner.rb
buildbox-0.3.6 lib/buildbox/runner.rb
buildbox-0.3.5 lib/buildbox/runner.rb
buildbox-0.3.4 lib/buildbox/runner.rb