Sample code on using celery and celery beat with flask. Get an email containing a link to a coding question/topic on youtube every day. This is randomized with the youtube api but in future can be scaled and customized with machine learning etc.
Check out devcoaster.com for more useful snippets/tutorials on specifics.
- Flask app can be run as usual with
flask runcommand. - Run celery with
celery -A app.celery worker --beat --loglevel=infoThis command can be fed into a heroku worker and runs both celery beat and worker at once. It circumvents need for two workers which may be restricted on free plans on heroku. Don't scale this since consistency/duplicate problems may arise. - Run
heroku ps:scale hybrid_worker=1to scale worker to 1 dyno and start it. Do this after fresh deployments. Restart dyno withheroku restart hybrid_workerand stop it withheroku ps:stop hybrid_worker - You need an api key to access the youtube api - get yours from google developer console after enabling youtube data api
- Celery beat setup to run scheduled tasks executed by the celery worker in the background.
Daily Coding Video https://daily-coding-video.herokuapp.com/
Please open a pull request with your improvements so that this can be made better.
Check user locale, email using cron scheduling targeting certain times of day etc