From bc77f189df004a1b00907e216e4b8539d8ab6685 Mon Sep 17 00:00:00 2001 From: Michel Fang <43075287+littlemight@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:28:18 +0700 Subject: [PATCH] use exit code 1 for failure (#2) --- bin/rspecq | 2 +- lib/rspecq/formatters/failure_recorder.rb | 3 +++ lib/rspecq/queue.rb | 2 ++ lib/rspecq/worker.rb | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/rspecq b/bin/rspecq index e0df9d6..25edcac 100755 --- a/bin/rspecq +++ b/bin/rspecq @@ -181,5 +181,5 @@ else worker.seed = Integer(opts[:seed]) if opts[:seed] worker.reproduction = opts[:reproduction] worker.tags = opts[:tags] - worker.work + exit worker.work end diff --git a/lib/rspecq/formatters/failure_recorder.rb b/lib/rspecq/formatters/failure_recorder.rb index bae6378..f5b82d9 100644 --- a/lib/rspecq/formatters/failure_recorder.rb +++ b/lib/rspecq/formatters/failure_recorder.rb @@ -43,6 +43,9 @@ def example_failed(notification) @queue.record_flaky_failure(notification.example.id, msg) sleep 0.5 return + else + # returns nil when hit requeue limit, use exit code 1 + @queue.exit_code = 1 end msg << "\n" diff --git a/lib/rspecq/queue.rb b/lib/rspecq/queue.rb index a6255eb..11bc879 100644 --- a/lib/rspecq/queue.rb +++ b/lib/rspecq/queue.rb @@ -75,11 +75,13 @@ class Queue STATUS_READY = "ready".freeze attr_reader :redis + attr_accessor :exit_code def initialize(build_id, worker_id, redis_opts) @build_id = build_id @worker_id = worker_id @redis = Redis.new(redis_opts.merge(id: worker_id)) + @exit_code = 0 end # NOTE: jobs will be processed from head to tail (lpop) diff --git a/lib/rspecq/worker.rb b/lib/rspecq/worker.rb index 335f420..53d0638 100644 --- a/lib/rspecq/worker.rb +++ b/lib/rspecq/worker.rb @@ -96,7 +96,7 @@ def work # to `requeue_lost_job` inside the work loop update_heartbeat - return if queue.build_failed_fast? + return queue.exit_code if queue.build_failed_fast? lost = queue.requeue_lost_job puts "Requeued lost job: #{lost}" if lost @@ -106,7 +106,7 @@ def work job = queue.reserve_job # build is finished - return if job.nil? && queue.exhausted? + return queue.exit_code if job.nil? && queue.exhausted? next if job.nil?