Magic words:
psql -U postgres
sudo -u postgres psqlSome interesting flags (to see all, use -h or --help depending on your psql version):
-E: will describe the underlaying queries of the\commands (cool for learning!)
| # views | |
| # https://django.readthedocs.io/en/2.1.x/topics/class-based-views/index.html | |
| # https://django.readthedocs.io/en/2.1.x/ref/class-based-views/index.html | |
| #urls.py | |
| from django.urls import include,path, re_path | |
| from django.views.generic import TemplateView | |
| from . import views | |
| urlpatterns = [ |
| https://docs.python.org/3/howto/pyporting.html | |
| https://docs.python.org/3/whatsnew/index.html | |
| https://stackoverflow.com/questions/43957004/upgrade-python-3-4-3-to-python-3-6-1-in-ubuntu-15-0464-bit | |
| https://docs.python.org/3/library/venv.html | |
| https://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3 |
| ; Create default config file -- solves the unix server error | |
| ; credits: https://stackoverflow.com/questions/20067116/supervisorctl-error-unix-var-run-supervisord-sock-refused-connection | |
| echo_supervisord_conf > /etc/supervisord.conf | |
| sudo supervisord -c /etc/supervisord.conf | |
| sudo supervisorctl status | |
| ; Missing '/var/run/supervisor.sock' file? | |
| touch var/run/supervisor.sock | |
| chmod 777 var/run/supervisor.sock | |
| service supervisor restart |
| from django_cron import CronJobBase, Schedule | |
| class FetchData(CronJobBase): | |
| #RUN_EVERY_MINS = 1 | |
| #RUN_EVERY_SECONDS = 30 :: non-existent feature | |
| # maybe we should just write a simple django-mgt comd then daemonize it | |
| RUN_AT_TIMES = trading_hours #list of hours | |
| schedule = Schedule(run_every_mins=RUN_EVERY_MINS, run_at_times=RUN_AT_TIMES) | |
| code = 'my_app.my_cron_job' # a unique code |
| # Toy solution :: not production-ready but food for thought | |
| # https://jeffknupp.com/blog/2014/02/11/a-celerylike-python-task-queue-in-55-lines-of-code/ | |
| # This article shows how to daemonize a job using supervisord | |
| # https://adamj.eu/tech/2014/08/16/time-to-move-on-from-cron/ | |
| # Below is the github repo link | |
| # https://github.com/dbader/schedule | |
| # --------------------------------------- # |
| # execute a python script in virtualenn using cron | |
| # web links to solutions | |
| # http://www.adminschoice.com/crontab-quick-reference | |
| # https://www.unix.com/man-page/linux/5/crontab/ | |
| PATH="" # RUN 'echo PATH' as root | |
| MAILTO=mwaigaryan@gmail.com | |
| # setup e-mail first :: https://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/ |
| # -------------------------------- # | |
| # the main advanatages of celery : # | |
| # -------------------------------- # | |
| # queueing, | |
| # 0. http://python-rq.org/ | |
| # queueing is for invoking a function asynchronously | |
| # retries (the most important feature):: | |
| # 0. https://pypi.org/project/backoff/ :: perfect solution |
| def my_wrapper(func): | |
| try: | |
| return func | |
| except MyException as e: | |
| return "My traceback" | |
| def my_task(*args,**kwargs): | |
| yada = x + 1 |
| # create this in etc/supervisor/conf.d/task_manager.conf | |
| [program:task_manager] | |
| command=bash -c "echo starting main.huey && sleep $(( $RANDOM / 2500 + 4)) && exec huey_consumer.py main.huey" | |
| environment=PYTHONPATH=%(here)s/.. | |
| numprocs=1 | |
| process_name=%(program_name)s-%(process_num)d | |
| stopwaitsecs=5 | |
| stdout_logfile=%(here)s/huey.log |