{"action":"closed","issue":{"url":"https://api.github.com/repos/nevans/resque-pool/issues/115","labels_url":"https://api.github.com/repos/nevans/resque-pool/issues/115/labels{/name}","comments_url":"https://api.github.com/repos/nevans/resque-pool/issues/115/comments","events_url":"https://api.github.com/repos/nevans/resque-pool/issues/115/events","html_url":"https://github.com/nevans/resque-pool/issues/115","id":51245966,"number":115,"title":"Resque worker shuts down when a terminal or ssh connection exits","user":{"login":"nisanth074","id":1789832,"avatar_url":"https://avatars.githubusercontent.com/u/1789832?v=3","gravatar_id":"","url":"https://api.github.com/users/nisanth074","html_url":"https://github.com/nisanth074","followers_url":"https://api.github.com/users/nisanth074/followers","following_url":"https://api.github.com/users/nisanth074/following{/other_user}","gists_url":"https://api.github.com/users/nisanth074/gists{/gist_id}","starred_url":"https://api.github.com/users/nisanth074/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nisanth074/subscriptions","organizations_url":"https://api.github.com/users/nisanth074/orgs","repos_url":"https://api.github.com/users/nisanth074/repos","events_url":"https://api.github.com/users/nisanth074/events{/privacy}","received_events_url":"https://api.github.com/users/nisanth074/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-12-08T03:47:47Z","updated_at":"2015-01-28T22:54:16Z","closed_at":"2015-01-28T22:54:16Z","body":"With resque-pool, a resque worker started from a terminal shuts down when the terminal exits\r\n```\r\nnohup bundle exec rake resque:work &\r\n```\r\n\r\nWhen the terminal exits, the worker's ppid becomes 1. The worker thinks its pool master has died (even though it isn't part of any pool) and shuts down.\r\n```ruby\r\n# https://github.com/nevans/resque-pool/blob/v0.3/lib/resque/pool/pooled_worker.rb\r\nmodule PooledWorker\r\n  def shutdown_with_pool\r\n    shutdown_without_pool || Process.ppid == 1\r\n  end  \r\n# ...\r\n```\r\nWe need to query the running status of the pool master only when the worker is part of a pool.\r\n\r\nA possible fix (borrowed from previous commits) is to save the process pid when Resque::Worker is initialized and use it later to determine if the worker is part of a pool.\r\n```ruby\r\ndef initialize(*args)\r\n  @__original_pid = Process.pid\r\nend\r\n\r\nalias_method :__shutdown?, :shutdown?\r\ndef shutdown?\r\n  return true if __shutdown?\r\n  pooled? && pool_master_has_gone_away?\r\nend\r\n\r\nprivate\r\n\r\ndef pooled?\r\n  Process.pid != @__original_pid\r\nend\r\n\r\ndef pool_master_has_gone_away?\r\n  Process.ppid == 1\r\nend\r\n```\r\nI've fixed this in a fork (https://github.com/SupportBee/resque-pool/commit/88d2537f49b247611ec7545b8f4d201eb2b4ca57) and would be happy to send in a pull request. Thanks."}}