dmstr / docker-php-yii2

:whale: :cd: Docker PHP image containing extensions and libraries for Yii 2.0 Framework
99 stars 33 forks source link

[Q] How to use cron? #33

Closed shaqman closed 5 years ago

shaqman commented 5 years ago

I noticed that cron is available in this image. What is the best way to schedule a cron job, eg: for yii queue/run?

I tried creating a file and putting it in /etc/cron.d, but it doesn't seem to execute. No logging, and the command gives no sign of any effects.

Below is the content of my cron file * * * * * root php /app/yii queue/run > /proc/1/fd/1 2>/proc/1/fd/2

Is this the correct way to use cron here?

schmunk42 commented 5 years ago

I'd recommend using /etc/periodic/..., see also https://github.com/dmstr/phd5-app/blob/master/image-files/etc/periodic/minutely/scheduler and try crontab -l.

Cron can be tricky in the image, because there are system and user crontab. I found it easier in the end to stick with the /etc/periodic setup, since it's more flexible when adding cronjobs in subsequent built images.

[edit] you don't need to run a scheduler, you can run yii queue or any command directly - but be aware of a cleaned ENV when running jobs.