I'm trying to create a cron job inside the container to run a ruby class, but it's not running automatically.
When I'm trying to test it locally without docker and container, it works great. And also when running the following command rails runner "Delete.delete_old_requests"
in the terminal and it works.
I think the problem in the app path! which is called myapp. Thanks in advance
- I install the cron inside the container.
apt-get install cron
- create a task in a ruby file called Delete.rb. and a method called delete_old_requests
- create a cron task in crontab file as shown below:
* * * * * /bin/bash -l -c 'cd /myapp && RAILS_ENV=development bundle exec rails runner "Delete.delete_old_requests"'
the code: delete.rb
class Delete < ApplicationRecord
def self.delete_old_requests
users=User.all
users.update_all(requests_num_per_day: 0)
end
end
crontab
* * * * * /bin/bash -l -c '/myapp && RAILS_ENV=development bundle exec rails runner "Delete.delete_old_requests"'