Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whenever gem 1.0.0 compatibility issue #3

Closed
mzagaja opened this issue Feb 24, 2022 · 2 comments
Closed

whenever gem 1.0.0 compatibility issue #3

mzagaja opened this issue Feb 24, 2022 · 2 comments

Comments

@mzagaja
Copy link
Contributor

mzagaja commented Feb 24, 2022

When attempting to update an app to whenever 1.0.0 the deployment throws the following error:

Whenever and cron_swanson throw the following error on deployment to staging:

export RAILS_ENV="staging" ; /usr/local/rvm/bin/rvm 2.7.5 do bundle exec whenever --update-crontab acme_staging --set environment=staging --roles=web,app,db,cron,waiting_room_upstart,delayed_job_upstart
Traceback (most recent call last):
	17: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/bin/ruby_executable_hooks:22:in `<main>'
	16: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/bin/ruby_executable_hooks:22:in `eval'
	15: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/bin/whenever:23:in `<main>'
	14: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/bin/whenever:23:in `load'
	13: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/bin/whenever:44:in `<top (required)>'
	12: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever/command_line.rb:6:in `execute'
	11: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever/command_line.rb:38:in `run'
	10: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever/command_line.rb:109:in `updated_crontab'
	 9: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever/command_line.rb:57:in `whenever_cron'
	 8: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever.rb:12:in `cron'
	 7: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever.rb:12:in `new'
	 6: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever/job_list.rb:25:in `initialize'
	 5: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/whenever-1.0.0/lib/whenever/job_list.rb:25:in `instance_eval'
	 4: from config/schedule.rb:19:in `initialize'
	 3: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/cron_swanson-0.3.4/lib/cron_swanson/whenever.rb:73:in `schedule'
	 2: from /var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/cron_swanson-0.3.4/lib/cron_swanson/whenever.rb:73:in `instance_eval'
	 1: from config/schedule.rb:21:in `block in initialize'
/var/www/acme/staging/master/shared/bundle/ruby/2.7.0/gems/cron_swanson-0.3.4/lib/cron_swanson/whenever.rb:102:in `method_missing': environment is not defined. Call `job_type` to resolve this. (RuntimeError)

:whenever_environment is just using the default value from the gem and changing to -> { fetch(:stage) } did not impact this error. I'm guessing this gem has to account for a change in the whenever gem potentially related to javan/whenever#728 or javan/whenever#719. However if you think it might be a change that needs to be made to a deploy.rb or such locally, I'm open to suggestions.

@alexdean
Copy link
Owner

cron_swanson is intercepting calls to the whenever job list.

# execute the block in the context of CronSwanson::Whenever (rather than in the context
# of the Whenever::JobList where it will be invoked) so that we can intercept
# calls to `rake` and similar (via method_missing below).
instance_eval(&block)

it looks like a method environment is now being called, but the job list doesn't implement this method.

if @whenever_job_list.respond_to?(m)
@whenever_jobs << [m, args, block]
else
raise "#{m} is not defined. Call `job_type` to resolve this."
end

can you confirm if this happens in all crontabs, or could it be specific to the one you're trying to deploy? (are you making a call to environment somewhere?)

@mzagaja
Copy link
Contributor Author

mzagaja commented May 11, 2022

Apologies for the delayed reply, I apparently missed or accidentally nuked the notification!

We do in fact call environment from within schedule.rb in the following manner:

swanson.schedule(interval: 2.minutes, roles: [:waiting_room_upstart]) do
  services = [
    "acme_master_#{environment}_waiting_room_consumer",
    "acme_master_#{environment}_waiting_room_publisher",
  ]
  script "acme_upstart_angel #{services.join(' ')}"
end
swanson.schedule(interval: 2.minutes, roles: [:delayed_job_upstart]) do
  script "acme_upstart_angel acme_master_#{environment}_delayed_job_supervisor"
end

I can confirm removing these above entries resolves this issue, so appreciate the hint/pointer on calling environment.

I can also share that the issue presents in v0.10.0 of whenever. I see that there is a new method_missing method in job_list.rb.

However debugging with a debugger shows me the difference in values of environment in v0.9.7:

[15, 24] in config/schedule.rb
    15| #   2. config/deploy.rb can have only `set :whenever_roles, %w(cron)`
    16| #   3. script/acme_upstart_angel can be deleted
    17| #
    18| # https://www.pivotaltracker.com/story/show/172502059
    19| swanson.schedule(interval: 2.minutes, roles: [:waiting_room_upstart]) do
=>  20|   debugger
    21|   services = [
    22|     "acme_master_#{environment}_waiting_room_consumer",
    23|     "acme_master_#{environment}_waiting_room_publisher",
    24|   ]
=>#0	block in initialize at config/schedule.rb:20
  #1	[C] BasicObject#instance_eval at ~/.rvm/gems/ruby-2.7.5@acme/gems/cron_swanson-0.3.4/lib/cron_swanson/whenever.rb:73
  # and 13 frames (use `bt' command for all frames)
(rdbg) environment
[[:environment, [], nil]]

vesus v0.10.0

[15, 24] in config/schedule.rb
    15| #   2. config/deploy.rb can have only `set :whenever_roles, %w(cron)`
    16| #   3. script/acme_upstart_angel can be deleted
    17| #
    18| # https://www.pivotaltracker.com/story/show/172502059
    19| swanson.schedule(interval: 2.minutes, roles: [:waiting_room_upstart]) do
=>  20|   debugger
    21|   services = [
    22|     "acme_master_#{environment}_waiting_room_consumer",
    23|     "acme_master_#{environment}_waiting_room_publisher",
    24|   ]
=>#0	block in initialize at config/schedule.rb:20
  #1	[C] BasicObject#instance_eval at ~/.rvm/gems/ruby-2.7.5@acme/gems/cron_swanson-0.3.4/lib/cron_swanson/whenever.rb:73
  # and 13 frames (use `bt' command for all frames)
(rdbg) environment
eval error: environment is not defined. Call `job_type` to resolve this.
  /Users/mzagaja/.rvm/gems/ruby-2.7.5@acme/gems/cron_swanson-0.3.4/lib/cron_swanson/whenever.rb:102:in `method_missing'
  (rdbg)/config/schedule.rb:1:in `block in initialize'
nil

The easy solution here seems to be replace environment with Rails.env but given the change occurred in whenever, I am now disinclined to suggest cron_swanson needs to change in relation to this. Thanks again for responding to this and pointing me in the right direction!

@mzagaja mzagaja closed this as completed May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants