vendredi 24 juillet 2020

Rails | How to Ignore raise error sidekiq worker | Capybara

I am pretty new to rails and my team recently moved to use sidekiq

I'm using a worker with a code similar to this:

def perform()
    ...
        whatever = {...}

        if whatever.status == 'successful'
          thisCoolFunction                  # successfully ends job
        elsif whatever.status == 'failed'
          anotherCoolFunction               # successfully ends job
        elsif whatever.pending?             # I want to retry if it falls in this condition since it is "waiting" for another task to complete.
          raise 'We are trying again'
        end
    ...
end

I tried with

          begin
            raise 'We are trying again!'
          rescue
             nil
          end

But when I run my tests, I get this error:

     Failure/Error: raise 'We are trying again!'
     
     RuntimeError:
       'We are trying again!'
     ...

Which of course, makes sense to me, since I'm raising the error, I tried searching but wasn't able to come up with a solution. I'm wondering whether its able to a) retry again without raising an error or b) tell Capybara (rspec) to keep trying without throwing an error.




Aucun commentaire:

Enregistrer un commentaire