{"action":"created","issue":{"url":"https://api.github.com/repos/soveran/ost/issues/10","repository_url":"https://api.github.com/repos/soveran/ost","labels_url":"https://api.github.com/repos/soveran/ost/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/soveran/ost/issues/10/comments","events_url":"https://api.github.com/repos/soveran/ost/issues/10/events","html_url":"https://github.com/soveran/ost/issues/10","id":196550360,"number":10,"title":"Force an item to be put in backup queue without breaking Ost main loop?","user":{"login":"scalp42","id":1475276,"avatar_url":"https://avatars.githubusercontent.com/u/1475276?v=3","gravatar_id":"","url":"https://api.github.com/users/scalp42","html_url":"https://github.com/scalp42","followers_url":"https://api.github.com/users/scalp42/followers","following_url":"https://api.github.com/users/scalp42/following{/other_user}","gists_url":"https://api.github.com/users/scalp42/gists{/gist_id}","starred_url":"https://api.github.com/users/scalp42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scalp42/subscriptions","organizations_url":"https://api.github.com/users/scalp42/orgs","repos_url":"https://api.github.com/users/scalp42/repos","events_url":"https://api.github.com/users/scalp42/events{/privacy}","received_events_url":"https://api.github.com/users/scalp42/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-19T23:49:52Z","updated_at":"2016-12-20T21:46:35Z","closed_at":"2016-12-20T20:53:33Z","body":"Hi @soveran,\r\n\r\nAssuming a poc:\r\n\r\n```ruby\r\nOst.redis = Redic.new(cli.config[:redis_url])\r\nlogger.info 'Worker started.'\r\nif cli.config[:api]\r\n  begin\r\n    Ost[cli.config[:redis_key]].each do |item|\r\n      url = 'api.example.com'\r\n      curl = Typhoeus.post(\r\n        url,\r\n        body: item\r\n      )\r\n      if curl.success? && !curl.response_body.empty? && !curl.timed_out?\r\n        logger.info %|#{item} => Done, response #{response.code}.|\r\n        logger.debug %|#{item} => JSON.parse(#{response.body})|\r\n      else\r\n        logger.error %|#{item} => API error or timed out.|\r\n        raise 'BOOM'\r\n      end\r\n    end\r\n  rescue Errno::ECONNREFUSED\r\n    logger.error %|Could not connect to Redis #{cli.config[:redis_url]}|\r\n  end\r\nend\r\nlogger.info 'Worker finished.'\r\n\r\n```\r\n\r\n```\r\n[2016-12-19 15:36:49 -0800 INFO] Worker started.\r\n[2016-12-19 15:37:08 -0800 ERROR] test => API error or timed out.\r\n/Users/scalp/worker/lib/main.rb:23:in `block in init': BOOM (RuntimeError)\r\n  from /Users/scalp/.rvm/gems/ruby-2.3.1@worker/gems/ost-1.0.0/lib/ost.rb:26:in `block in each'\r\n  from /Users/scalp/.rvm/gems/ruby-2.3.1@worker/gems/ost-1.0.0/lib/ost.rb:22:in `loop'\r\n  from /Users/scalp/.rvm/gems/ruby-2.3.1@worker/gems/ost-1.0.0/lib/ost.rb:22:in `each'\r\n  from /Users/scalp/worker/lib/main.rb:9:in `init'\r\n  from ./worker.rb:10:in `<main>'\r\n```\r\n\r\nI see that it saves it to a backup queue `\"ost:worker:mbp42.local:75343\"` but I would like to know if there's a way to make it happen without an exception (which stops the queue processing) ?\r\n\r\nPretty much force putting the item in the backup queue, while still processing items ?\r\n\r\nHopefully it makes sense, thanks in advance 🍶 "},"comment":{"url":"https://api.github.com/repos/soveran/ost/issues/comments/268368627","html_url":"https://github.com/soveran/ost/issues/10#issuecomment-268368627","issue_url":"https://api.github.com/repos/soveran/ost/issues/10","id":268368627,"user":{"login":"soveran","id":951,"avatar_url":"https://avatars.githubusercontent.com/u/951?v=3","gravatar_id":"","url":"https://api.github.com/users/soveran","html_url":"https://github.com/soveran","followers_url":"https://api.github.com/users/soveran/followers","following_url":"https://api.github.com/users/soveran/following{/other_user}","gists_url":"https://api.github.com/users/soveran/gists{/gist_id}","starred_url":"https://api.github.com/users/soveran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soveran/subscriptions","organizations_url":"https://api.github.com/users/soveran/orgs","repos_url":"https://api.github.com/users/soveran/repos","events_url":"https://api.github.com/users/soveran/events{/privacy}","received_events_url":"https://api.github.com/users/soveran/received_events","type":"User","site_admin":false},"created_at":"2016-12-20T21:46:35Z","updated_at":"2016-12-20T21:46:35Z","body":"Yes, I think the fork can cover your use case indeed. Conceptually, I think about Ost this way: there will be expected errors and unexpected errors. For the expected errors, you must handle them in a way that makes sense for your use case. For example, in some cases you may want to send the item back to the queue. In other cases, you may want to push it to a different queue and send an email alert. There are many different things you may want to do for expected errors. The case that Ost covers for you with the backup queues is the situation when you encounter an unexpected error. The idea is that once that happens, you can analyze the error and decide how to deal with it moving forward. Once once you have decided how to deal with it, you can send it back to the queue."}}
{"actor":{"display_login":"soveran"}}