Repository navigation
undefined method `collect' for nil:NilClass Sidekiq doesnt start, faild to load cron #108
Copy link
Copy link
Closed
Description
Issue description
Im trying to implement sidekiq-scheduler or sidekiq-cron, I got an error at starting sidekiq
How to reproduce
gem 'sidekiq', '7.2.0'
gem "sidekiq-scheduler", "~> 5.0"
gem "fugit", "1.11.1"
then run: bundle exec sidekiq
Following the code, I found that the issue is here : /Users/xx/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rb
def do_determine(key, arr, min, max)
null = false
r = arr
.collect { |v|
expand(min, max, v) }
.flatten(1)
.collect { |e|
return false if e == false
null = null || e == nil
(key == :hours && e == 24) ? 0 : e }
return nil if null
r.uniq.sort
endI try it in the console too:
Loading development environment (Rails 7.1.4)
irb(main):001> require 'fugit'
=> false
irb(main):002> Fugit::Cron.parse('0 1 * * *')
(irb):2:in `<main>': undefined method `collect' for nil:NilClass (NoMethodError)
.collect { |v|
^^^^^^^^
Did you mean? collectionizeError and error backtrace (if any)
(This should look like:
2024-09-05T11:46:53.088Z pid=95410 tid=1rsu INFO: Booted Rails 7.1.2 application in development environment
2024-09-05T11:46:53.088Z pid=95410 tid=1rsu INFO: Running in ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
2024-09-05T11:46:53.088Z pid=95410 tid=1rsu INFO: See LICENSE and the LGPL-3.0 for licensing details.
2024-09-05T11:46:53.088Z pid=95410 tid=1rsu INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
2024-09-05T11:46:53.088Z pid=95410 tid=1rsu INFO: Sidekiq 7.2.0 connecting to Redis with options {:size=>10, :pool_name=>"internal", :url=>"redis://localhost:6379/0"}
2024-09-05T11:46:53.090Z pid=95410 tid=1rsu INFO: Sidekiq 7.2.0 connecting to Redis with options {:size=>5, :pool_name=>"default", :url=>"redis://localhost:6379/0"}
2024-09-05T11:46:53.091Z pid=95410 tid=1rsu INFO: Loading Schedule
2024-09-05T11:46:53.091Z pid=95410 tid=1rsu INFO: Schedule empty! Set Sidekiq.schedule
2024-09-05T11:46:53.091Z pid=95410 tid=1rsu INFO: Schedules Loaded
2024-09-05T11:46:53.093Z pid=95410 tid=1rsu INFO: Reloading Schedule
2024-09-05T11:46:53.094Z pid=95410 tid=1rsu INFO: Loading Schedule
2024-09-05T11:46:53.094Z pid=95410 tid=1rsu INFO: Scheduling test_schedule_job {"cron"=>"0 * * * * *", "class"=>"TestScheduleJob", "queue"=>"scheduler"}
2024-09-05T11:46:53.094Z pid=95410 tid=1rsu WARN: {"context":"Exception during Sidekiq lifecycle event.","event":"startup"}
2024-09-05T11:46:53.095Z pid=95410 tid=1rsu WARN: NoMethodError: undefined method `collect' for nil:NilClass
2024-09-05T11:46:53.095Z pid=95410 tid=1rsu WARN: config/initializers/sidekiq.rb:13:in `block (2 levels) in <main>'
undefined method `collect' for nil:NilClass
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rb:649:in `do_determine'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rb:666:in `determine_minutes'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rb:568:in `init'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rb:43:in `parse'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rb:48:in `do_parse'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rufus-scheduler-3.9.2/lib/rufus/scheduler/jobs_repeat.rb:271:in `initialize'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rufus-scheduler-3.9.2/lib/rufus/scheduler.rb:724:in `new'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rufus-scheduler-3.9.2/lib/rufus/scheduler.rb:724:in `do_schedule'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rufus-scheduler-3.9.2/lib/rufus/scheduler.rb:226:in `cron'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:266:in `new_job'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:130:in `block in load_schedule_job'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:123:in `each'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:123:in `load_schedule_job'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:101:in `block in load_schedule!'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:99:in `each'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:99:in `load_schedule!'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-scheduler-5.0.6/lib/sidekiq-scheduler/scheduler.rb:208:in `reload_schedule!'
/Users/luiscastillo/projects/vangow/vangow-api/config/initializers/sidekiq.rb:13:in `block (2 levels) in <main>'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-7.2.0/lib/sidekiq/component.rb:60:in `block in fire_event'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-7.2.0/lib/sidekiq/component.rb:59:in `each'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-7.2.0/lib/sidekiq/component.rb:59:in `fire_event'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-7.2.0/lib/sidekiq/cli.rb:106:in `run'
/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/sidekiq-7.2.0/bin/sidekiq:31:in `<top (required)>')
Expected behaviour
Sidekiq starts normally and schedules jobs work.
Context
It is a rails api project using mongodb
Additional context
test_schedule_job:
cron: '0 1 * * *'
class: TestScheduleJob
queue: scheduler# config/initializer/sidekiq.rb
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = { url: ENV.fetch('REDIS_URL', nil) }
end
Sidekiq.configure_server do |config|
config.redis = { url: ENV.fetch('REDIS_URL', nil) }
config.on(:startup) do
Sidekiq.schedule = YAML.load_file(File.expand_path('../schedule.yml', __dir__))
SidekiqScheduler::Scheduler.instance.reload_schedule!
end
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Sidekiq doesnt start, faild to load cron[/-][+]undefined method `collect' for nil:NilClass Sidekiq doesnt start, faild to load cron[/+]jeromedalbert commentedon Sep 5, 2024
I am not immediately able to repro your issue as
Fugit::Cron.parse('0 1 * * *')works fine for me in the console. In order to repro more reliably, maybe you could provide a minimal example app that has the problem?lekastillo commentedon Sep 5, 2024
It is weird, I have another project with the same ruby, rails, sidekiq, sidekiq-sheduler and fugit version, and it works fine.
the only difference is this project is a normal ruby on rails app, and Where it is failing it's a --api project.
Does it have some dependency to work fine in ruby on rails --api flagged app?
jmettraux commentedon Sep 5, 2024
Good afternoon,
(question A)
in the section "Context" of the issue template, you forgot to run the following commands and to paste their output:
jmettraux commentedon Sep 5, 2024
@lekastillo escribió:
No, fugit is a Ruby library, there is nothing in it about Ruby on Rails. Fugit tries its best to be a good Ruby citizen, to do its jobs and not to get in the way of other libraries or in the way of frameworks.
jmettraux commentedon Sep 5, 2024
Question B @lekastillo
In your no
--apiproject that works, runbundle listand paste the result here in an answer.In your non-working
--apiproject runbundle listand paste the result here in an answer.jmettraux commentedon Sep 5, 2024
Question C @lekastillo
Use the
cron.rbfile at https://github.com/proxy/gist.github.com/jmettraux/ec73683e8e0d513381bfd47f1e296f0d and replace thecron.rbat/Users/luiscastillo/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/fugit-1.11.1/lib/fugit/cron.rbwith it.Then try again. Please paste here the resulting trace/log in your answer.
It might be very interesting to the do same with your working, non
--api, setup to compare the two traces/logs.(trying in the console like you did at the top of the thread should be sufficient)
Thanks in advance.
lekastillo commentedon Sep 5, 2024
Hello, @jmettraux here are the things you asked me for, please let me know if you need something else.
(question A)
uname -a
Darwin Luiss-MacBook-Pro.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64bundle exec ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]bundle exec ruby -e "p [ :env_tz, ENV['TZ'] ]"
[:env_tz, nil]bundle exec ruby -r et-orbi -e "EtOrbi._make_info"
bundle exec ruby -r et-orbi -e "p [ :et_orbi, EtOrbi::VERSION ]"
[:et_orbi, "1.2.11"]bundle exec ruby -e "require 'fugit'; p [ :fugit, Fugit::VERSION ]"
[:fugit, "1.11.1"]bundle exec ruby -e "p [ :now, Time.now, :zone, Time.now.zone ]"
[:now, 2024-09-05 15:09:17.955175 -0600, :zone, "CST"]Question B
** no --api projects that works **
** non-working --api project **
Question C
jmettraux commentedon Sep 5, 2024
@lekastillo Hello, I see you have answers which state
Rails 7.1.2and other answers that stateRails 7.1.4. Do you see the problem on both version of Ruby on Rails?jmettraux commentedon Sep 5, 2024
@lekastillo your "--api" and "no --api" setups appear to be totally different. Look at
Zeitwekit's 2.6.18 in your "--api" setup and 2.6.12 in the other.My hypothesis is that a gem is interfering with the fugit gem or the raabro gem (they are 1.11 / 1.4.0 respectively in both your setups).
Your affirmation is that fugit fails when "--api" and not when it's not present. Fair enough, but you are comparing two wildly different setups. I need you to set up two environments, one that is "--api" and the other not, but that have similar gem versions. The diff I computed for you is wildly off.
Thanks in advance for two gem lists that make it easy to pinpoint what is wrong. And please
Rails 7.1.2orRails 7.1.4, notand/or.jmettraux commentedon Sep 6, 2024
Note in passing.
correct debug output:
incorrect debug output as observed in one of Luis' setup:
Update: the tree as seen from
raabrodebug is the same. The issue might be in how the raabro based parser rewrites the tree. In the faulty output, the key seems to be alwaysnil, while the desired output should like:min,:hou,:dom, etc.jmettraux commentedon Sep 6, 2024
@lekastillo Could you please, when you have the time, replace your cron.rb with the one at https://github.com/proxy/gist.github.com/jmettraux/74fc0d0751e5f3188237174d5fcc526a ? Then run your
Fugit::Cron.parse('0 1 * * *')with it on one of your faulty setups and paste the result in your answer?Thanks in advance.
lekastillo commentedon Sep 6, 2024
@jmettraux done
jmettraux commentedon Sep 6, 2024
Something gets in the way of
Raabro::Tree#name, the correct output isSomething in the setup makes
Raabro::Tree#namealways returnnil. Since#nameis merely an attribute accessor, it could also be that theRaabro::Treeinstance is fed withnilat initialization... Digging in...jmettraux commentedon Sep 6, 2024
@lekastillo Could you please, when you have the time, replace your cron.rb with the one at https://github.com/proxy/gist.github.com/jmettraux/05e892291a5d27601a9d8759fb0d9f36 ? Then run your
Fugit::Cron.parse('0 1 * * *')with it on one of your faulty setups and paste the result in your answer?It should indicate where
Raabro::Tree#nameis sourced.Thanks in advance.
lekastillo commentedon Sep 6, 2024
@jmettraux done
jmettraux commentedon Sep 6, 2024
@lekastillo Thanks. I need to dig more. Meanwhile, I am still waiting for a tighter bundle list diff from you as stated in #108 (comment)
lekastillo commentedon Sep 6, 2024
@jmettraux I created two new projects with rails 7.1.2 one with option
--apiand other without that. And it is working fine 🤔Maybe one of my project gem.
rails _7.1.2_ new my_api --apirails _7.1.2_ new my_appThen I added
bundle add fugitApp without
--apiApp with
--apiGemfile Project without --api
Gemfile Project with --api
jmettraux commentedon Sep 6, 2024
OK, solved, then I am closing this issue.
Best regards.
lekastillo commentedon Sep 6, 2024
Hey @jmettraux In a new project with default gems work.
I started to remove each gem in my gemfile and I found this gem was causing the issue.
# gem 'nice_hash'I commented and then works fine
lekastillo commentedon Sep 6, 2024
Thanks @jmettraux for your help
jmettraux commentedon Sep 6, 2024
Well done!
jmettraux commentedon Sep 6, 2024
List
nice_hashunder KNOWN ISSUES 36b3257