Skip to content

Commit

Permalink
Use exceptions for empty output retries in preparation of related work
Browse files Browse the repository at this point in the history
  • Loading branch information
dzuelke committed Jan 24, 2023
1 parent a9d3dc5 commit 6dcf6a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## HEAD

- Add support for GitHub Actions env vars (https://github.com/heroku/hatchet/pull/189)
- Change HerokuRun#call to use exceptions for empty output retries in preparation of related work

## 7.4.0

Expand Down
30 changes: 15 additions & 15 deletions lib/hatchet/heroku_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def match(value)
# the command to be empty.
#
class HerokuRun
class HerokuRunEmptyOutputError < RuntimeError; end

attr_reader :command

def initialize(
Expand Down Expand Up @@ -82,22 +84,19 @@ def status
end

def call
loop do
begin
execute!

break unless output.empty?
break unless @retry_on_empty

@empty_fail_count += 1

break if @empty_fail_count >= 3

message = String.new("Empty output from command #{@command}, retrying the command.")
message << "\nTo disable pass in `retry_on_empty: false` or set HATCHET_DISABLE_EMPTY_RUN_RETRY=1 globally"
message << "\nfailed_count: #{@empty_fail_count}"
message << "\nreleases: #{@app.releases}"
message << "\n#{caller.join("\n")}"
@stderr.puts message
rescue HerokuRunEmptyOutputError => e
if @retry_on_empty and @empty_fail_count < 3
@empty_fail_count += 1
message = String.new("Empty output from command #{@command}, retrying the command.")
message << "\nTo disable pass in `retry_on_empty: false` or set HATCHET_DISABLE_EMPTY_RUN_RETRY=1 globally"
message << "\nfailed_count: #{@empty_fail_count}"
message << "\nreleases: #{@app.releases}"
message << "\n#{caller.join("\n")}"
@stderr.puts message
retry
end
end

self
Expand All @@ -107,6 +106,7 @@ def call
ShellThrottle.new(platform_api: @app.platform_api).call do |throttle|
run_shell!
throw(:throttle) if @result.stderr.match?(/reached the API rate limit/)
raise HerokuRunEmptyOutputError if @result.stdout.empty?
end
end

Expand Down

0 comments on commit 6dcf6a0

Please sign in to comment.