{"action":"created","issue":{"url":"https://api.github.com/repos/mperham/sidekiq/issues/2154","labels_url":"https://api.github.com/repos/mperham/sidekiq/issues/2154/labels{/name}","comments_url":"https://api.github.com/repos/mperham/sidekiq/issues/2154/comments","events_url":"https://api.github.com/repos/mperham/sidekiq/issues/2154/events","html_url":"https://github.com/mperham/sidekiq/issues/2154","id":55511344,"number":2154,"title":"Beta2: `Sidekiq::Batch::NoSuchBatch` error when nesting several levels deep","user":{"login":"plukevdh","id":16054,"avatar_url":"https://avatars.githubusercontent.com/u/16054?v=3","gravatar_id":"","url":"https://api.github.com/users/plukevdh","html_url":"https://github.com/plukevdh","followers_url":"https://api.github.com/users/plukevdh/followers","following_url":"https://api.github.com/users/plukevdh/following{/other_user}","gists_url":"https://api.github.com/users/plukevdh/gists{/gist_id}","starred_url":"https://api.github.com/users/plukevdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plukevdh/subscriptions","organizations_url":"https://api.github.com/users/plukevdh/orgs","repos_url":"https://api.github.com/users/plukevdh/repos","events_url":"https://api.github.com/users/plukevdh/events{/privacy}","received_events_url":"https://api.github.com/users/plukevdh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-26T17:27:29Z","updated_at":"2015-01-26T17:33:28Z","closed_at":null,"body":"Using the following (very) contrived example, Sidekiq seems unable to find batches on certain runs when the callback stack starts to unwind:\r\n\r\n```ruby\r\nrequire_relative '../setup'\r\n\r\n## Abstract Classes\r\n\r\nclass BaseJob\r\n  include Sidekiq::Worker\r\n\r\n  def perform\r\n    batch = Sidekiq::Batch.new\r\n    batch.on :complete, CompletionHandler, level: self.class::LEVEL\r\n    batch.on :success, CompletionHandler, level: self.class::LEVEL\r\n\r\n    funk_with_time\r\n\r\n    batch.jobs do\r\n      self.class::NEST.send :perform_async if defined? self.class::NEST\r\n    end\r\n  end\r\n\r\n  def funk_with_time\r\n    time = rand(5) + 1\r\n    puts \"running job level #{self.class::LEVEL} for #{time} seconds\"\r\n    sleep time\r\n    puts \"#{self.class::LEVEL} level complete\"\r\n  end\r\nend\r\n\r\nclass NestingJob < BaseJob\r\n  include Sidekiq::Worker\r\n\r\n  def perform\r\n    batch.jobs do\r\n      super\r\n    end\r\n  end\r\nend\r\n\r\n## Concrete Classes\r\n\r\nclass JobLevelFour < NestingJob\r\n  LEVEL = 4\r\nend\r\n\r\nclass JobLevelThree < NestingJob\r\n  LEVEL = 3\r\n  NEST = JobLevelFour\r\nend\r\n\r\nclass JobLevelTwo < NestingJob\r\n  LEVEL = 2\r\n  NEST = JobLevelThree\r\nend\r\n\r\nclass JobLevelOne < BaseJob\r\n  LEVEL = 1\r\n  NEST = JobLevelTwo\r\nend\r\n\r\n# Completion Handler.\r\n\r\nclass CompletionHandler\r\n  def on_complete(status, options)\r\n    puts \"#{options['level']} COMPLETE callback fired\"\r\n  end\r\n\r\n  def on_success(status, options)\r\n    puts \"#{options['level']} SUCCESS callback fired\"\r\n  end\r\nend\r\n```\r\n\r\n```\r\n2015-01-26T17:23:10.860Z 57797 TID-ouuubhpgw Sidekiq::Batch::Callback JID-5a4d85990851d2b11ee6bc06 INFO: fail: 0.002 sec\r\n2015-01-26T17:23:10.861Z 57797 TID-ouuubhpgw WARN: {\"retry\"=>true, \"queue\"=>\"default\", \"class\"=>\"Sidekiq::Batch::Callback\", \"args\"=>[\"success\", \"_rAUd6LrjuvAFQ\", \"default\"], \"jid\"=>\"5a4d85990851d2b11ee6bc06\", \"enqueued_at\"=>1422292990.850067, \"error_message\"=>\"Couldn't find Batch _rAUd6LrjuvAFQ in redis\", \"error_class\"=>\"Sidekiq::Batch::NoSuchBatch\", \"failed_at\"=>1422292990.859209, \"retry_count\"=>0}\r\n2015-01-26T17:23:10.861Z 57797 TID-ouuubhpgw WARN: Couldn't find Batch _rAUd6LrjuvAFQ in redis\r\n```\r\n\r\nCan provide full stack trace on request."},"comment":{"url":"https://api.github.com/repos/mperham/sidekiq/issues/comments/71500975","html_url":"https://github.com/mperham/sidekiq/issues/2154#issuecomment-71500975","issue_url":"https://api.github.com/repos/mperham/sidekiq/issues/2154","id":71500975,"user":{"login":"mperham","id":2911,"avatar_url":"https://avatars.githubusercontent.com/u/2911?v=3","gravatar_id":"","url":"https://api.github.com/users/mperham","html_url":"https://github.com/mperham","followers_url":"https://api.github.com/users/mperham/followers","following_url":"https://api.github.com/users/mperham/following{/other_user}","gists_url":"https://api.github.com/users/mperham/gists{/gist_id}","starred_url":"https://api.github.com/users/mperham/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mperham/subscriptions","organizations_url":"https://api.github.com/users/mperham/orgs","repos_url":"https://api.github.com/users/mperham/repos","events_url":"https://api.github.com/users/mperham/events{/privacy}","received_events_url":"https://api.github.com/users/mperham/received_events","type":"User","site_admin":false},"created_at":"2015-01-26T17:33:28Z","updated_at":"2015-01-26T17:33:28Z","body":"Figured it out, never mind."}}