Last active
December 24, 2023 09:49
-
-
Save hopewise/31764fdf7a1453872d660b61f64ba723 to your computer and use it in GitHub Desktop.
RubyOnRails cron jobs setup for AWS Elastic BeanStalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: .ebextensions/create_rake_1_caller.config | |
files: | |
/tmp/run_cronjob_1.sh: | |
mode: "000755" # This sets the file as executable | |
owner: root # Set to the appropriate owner | |
group: root # Set to the appropriate group | |
content: | | |
#!/bin/bash | |
# Custom script content goes here | |
echo "Running custom cron job script" | |
# Other script commands... | |
export $(cat /opt/elasticbeanstalk/deployment/env | xargs) | |
cd /var/app/current | |
/opt/elasticbeanstalk/.rbenv/shims/bundle exec rake cron:test_1 --silent >> /var/log/eb-hooks.log 2>&1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: .ebextensions/create_rake_2_caller.config | |
files: | |
/tmp/run_cronjob_2.sh: | |
mode: "000755" # This sets the file as executable | |
owner: root # Set to the appropriate owner | |
group: root # Set to the appropriate group | |
content: | | |
#!/bin/bash | |
# Custom script content goes here | |
echo "Running custom cron job script" | |
# Other script commands... | |
export $(cat /opt/elasticbeanstalk/deployment/env | xargs) | |
cd /var/app/current | |
/opt/elasticbeanstalk/.rbenv/shims/bundle exec rake cron:test_2 --silent >> /var/log/eb-hooks.log 2>&1 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/cron1.rake | |
namespace :cron do | |
desc "Test task" | |
task test_1: :environment do | |
# Your task implementation here | |
puts "Cron job # 1 executed at #{Time.now}" | |
puts "ENV RAILS_ENV: #{ENV['RAILS_ENV']}" | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/cron1.rake | |
namespace :cron do | |
desc "Test task" | |
task test_2: :environment do | |
# Your task implementation here | |
puts "Cron job # 2 executed at #{Time.now}" | |
puts "ENV AWS_BUCKET: #{ENV['AWS_BUCKET']}" | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: .ebextensions/cronjobs.config | |
files: | |
"/etc/cron.d/my_cron_job": | |
mode: "000644" | |
owner: root | |
group: root | |
content: | | |
* * * * * root /tmp/run_cronjob_1.sh >> /var/log/eb-hooks.log 2>&1 | |
* * * * * root /tmp/run_cronjob_2.sh >> /var/log/eb-hooks.log 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment