0

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

  1. I install the cron inside the container. apt-get install cron
  2. create a task in a ruby file called Delete.rb. and a method called delete_old_requests
  3. 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"'
IDI
  • 175
  • 1
  • 14
  • As mentioned in the possible duplicate question, running cron in foreground will help `cron -f`. Go through that question. – mchawre Jun 23 '19 at 16:20
  • Or you could simply use [arask](https://github.com/Ebbe/arask). Works inside docker out of the box. – Esben Damgaard Dec 09 '19 at 13:43

0 Answers0