Skip to content

Commit

Permalink
use exit code 1 for failure (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
littlemight authored and Stefanos Boglou committed Oct 27, 2022
1 parent 37c0964 commit bc77f18
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/rspecq
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions lib/rspecq/formatters/failure_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions lib/rspecq/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/rspecq/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?

Expand Down

0 comments on commit bc77f18

Please sign in to comment.