so this is like my first time doing a cron job, and also using a whenever gem.
this is what's in my schedule.rb
set :environment, :development
every 1.minute do
command "rails runner /home/ec2-user/projectA/scripts/download.rb"
end
It's running a script where it download's a file and does a few more other thing.
However, for some reason , the job is not running ? nothing is happening, the results are not returning. why is that?
UPDATE#############
i checked my cron log file, and it seems that it was running the script every minute as intended. however my results of the script is not producing as i would to run it manually.. why is that?
Related
Hi I am using the whenever gem and trying to send a daily email. For testing I set it to 2 minutes, and I have it in my schedule.rb file. It calls a task I have in a rake file. When I run bundle exec rake task_to_be_called, it runs and works. But the actual scheduling does not work. When I try to run things to find out crontab it says no such file or directory. Is there some way to get a crontab file, or do I make it? How do I test or get my scheduler to run that task?
EDIT: Thanks for the advice on sharing code and error.
In my lib/tasks/daily_email.rake I have
desc 'Daily email rake task test'
task daily_email_call: :environment do
ReportMailer.with(email: "email#email.com").daily_summary_report.deliver_now
end
Then in my config/schedule.rb I have
every 2.minute do
rake 'daily_email_call'
end
When I run bundle exec rake daily_email_call it functions correctly and does the send email task. My question is how to get it to do it on the schedule. I have no crontab file. Am I even able to do this locally or would it need to be on a running server. I am using windows not Linux when I run mine locally.
There is a typo in the file name,
lib/tasks/darily_email.rake => lib/tasks/daily_email.rake
I guess this is causing the error, no such file or directory
I am using the whenever gem to schedule tasks on OSX Mojave. In the scheduling file, I have
#config/schedule.rb
set :output, "log/cron.log"
every 1.day, at: '23:00' do
rake 'util:something'
runner 'User.something_else'
command "echo 'I just want to see something happen'"
end
The rake, and runner methods work fine and I see output in the cron.log. However, there is no output from the command method, it just seems to be ignored. It may be something to do with user permissions, but I am running it from the base directory of my ruby on rails app, so I would have thought I would have the correct permissions.
How do I fix this?
For the 'command' method, it is necessary to specify the full path to the log files, so the output should something like:
set :output, 'user/sites/my_app/log/cron.log'
So I'm using Rails and I have a few Sidekiq workers, but none are enabled. I'm using the sidekiq-cron gem, which requires you to put files in app/workers/, configure a sidekiq scheduler in config/sidekiq_schedule.yml, and also add a few lines in config/initializers/sidekiq.rb. However, I've commented everything out from sidekiq_schedule.yml and also commented the following lines out from sidekiq.rb:
# Sidekiq scheduler.
# schedule_file = 'config/sidekiq_schedule.yml'
# if File.exists?(schedule_file) && Sidekiq.server?
# Sidekiq::Cron::Job.load_from_hash! YAML.load_file(schedule_file)
# end
However, if I launch Sidekiq, every minute (which is the old schedule), I see this in the prompt:
2018-01-19T02:54:04.156Z 22197 TID-ovsidcme8 ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-8609429b89db2a91793509ea INFO: start
2018-01-19T02:54:04.164Z 22197 TID-ovsidcme8 ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper JID-8609429b89db2a91793509ea INFO: fail: 0.008 sec
and it fails because it's trying to launch code a job that's not supposed to be launching.
I've went to the rails console prompt (rails -c) and tried to find the job, but nothing's in there:
irb(main):001:0> Sidekiq::Cron::Job.all
=> []
so I'm not quite sure why it's constantly trying to launch a job. If I go to the rails interface on my application, I don't see anything in the queue, nothing being processed, busy, retries, enqueued, nothing.
Any suggestions would be greatly appreciated. I've been trying to hunt this down for like the last hour and have no success. I even removed ALL of the workers from the workers directory, and yet it's still trying to launch one of them.
Because you have already load jobs, I think that those jobs configuration are still in REDIS. Checking this assumption by opening a new terminal tab with redis-cli:
KEYS '*cron*'
If there are those keys on REDIS, clear them will fix your issue.
Since you mentioned a cron job in your title but not in the question, I'm assuming there's a cronjob running the background sidekiq task.
Try running crontab - l in Terminal to see all your cron jobs. If you see something like "* * * * *", that means there's a job that is running every minute.
Then, use crontab - r to clear your cron tab and delete all scheduled tasks.
Hello I was trying to run a rake task every 5 minutes with this schedule code using the whenever gem
set :output, "#{path}/log/cron.log"
every 10.minutes do
rake "delete:old_offers"
end
But the code never execute. If I try to run my task with:
rake delete:old_offers
everything works great, so the problem is in the schedule file. Please I need your help to solve this issues.
I'm planning to execute this task every 60 days in my heroku app, so I could the schedule has to work also on heroku.
Thanks in advance.
UPDATE
Sorry guys, I have to set the environment to development like this
set :environment, 'development'
After you write your schedule, you need to actually update your crontab:
whenever --update-crontab
Simply running the whenever command by itself will only show you the schedule in cron format.
I have a rails app with the whenever gem installed to setup cron jobs which invoke various rake tasks. For reasons unbeknownst to me, each rake task gets invoked twice at precisely the same time. So my db backup task backs up the db twice at 4:00am.
Inspecting crontab reveals correct syntax for all of the cron jobs, so I don't think this is an issue with the whenever gem not correctly configuring the cron jobs. Also confusing is that in both staging and production environments and can invoke tasks on the command line and they only run once.
Any thoughts on what would cause this? I'm at a complete loss troubleshooting wise.
The number of cron jobs that run depends on the number of application instances running in the server box. Are you have two instances of rails application running in the same server box?