how do I run cronjob in Alpine container? I am currently running ckan container and this are the code I have tried to run cronjob
The cronjob that I want to run is just to delete a file inside a specific folder
- I have used python-crontab and here is my code
this isn’t working, I tried the code to schedule, but it did not trigger
from crontab import CronTab cron = CronTab() job = cron.new(command='/usr/bin/find /srv/app -name "*.zip" -type f -mmin +1 -mmin -120 -delete')
- I have tried the rq-scheduler
I wanted to try to trigger this scheduler every 30 seconds, but only trigger once after the application loads
from rq_schuleder import Scheduler
def myjob(): print("ssssfdv") redis_conn = Redis(host="redis", port=6379) scheduler = Scheduler(connection=redis_conn) scheduler.schedule( scheduled_time=datetime.utcnow(), func=myjob interval=30 )
- Using the ckan background (I am not sure if I did it correctly)
triggered only once after the application loads, and did not trigger after 1 seconds.
import ckan.lib.jobs as jobs jobs.enqueue(fn=myjob(), title="test",queue="testingqueue", rq_kwargs={"timeout":1})
- I tried to use the Dockerfile to trigger the cron job, but it is not working too
here is the code I put in the DockerFile
RUN echo ‘*/1 * * * * /srv/app/cron.py’ > /etc/crontabs/root
inside the cron.py
> import os
> os.remove("<the path to the file I want to delete>")
I wanted to create a cronjob to cleanup a particular folder on midnight only. The execution is once per day.
Can someone pls help me?? I am not sure if I did any of the implementation wrongly.