{"action":"created","issue":{"url":"https://api.github.com/repos/platanus/capistrano3-delayed-job/issues/12","labels_url":"https://api.github.com/repos/platanus/capistrano3-delayed-job/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/platanus/capistrano3-delayed-job/issues/12/comments","events_url":"https://api.github.com/repos/platanus/capistrano3-delayed-job/issues/12/events","html_url":"https://github.com/platanus/capistrano3-delayed-job/issues/12","id":85921086,"number":12,"title":"Final pid file in pool is not written during restart","user":{"login":"synth","id":10546,"avatar_url":"https://avatars.githubusercontent.com/u/10546?v=3","gravatar_id":"","url":"https://api.github.com/users/synth","html_url":"https://github.com/synth","followers_url":"https://api.github.com/users/synth/followers","following_url":"https://api.github.com/users/synth/following{/other_user}","gists_url":"https://api.github.com/users/synth/gists{/gist_id}","starred_url":"https://api.github.com/users/synth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/synth/subscriptions","organizations_url":"https://api.github.com/users/synth/orgs","repos_url":"https://api.github.com/users/synth/repos","events_url":"https://api.github.com/users/synth/events{/privacy}","received_events_url":"https://api.github.com/users/synth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-07T17:20:34Z","updated_at":"2015-06-22T16:18:55Z","closed_at":null,"body":"In my app, we set the following dj capistrano variables in our config/deploy/production.rb\r\n\r\n    set :delayed_job_workers, 4\r\n    set :delayed_job_queues, ['priority', 'points', '*']\r\n    set :delayed_job_pools, {\r\n      'priority' => 1,\r\n      'points' => 1,\r\n      '*' => 2\r\n    }\r\n\r\nWhen we issue a cap production delayed_job:restart, what happens is that it stops all the jobs, and even starts them all up again, but the final delayed job process pid is not getting written. We end up with delayed_job.0.pid, delayed_job.1.pid, delayed_job.2.pid, but NOT delayed_job.3.pid. \r\n\r\nIf I run directly on production:\r\n\r\n    RAILS_ENV=production bin/delayed_job -n 4 --queues=priority,points,* --pool=priority:1 --pool=points:1 --pool=*:2 restart\r\n\r\nit restarts all the processes and drops all the correct pid files, but I noticed that the final pid file is dropped after the program exits. See below.\r\n\r\n````\r\n[web@xxxx current]$ RAILS_ENV=production bin/delayed_job -n 4 --queues=priority,points,* --pool=priority:1 --pool=points:1 --pool=*:2 restart\r\ndelayed_job.0: trying to stop process with pid 30603...\r\ndelayed_job.0: process with pid 30603 successfully stopped.\r\ndelayed_job.1: trying to stop process with pid 30609...\r\ndelayed_job.0: process with pid 30683 started.\r\ndelayed_job.1: process with pid 30609 successfully stopped.\r\ndelayed_job.2: trying to stop process with pid 30615...\r\ndelayed_job.1: process with pid 30699 started.\r\ndelayed_job.2: process with pid 30615 successfully stopped.\r\ndelayed_job.3: trying to stop process with pid 30621...\r\ndelayed_job.2: process with pid 30715 started.\r\ndelayed_job.3: process with pid 30621 successfully stopped.\r\n[web@xxxx current]$ delayed_job.3: process with pid 30728 started.\r\n\r\n[web@xxxx current]$\r\n````\r\n\r\nSo, it looks like there is some asynchronous behavior occurring. But why is the pid file not getting dropped when run under capistrano?"},"comment":{"url":"https://api.github.com/repos/platanus/capistrano3-delayed-job/issues/comments/114169234","html_url":"https://github.com/platanus/capistrano3-delayed-job/issues/12#issuecomment-114169234","issue_url":"https://api.github.com/repos/platanus/capistrano3-delayed-job/issues/12","id":114169234,"user":{"login":"dan-jensen","id":3031162,"avatar_url":"https://avatars.githubusercontent.com/u/3031162?v=3","gravatar_id":"","url":"https://api.github.com/users/dan-jensen","html_url":"https://github.com/dan-jensen","followers_url":"https://api.github.com/users/dan-jensen/followers","following_url":"https://api.github.com/users/dan-jensen/following{/other_user}","gists_url":"https://api.github.com/users/dan-jensen/gists{/gist_id}","starred_url":"https://api.github.com/users/dan-jensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dan-jensen/subscriptions","organizations_url":"https://api.github.com/users/dan-jensen/orgs","repos_url":"https://api.github.com/users/dan-jensen/repos","events_url":"https://api.github.com/users/dan-jensen/events{/privacy}","received_events_url":"https://api.github.com/users/dan-jensen/received_events","type":"User","site_admin":false},"created_at":"2015-06-22T16:18:55Z","updated_at":"2015-06-22T16:18:55Z","body":"I experienced this same issue, but for me it was less predictable.  With a larger number of workers, it seems PID files were missing at random.\r\n\r\nFor example, the following setting: \r\n```\r\nset :delayed_job_workers, 8\r\n```\r\n\r\nMight produce only these PID files:\r\n```\r\ndelayed_job.0.pid, delayed_job.1.pid, delayed_job.3.pid delayed_job.6.pid\r\n```\r\n\r\nI discovered this today when I started getting \"ENOENT: No such file or directory @ rb_sysopen\" errors from a job.  It turned out it was from one of these untracked Delayed Job processes that had survived 5+ Capistrano deployments.  This outdated process was looking for a file in a Capistrano release that was so old it didn't even exist on the server anymore.\r\n\r\nSOLUTION:  It turns out the missing PID files are due to a bug with the Daemons gem.  It has been fixed in the master branch on GitHub (see the pull request at https://github.com/thuehlinger/daemons/pull/29).  Unfortunately the fix hasn't been published to the gem yet.  So until it is, you can use the following line in your Gemfile to use the code on GitHub:\r\n```\r\ngem 'daemons', github: 'thuehlinger/daemons'\r\n```\r\n\r\n"}}