{"action":"opened","issue":{"url":"https://api.github.com/repos/mhenrixon/sidekiq-unique-jobs/issues/151","labels_url":"https://api.github.com/repos/mhenrixon/sidekiq-unique-jobs/issues/151/labels{/name}","comments_url":"https://api.github.com/repos/mhenrixon/sidekiq-unique-jobs/issues/151/comments","events_url":"https://api.github.com/repos/mhenrixon/sidekiq-unique-jobs/issues/151/events","html_url":"https://github.com/mhenrixon/sidekiq-unique-jobs/issues/151","id":119957003,"number":151,"title":"Can't schedule a job from another job","user":{"login":"heaven","id":126732,"avatar_url":"https://avatars.githubusercontent.com/u/126732?v=3","gravatar_id":"","url":"https://api.github.com/users/heaven","html_url":"https://github.com/heaven","followers_url":"https://api.github.com/users/heaven/followers","following_url":"https://api.github.com/users/heaven/following{/other_user}","gists_url":"https://api.github.com/users/heaven/gists{/gist_id}","starred_url":"https://api.github.com/users/heaven/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heaven/subscriptions","organizations_url":"https://api.github.com/users/heaven/orgs","repos_url":"https://api.github.com/users/heaven/repos","events_url":"https://api.github.com/users/heaven/events{/privacy}","received_events_url":"https://api.github.com/users/heaven/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-02T14:46:39Z","updated_at":"2015-12-02T14:46:39Z","closed_at":null,"body":"My code is the next:\r\n\r\n```ruby\r\nclass PhoneMessage < ActiveRecord::Base\r\n  def queue\r\n    if self.persisted? and not self.sent?\r\n      Worker::SmsSender.perform_async(self.id)\r\n    end\r\n  end\r\n\r\n  def queue_status_check\r\n    if self.persisted? and self.sent?\r\n      Worker::SmsStatusUpdater.perform_at(10.seconds, self.id)\r\n      Worker::SmsStatusUpdater.perform_at(1.minute, self.id)\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nWorker 1:\r\n\r\n```ruby\r\nclass Worker::SmsSender\r\n  include Sidekiq::Worker\r\n\r\n  sidekiq_options :unique => :until_executed, :unique_expiration => 100.years\r\n\r\n  def perform(message_id)\r\n    message = PhoneMessage.where(:id => message_id).first\r\n    return unless message and not message.sent?\r\n\r\n    number = message.phone_number\r\n    return unless number.present?\r\n\r\n    twilio_message = Twilio::REST::Client.new.account.messages.create(\r\n      :from => Settings.twilio.from_number,\r\n      :to => message.phone_number,\r\n      :body => message.text\r\n    )\r\n\r\n    message.sent!(twilio_message.sid)\r\n    message.queue_status_check # This doesn't work\r\n  end\r\nend\r\n```\r\n\r\nWorker 2:\r\n\r\n```ruby\r\nclass Worker::SmsStatusUpdater\r\n  include Sidekiq::Worker\r\n\r\n  sidekiq_options :unique => :until_executing, :unique_expiration => 100.years\r\n\r\n  def perform(message_id)\r\n    message = PhoneMessage.where(:id => message_id).first\r\n    return unless message and message.sent?\r\n\r\n    twilio_message = Twilio::REST::Client.new.account.messages.get(message.message_sid)\r\n\r\n    message.update_attribute(:status, twilio_message.status)\r\n    message.queue_status_check if message[:status] < 4\r\n  end\r\nend\r\n```\r\n\r\nFirst worker has until_executed while the second one has until_executing (it also calls `message.queue_status_check` so by idea could re-schedule itself).\r\n\r\nWithout the sidekiq_options both workers work as expected:\r\n\r\n```\r\n2015-12-02T14:37:53.028Z 30357 TID-117r950 DEBUG: Middleware: Sidekiq::Middleware::Server::Logging, Sidekiq::Middleware::Server::RetryJobs, Sidekiq::Middleware::Server::ActiveRecord, SidekiqUniqueJobs::Server::Middleware, Sidekiq::Status::ServerMiddleware\r\n2015-12-02T14:37:53.028Z 30357 TID-117r950 INFO: Starting processing, hit Ctrl-C to stop\r\n2015-12-02T14:37:53.097Z 30357 TID-117r950 DEBUG: {:queues=>[\"default\", \"mailers\", \"import\", \"export\"], :labels=>[], :concurrency=>4, :require=>\".\", :environment=>nil, :timeout=>15, :poll_interval_average=>nil, :average_scheduled_poll_interval=>15, :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x0000010dd160b0>], :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[]}, :dead_max_jobs=>10000, :dead_timeout_in_seconds=>15552000, :pidfile=>\"./tmp/pids/sidekiq.pid\", :config_file=>\"config/sidekiq-dev.yml\", :strict=>true, :tag=>\"crm\"}\r\n2015-12-02T14:38:42.239Z 30357 TID-130c7m0 Worker::SmsSender JID-06774f37f646e106df47cf89 INFO: start\r\n2015-12-02T14:38:44.734Z 30357 TID-130c7m0 Worker::SmsSender JID-06774f37f646e106df47cf89 INFO: done: 2.495 sec\r\n2015-12-02T14:39:07.201Z 30357 TID-130c7wk DEBUG: enqueued schedule: {\"class\":\"Worker::SmsStatusUpdater\",\"args\":[20],\"retry\":true,\"queue\":\"default\",\"jid\":\"a9a46c2099ed3d0e96adca11\",\"created_at\":1449067124.732828}\r\n2015-12-02T14:39:07.202Z 30357 TID-130c7m0 Worker::SmsStatusUpdater JID-a9a46c2099ed3d0e96adca11 INFO: start\r\n2015-12-02T14:39:10.562Z 30357 TID-130c7m0 Worker::SmsStatusUpdater JID-a9a46c2099ed3d0e96adca11 INFO: done: 3.361 sec\r\n2015-12-02T14:39:47.599Z 30357 TID-130ej5s Worker::SmsStatusUpdater JID-51a88bae95eea6af3331adc5 INFO: start\r\n2015-12-02T14:39:47.599Z 30357 TID-130c7wk DEBUG: enqueued schedule: {\"class\":\"Worker::SmsStatusUpdater\",\"args\":[20],\"retry\":true,\"queue\":\"default\",\"jid\":\"51a88bae95eea6af3331adc5\",\"created_at\":1449067124.733674}\r\n2015-12-02T14:39:49.262Z 30357 TID-130ej5s Worker::SmsStatusUpdater JID-51a88bae95eea6af3331adc5 INFO: done: 1.663 sec\r\n```\r\n\r\n With these options the output is as follows:\r\n\r\n```\r\n2015-12-02T14:42:53.051Z 30776 TID-10vw8i0 DEBUG: Middleware: Sidekiq::Middleware::Server::Logging, Sidekiq::Middleware::Server::RetryJobs, Sidekiq::Middleware::Server::ActiveRecord, SidekiqUniqueJobs::Server::Middleware, Sidekiq::Status::ServerMiddleware\r\n2015-12-02T14:42:53.051Z 30776 TID-10vw8i0 INFO: Starting processing, hit Ctrl-C to stop\r\n2015-12-02T14:42:53.117Z 30776 TID-10vw8i0 DEBUG: {:queues=>[\"default\", \"mailers\", \"import\", \"export\"], :labels=>[], :concurrency=>4, :require=>\".\", :environment=>nil, :timeout=>15, :poll_interval_average=>nil, :average_scheduled_poll_interval=>15, :error_handlers=>[#<Sidekiq::ExceptionHandler::Logger:0x00000109fad160>], :lifecycle_events=>{:startup=>[], :quiet=>[], :shutdown=>[]}, :dead_max_jobs=>10000, :dead_timeout_in_seconds=>15552000, :pidfile=>\"./tmp/pids/sidekiq.pid\", :config_file=>\"config/sidekiq-dev.yml\", :strict=>true, :tag=>\"crm\"}\r\n2015-12-02T14:43:13.841Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a INFO: start\r\n2015-12-02T14:43:16.915Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a SidekiqUniqueJobs::UniqueArgs DEBUG: unique_args : unique arguments disabled\r\n2015-12-02T14:43:16.915Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a SidekiqUniqueJobs::UniqueArgs DEBUG: unique_digest : {\"class\"=>\"Worker::SmsStatusUpdater\", \"queue\"=>\"default\", \"unique_args\"=>[21]} into uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710\r\n2015-12-02T14:43:16.916Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a DEBUG: successfully locked uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710 for 3155760009 seconds\r\n2015-12-02T14:43:16.917Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a SidekiqUniqueJobs::UniqueArgs DEBUG: unique_args : unique arguments disabled\r\n2015-12-02T14:43:16.917Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a SidekiqUniqueJobs::UniqueArgs DEBUG: unique_digest : {\"class\"=>\"Worker::SmsStatusUpdater\", \"queue\"=>\"default\", \"unique_args\"=>[21]} into uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710\r\n2015-12-02T14:43:16.918Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a DEBUG: failed to aquire lock for uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710\r\n2015-12-02T14:43:16.918Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a SidekiqUniqueJobs::UniqueArgs DEBUG: unique_args : unique arguments disabled\r\n2015-12-02T14:43:16.918Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a DEBUG: unique_digest : {\"class\"=>\"Worker::SmsSender\", \"queue\"=>\"default\", \"unique_args\"=>[21]} into uniquejobs:cd8993a7e26f7e392a67b813bed400a0\r\n2015-12-02T14:43:16.920Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a DEBUG: successfully unlocked uniquejobs:cd8993a7e26f7e392a67b813bed400a0\r\n2015-12-02T14:43:16.920Z 30776 TID-12jtv8k Worker::SmsSender JID-9e40a8a29caffc759b23017a INFO: done: 3.079 sec\r\n2015-12-02T14:43:34.794Z 30776 TID-12ju9v8 SidekiqUniqueJobs::UniqueArgs DEBUG: unique_args : unique arguments disabled\r\n2015-12-02T14:43:34.795Z 30776 TID-12ju9v8 DEBUG: unique_digest : {\"class\"=>\"Worker::SmsStatusUpdater\", \"queue\"=>\"default\", \"unique_args\"=>[21]} into uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710\r\n2015-12-02T14:43:34.795Z 30776 TID-12ju9v8 DEBUG: failed to aquire lock for uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710\r\n2015-12-02T14:43:34.795Z 30776 TID-12ju9v8 DEBUG: enqueued schedule: {\"class\":\"Worker::SmsStatusUpdater\",\"args\":[21],\"retry\":true,\"queue\":\"default\",\"unique\":\"until_executing\",\"unique_expiration\":\"3155760000.0\",\"jid\":\"86b88964eeea21e95325fec6\",\"created_at\":1449067396.914665,\"unique_prefix\":\"uniquejobs\",\"unique_args\":[21],\"unique_digest\":\"uniquejobs:b5ff82d3abdda99f6ade1266ebf4e710\"}\r\n```"}}