-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Cron start problem #1520
Comments
Are you in the development environment, or is this happening in production too? I ask because in Development, GoodJob tries not to initialize your application prematurely. That means it won't start until Active Record and Active Job is initialized. You might see if this does it:
|
Maybe your cron value is malformed? Every 2 minutes should be "*/2 * * * *" |
Soorry it was my copy / paste mistake, because it closed network I typed all code. In fact schedule is correct |
I also tried switching to -e production, but the behavior remained the same. Maybe you can tell me what is the trigger for starting a cron task and I might understand where the pitfalls might be |
Briefly:
And to confirm, your schedule means it runs at 1252, 1254, 1256, etc. It doesn't mean "run right now, and then 2 minutes later". Just want to make sure your expectations are correct. |
Thanks for the explanation! My expectations are that he will at least start. So far I have not been able to get it to start automatically. From the interface, if I click - run now, then it starts the job. I'll try to play with the threads. Perhaps there is something wrong in my environment, but it's confusing that there are no errors in the log. |
You can check out the GoodJob demo too (which lives in /demo in this repo): https://goodjob-demo.herokuapp.com/good_job/cron_entries?locale=en For debugging this, I’d definitely recommend running them every 1 second or something just so you don’t have to wait around for the clock. |
Just so there’s no confusion:
The cron behavior is to enqueue the job with perform_later at the scheduled time; it won’t enqueue a later-scheduled job. |
Yes, I definitely understand what I expect from a cron task. However, now I took a completely clean host and tried to repeat my steps. I encountered similar behavior. Is this due to the fact that I do not have any paths defined? I use ruby this way - echo '#!/bin/bash dima@ubuntutemplate:~/jruby/my_api_app$ echo $GEM_PATH dima@ubuntutemplate:~/jruby/my_api_app$ echo $GEM_HOME dima@ubuntutemplate:~/jruby/my_api_app$ echo $PATH |
I am using jruby-complete-9.4.8.0.jar from Maven repo |
I'm not really sure where the problem lies. What happens when you press the Fast-Forward button in the dashboard? Does that fill in the "Last Run" with a job? |
dima@ubuntutemplate:~/jruby/my_api_app$ jruby -S bundle exec good_job start |
Sometimes upon restart it picks up the task itself! Perhaps the problem is somewhere in the difference in time zones or date formats? my_api_app/config/environments/development.rb Rails.application.configure do config.good_job.enable_cron = true config.time_zone = 'Moscow' Pool settingsconfig.good_job.execution_mode = :external Cron tasksconfig.good_job.cron = { Logsconfig.good_job.logger = Logger.new(STDOUT) config.cache_classes = false if Rails.root.join("tmp/caching-dev.txt").exist? config.active_storage.service = :local |
I also took the config from Jruby, put it in the MRI project and everything works as in the description. Could you install the version of Jruby 9.4.8.0, Rails 7.0.8.5, openjdk-21 via RVM yourself and check if it works correctly? |
Good day! I really ask for help! My environment is Jruby 9.4.8\Rails 7.0.8. Gem has been successfully installed and launched. All necessary tables in the database have been created and, judging by the log, are being updated. I also see my job in the cron section of the UI. The problem is that it does not start on schedule. If you launch it from the UI, it runs successfully, but cannot start on its own! What am I doing wrong?
Here all my configs:
application_job.rb
class ApplicationJob < ActiveJob::Base
self.queue_adapter = :good_job
include GoodJob::ActiveJobExtensions::Labels
retry_on ActiveRecord::Deadlocked
end
========================================
/app/jobs/search_and_notify_job.rb
cass SearchAndNotifyJob < ApplicationJob
queue_as :default
def perform
query = {
'bool': {
'must': [],
'filter': [
{
'match_all': {}
},
{
'match_phrase': {
'tag': 'log_java'
}
},
{
'match_phrase': {
'level': 'ERROR'
}
},
{
'range': {
'timestamp': {
'gte': '2024-10-09T21:00:00.000Z',
'lte': '2024-10-10T20:59:59.999Z',
'format': 'strict_date_optional_time'
}
}
}
]
}
}
rescue => e
Rails.logger.error("ERROR: #{e.message}")
end
end
/config/initializers/active_job.rb
ActiveJob::Base.queue_adapter = :good_job
/config/initializers/good_job.rb
Rails.application.configure do
config.good_job.logger = Logger.new(STDOUT)
config.good_job.logger.level = Logger::DEBUG
GoodJob.logger.formatter = proc do |severity, datetime, progname, msg|
datetime = datetime.in_time_zone('Moscow') # Укажите здесь нужный часовой пояс
"#{datetime} #{severity}: #{msg}\n"
end
config.good_job.enable_cron = true
config.good_job.execution_mode = :async_all
config.good_job.active_record_parent_class = "ApplicationRecord"
config.good_job.preserve_job_records = false
config.good_job.retry_on_unhandled_error = true
config.good_job.queues = '*'
config.good_job.max_threads = 15
config.good_job.poll_interval = 10 # seconds
config.good_job.shutdown_timeout = 25 # seconds
config.good_job.cron_graceful_restart_period = 1.minutes
config.good_job.dashboard_default_locale = :en
config.good_job.on_thread_error = -> (exception) { puts "GOOD_JOB ERROR: #{exception}" }
config.good_job.cron = {
}
end
The text was updated successfully, but these errors were encountered: