Sha256: f7b5bb82c129aea8290e82e8e5b16097c3598edd8be2156db113aa4cbfa3e86f

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

class PerformTaskJob < BackgroundJob
  queue_as :deploys

  def perform(task)
    @task = task
    @commands = Commands.for(@task)
    unless @task.pending?
      logger.error("Task ##{@task.id} already in `#{@task.status}` state. Aborting.")
      return
    end
    run
  ensure
    @task.clear_working_directory
  end

  def run
    @task.run!
    checkout_repository
    perform_task
    @task.complete!
  rescue Command::Error => error
    @task.report_failure!(error)
  rescue StandardError => error
    @task.report_error!(error)
  end

  def perform_task
    Bundler.with_clean_env do
      capture_all @commands.install_dependencies
      capture_all @commands.perform
    end
  end

  def checkout_repository
    @task.acquire_git_cache_lock do
      capture @commands.fetch
      capture @commands.clone
    end
    capture @commands.checkout(@task.until_commit)
  end

  def capture_all(commands)
    commands.map { |c| capture(c) }
  end

  def capture(command)
    command.start
    @task.write("$ #{command}\npid: #{command.pid}\n")
    @task.pid = command.pid
    command.stream! do |line|
      @task.write(line)
    end
    @task.write("\n")
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
shipit-engine-0.5.2 app/jobs/perform_task_job.rb
shipit-engine-0.5.1 app/jobs/perform_task_job.rb
shipit-engine-0.5.0 app/jobs/perform_task_job.rb
shipit-engine-0.4.10 app/jobs/perform_task_job.rb
shipit-engine-0.4.9 app/jobs/perform_task_job.rb
shipit-engine-0.4.8 app/jobs/perform_task_job.rb
shipit-engine-0.4.7 app/jobs/perform_task_job.rb
shipit-engine-0.4.6 app/jobs/perform_task_job.rb
shipit-engine-0.4.5 app/jobs/perform_task_job.rb
shipit-engine-0.4.4 app/jobs/perform_task_job.rb
shipit-engine-0.4.3 app/jobs/perform_task_job.rb
shipit-engine-0.4.2 app/jobs/perform_task_job.rb
shipit-engine-0.4.1 app/jobs/perform_task_job.rb
shipit-engine-0.4.0 app/jobs/perform_task_job.rb
shipit-engine-0.3.1 app/jobs/perform_task_job.rb