Repository: sidekiq-cron/sidekiq-cron (Ruby)

Issue:
LocalJumpError when embedding sidekiq on 2.2.0
Hello i tried to bump to 2.2.0

And in our case we are embedding sidekiq within puma process, following

https://github.com/sidekiq/sidekiq/wiki/Embedding#puma

On 2.2.0 we get 

`WARNING hook before_worker_boot failed with exception (LocalJumpError) break from proc-closure`

which i pinpointed to 

https://github.com/sidekiq-cron/sidekiq-cron/blob/master/lib/sidekiq/cron/schedule_loader.rb#L53

The fix that makes it work is to you change `break` to `next` as 

configure_embed is calling those procs as follows

https://github.com/sidekiq/sidekiq/blob/68b5462fb0a0a1a0299acb2edc0c7cff11e60f71/lib/sidekiq.rb#L130

and `break` stops the iterations

Please @markets can you confirm my reasoning is sound?


Discussion:
@tttffff What do you think? This change was introduced here: https://github.com/sidekiq-cron/sidekiq-cron/pull/543
@rafal-brize Seems reasonable to me (`break` -> `next`). But before moving on, I'd like to hear @tttffff thoughts on this one, as he implemented this change last week and maybe this was intentional for some reasons.
@markets thanks :)

`next` works fine for me. `break` was not an intentional choice.
Ok thanks! Would you mind to send a patch?
Happy to, and I would also like to capture this requirement in a test.
I should have some time over the next couple of days to do that.
@markets - I have created a PR for this including a test.

@rafal-brize - I could only replicate this when the configuration file does not exist. This makes sense, as the `break` is only called in that case, so it would not cause an issue if the file exists. However, it does beg the question: how is your configuration working without a valid schedule file?

Please can you confirm:
1) Have you configured the `cron_schedule_file` option e.g like stated [here](https://github.com/sidekiq-cron/sidekiq-cron?tab=readme-ov-file#configuration) AND does this file actually exist in your project?
2) Regardless of answer one, does the default file `config/schedule.yml` exist in your project?

@markets - There is a chance that there is a bug in the loading order when a `Sidekiq::Cron.configure` block is provided as an initializer, but the schedule loader has already been loaded before the initializer and has picked the default file name.
I do not believe that it was introduced by my change in #543 and it may be related to #507. I will investigate and create a new issue for this if required.
@tttffff you are correct.

We are not using the static schedule.yml and operate only on dynamic entries.
Thanks for fixing the issue, i tried the master branch and it works correctly!



Patch:
diff --git a/lib/sidekiq/cron/schedule_loader.rb b/lib/sidekiq/cron/schedule_loader.rb
index ecb5ac3..6ed855e 100644
--- a/lib/sidekiq/cron/schedule_loader.rb
+++ b/lib/sidekiq/cron/schedule_loader.rb
@@ -50,7 +50,7 @@ def yml_to_yaml_unless_file_exists(file_name)
 
 Sidekiq.configure_server do |config|
   schedule_loader = Sidekiq::Cron::ScheduleLoader.new
-  break unless schedule_loader.has_schedule_file?
+  next unless schedule_loader.has_schedule_file?
 
   config.on(:startup) { schedule_loader.load_schedule }
 end


Test patch:
diff --git a/test/unit/schedule_loader_test.rb b/test/unit/schedule_loader_test.rb
index 66db02a..2112443 100644
--- a/test/unit/schedule_loader_test.rb
+++ b/test/unit/schedule_loader_test.rb
@@ -6,6 +6,24 @@
     Sidekiq::Options[:lifecycle_events][:startup].clear
   end
 
+  describe 'Schedule file does not exist' do
+    before do
+      Sidekiq::Cron.configuration.cron_schedule_file = 'test/unit/fixtures/schedule_does_not_exist.yml'
+      load 'sidekiq/cron/schedule_loader.rb'
+    end
+
+    it 'does not add a sidekiq lifecycle startup event' do
+      assert_nil Sidekiq::Options[:lifecycle_events][:startup].first
+    end
+
+    sidekiq_version_has_embedded = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.0.0')
+    if sidekiq_version_has_embedded
+      it 'allows for sidekiq embedded configuration to be called without raising' do
+        Sidekiq.configure_embed {}
+      end
+    end
+  end
+
   describe 'Schedule is defined in hash' do
     before do
       Sidekiq::Cron.configuration.cron_schedule_file = 'test/unit/fixtures/schedule_hash.yml'