Closed timdown closed 2 months ago
Same issue with Rails 6, all versions tried so far, after upgrading from 5. Possibly related to this issue: https://github.com/collectiveidea/delayed_job/issues/1099
Same issue here. Happens in both development and production. Using the rake task (rake jobs:work
) seems to work ok. But that's not ideal for production mode
I am also facing same issue. Sometimes the delayed job starts.but sometime it is throwing error in both production and development environment Ruby version: 2.6 Rails version: 6.1
Same issue here
Same issue
Hey @timdown @roboyeti @marcoschicote @joshfester @jminterwebs
Did anyone get the solution to this issue? I m suffering from the same issue.
@ajaybhayani741 I ended up moving on to Sidekiq and it's been great. If that's a possibility for you, I would definitely recommend it
@ajaybhayani741, Yes unfortunately I complete forgot how. I was also dealing with isolating the worker into its own docker container as well.
Taking a shot in the dark on this but what ENV are you running in? I would check the config/delayed_job.rb
and make sure you are allowing the worker to run in the ENV/
Same issue when I use it in a transaction.
I believe it is closely related to the configuration option config.file_watcher = ActiveSupport::EventedFileUpdateChecker
But I have no solution other than to disable that configuration option.
Since the file_watcher
is not active in production environment I do not see the problem occur in that environment.
Ruby version: 2.7.4p191 Rails version: 6.1.7.2 DJ version: 4.1.11 listen version: 3.8.0 daemons version: 1.4.1 rb-inotify version: 0.10.1 linux system: debian 11 (bullseye)
For anyone still encountering this issue, I was able to identify the root issue with inspiration from this stackoverflow answer
When running the delayed job process in daemonized mode bundle exec ruby bin/delayed_job start
From current script generator:
!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(FILE), '..', 'config', 'environment')) require 'delayed/command' Delayed::Command.new(ARGV).daemonize
I too a look into the daemonize gem and found that when starting up, it actually CLOSES ALL IO STREAMS!!. Modifying global state is always fun 👍 .
Within the script file, it first boots Rails via loading config/environment
and especially with the config option eager_load = true
means that if there is any code during the bootup process that opens up IOs (e.g. I was opening up cache connections via the Dalli gem) will be closed after the call to daemonize
.
My current workaround is to ensure that Rails is loaded AFTER daemonize
#!/usr/bin/env ruby
require "delayed_job"
require "delayed_job_active_record"
require "delayed/command"
module LoadRailsAfterRunProc
def self.included base
after_fork_method = base.method(:after_fork)
base.define_singleton_method :after_fork do |*args|
# after Daemons.run_proc method
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
after_fork_method.call(*args)
end
end
end
Delayed::Worker.include(LoadRailsAfterRunProc)
Delayed::Command.new(ARGV).daemonize
This explains also why running it via rake rake jobs:work
does not have any issues as it does not daemonize the process.
@allenjgreer Your workaround solved it here on macOS and FreeBSD. Thank you very much!
Hello! Any ideas why there is no trace of the error if delayed_job
is started with an identifier (./bin/delayed_job -i 1234 start
) as indicated in #1172?
Closing stale
Hey @albus522 or other maintainers. How do we get the fix proposed by @allenjgreer incorporated in to the delayed_job startup script so it stop affecting new implementations, and update the README or some other upgrade notes for existing apps?
Is it supposed to go in lib/generators/delayed_job/templates/script
? I've been fighting with this for ages. It definitely shouldn't be a closed issue in my opinion.
I'd be happy to contribute a PR, if it is likely to be accepted (in a reasonable timescale.)
Steps to reproduce:
gem 'daemons'
andgem 'delayed_job_active_record'
to Gemfilebundle install
bundle exec rails generate delayed_job:active_record
thenbundle exec rake db:migrate
bundle exec ruby bin/delayed_job start
This does not happen with DJ 4.1.9 in Rails 6.0.3.4. I've tried it on macOS and the error does not appear. I've also tried changing the Ruby version to 3.0.0 and the error still appears.