I am trying to add a simple cron job to run in my Docker container. I want it to be added during setup so it will automatically run when ./launcher rebuild app completes.
The cron job works when I manually add it to the /etc/cron.d/anacron file with vim but if I edit it without entering and saving the file (i.e. with echo -n '* * * * * root python3 /var/www/discourse/script/email_me.py' >> /etc/cron.d/anacron), cron does not seem to pickup the change and does not run the job.
If I then add a space anywhere in the file with vim and save, cron will pickup the change and start running the job.
Since the changes are not picked up when adding them with the echo command, adding this command to my app.yml file does not work.
I also tried docker restart app after echoing in the changes which still did not work.
I feel like there should be an easier way that I’m missing. Having to edit the anacron file after setup seems like the wrong way to do this.
Thanks for getting back to me! Maybe this will make more sense:
I am running a privately hosted discourse repo with some custom files on it.
I have a file in Discourse’s script directory called email_me.py
When run, this file sends me an email saying “Hello World!”
I want to create a cron job in the Discourse Docker container that will run this file every minute.
This can be accomplished by manually adding the line * * * * * root python3 /var/www/discourse/script/email_me.py to the /etc/cron.d/anacron file using an editor like vim.
I want the above cron job to run when the Discourse container is set up, however I cannot use vim to do so from the app.yml file.
I tried using echo -n '* * * * * root python3 /var/www/discourse/script/email_me.py' >> /etc/cron.d/anacron as a command in the app.yml file. This successfully adds the line to the anacron file but the job does NOT run (as if the change was not registered).
I am simply trying to find a way to have the job: * * * * * root python3 /var/www/discourse/script/email_me.py
run after rebuilding with ./launcher rebuild app
Also to be more clear, I am curious what your end goal is, not the steps you are using to achieve it. If the goal is to have an email sent to you once a minute, you can do that in a sidekiq job in a plugin and it’s significantly simpler.
My end goal is to run a database query looking for specific user activity and send an email with a table containing the results. This email will act as a pre-payment confirmation as the users who did this specific activity will be paid later in the day (via PayPal) through another script run by cron.
I already have scripts that can do both these things but I just need to find a way to get the discourse container to run them once per week.
I am not familiar with Sidekiq. If it can do this, where should I look to learn it?
(Also I tried sv restart cron and many other ways of restarting cron to no avail)