Skip to content

Conversation

@rafaelmf3
Copy link
Contributor

@rafaelmf3 rafaelmf3 commented Dec 22, 2025

Submit a pull request

https://linear.app/stream/issue/CHA-1610/ruby

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

Comment on lines 7 to 19
def loop_times(times)
loop do
begin
yield()
return
rescue StandardError, RSpec::Expectations::ExpectationNotMetError
raise if times.zero?
end

sleep(1)
times -= 1
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something, but Ruby already has this built in. Would it make sense to use:

10.times do |i|
  # do something
end

if you need exception handling this will also work

10.times do |i|
  # do something
rescue => e
  # handle exception
end

It would keep this a bit simpler.

Comment on lines +26 to +54
def wait_for_task(task_id, timeout_seconds: 120)
sleep(2) # Initial delay

timeout_seconds.times do |i|
task = fetch_task_with_retry(task_id, i)
next if task.nil?

expect(task['task_id']).to eq(task_id)

case task['status']
when 'waiting', 'pending', 'running'
sleep(1)
when 'completed'
return task
when 'failed'
# If result is empty, continue polling (matches Go behavior)
result = task['result']
if result.nil? || (result.is_a?(Hash) && result.empty?)
sleep(2)
elsif rate_limit_error?(task)
sleep(2)
else
raise "Task failed with result: #{task['result']}"
end
end
end

raise "Task did not complete within #{timeout_seconds} seconds"
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [rubocop] <Metrics/CyclomaticComplexity> reported by reviewdog 🐶
Cyclomatic complexity for wait_for_task is too high. [9/7]

Comment on lines +45 to +48
elsif rate_limit_error?(task)
sleep(2)
else
raise "Task failed with result: #{task['result']}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [rubocop] <Lint/DuplicateBranch> reported by reviewdog 🐶
Duplicate branch body detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants