By froy001
I have been searching for this for a couple of hours now:
I have a crontab file:
PATH=/usr/sbin:/usr/bin:/sbin:/bin
# Begin Whenever generated tasks for: bandmanage_backend_export_handler
* * * * * /bin/bash -l -c 'cd /home/froy001/apps/bandmanage_backend_export_handler/releases/20150824081934 && RAILS_ENV=production bundle exec rake bandmanage:request_user_message_export --silent >> log/cron_log.log 2>&1'
56 * * * * /bin/bash -l -c 'cd /home/froy001/apps/bandmanage_backend_export_handler/releases/20150824081934 && RAILS_ENV=production bundle exec rake bandmanage:get_requested_exports --silent >> log/cron_log.log 2>&1'
# End Whenever generated tasks for: bandmanage_backend_export_handler
and a rake task:
namespace :bandmanage do
desc "request an export from SAMI"
task request_user_message_export: :environment do
puts "requesting message export"
MessageExportService.new.message_export_request_hourly
puts ".....DONE requesting message exports"
end
desc "request the exported result from SAMI a test for us to see"
task request_user_message_export_test: :environment do
puts "requesting message export"
MessageExportService.new.message_export_request_test
puts ".....DONE requesting message exports"
end
desc "request the exported result from SAMI"
task get_requested_exports: :environment do
puts "getting message export"
MessageExportService.new.periodic_export_request_query
puts ".....DONE getting message exports"
end
end
When I run /bin/bash -l -c 'cd /home/froy001/apps/bandmanage_backend_export_handler/releases/20150824081934 && RAILS_ENV=production bundle exec rake bandmanage:request_user_message_export --silent >> log/cron_log.log 2>&1' from the command line It runs great.
When it is run by cron I get an error saying that a call to my DB requesting all registered users returns nil. And the job aborts.
I can’t figure out why. Please help!!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
While we have alot of information here, there is some missing that makes it hard to advise. What sorta of DB are you using? What are the commands being run in the rake doing? What is trying to get exported?
Could it be that the cron is running as a different user than your froy001 user? This seems to be what I think it might be without a bit more information. Perhaps something is set in the froy001 user environment that doesn’t exist in the cron’s user environment.
If you can provide more detail on what exactly these crons are trying to do, and how they interact with the various services; more information might be available to provide.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.