├── .coveragerc ├── .dockerignore ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .pylintrc ├── .travis.yml ├── CONTRIBUTORS.txt ├── Dockerfile ├── LICENSE ├── README.rst ├── celery_uncovered ├── __init__.py ├── advex │ ├── README.rst │ ├── __init__.py │ └── tasks.py ├── celery.py ├── static │ ├── css │ │ └── project.css │ ├── fonts │ │ └── .gitkeep │ ├── images │ │ └── favicon.ico │ ├── js │ │ └── project.js │ └── sass │ │ └── project.scss ├── templates │ ├── 403_csrf.html │ ├── 404.html │ ├── 500.html │ ├── base.html │ └── pages │ │ ├── about.html │ │ └── home.html ├── toyex │ ├── README.rst │ ├── __init__.py │ ├── dummy.py │ ├── log_handlers │ │ ├── __init__.py │ │ └── admin_email.py │ ├── models.py │ ├── tasks.py │ ├── utils.py │ └── views.py └── tricks │ ├── README.rst │ ├── __init__.py │ ├── celery_conf.py │ ├── celery_ext.py │ ├── fixtures │ └── scenarios │ │ ├── sc_1.json │ │ └── sc_2.json │ ├── models.py │ ├── tasks.py │ └── utils.py ├── celery_uncovered_dev ├── config ├── __init__.py ├── settings │ ├── __init__.py │ ├── base.py │ ├── local.py │ └── test.py ├── urls.py └── wsgi.py ├── docker └── mailhog │ ├── Dockerfile │ └── README.md ├── docs ├── Makefile ├── __init__.py ├── conf.py ├── deploy.rst ├── index.rst ├── install.rst └── make.bat ├── env.example ├── manage.py ├── pytest.ini ├── requirements ├── base.txt ├── local.txt ├── production.txt └── test.txt ├── setup.cfg ├── tests ├── __init__.py └── unit │ ├── __init__.py │ ├── advex │ └── __init__.py │ ├── toyex │ ├── README.md │ ├── __init__.py │ └── dummy.py │ └── tricks │ └── __init__.py └── utility ├── install_os_dependencies.sh ├── install_python_dependencies.sh ├── requirements-jessie.apt ├── requirements-trusty.apt ├── requirements-xenial.apt └── unittest.sh /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | include = celery_uncovered/* 3 | omit = *migrations*, *tests* 4 | plugins = 5 | django_coverage_plugin 6 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .* 2 | !.coveragerc 3 | !.env 4 | !.pylintrc 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.{py,rst,ini}] 12 | indent_style = space 13 | indent_size = 4 14 | 15 | [*.py] 16 | line_length=120 17 | known_first_party=celery_uncovered 18 | multi_line_output=3 19 | default_section=THIRDPARTY 20 | 21 | [*.{html,css,scss,json,yml}] 22 | indent_style = space 23 | indent_size = 2 24 | 25 | [*.md] 26 | trim_trailing_whitespace = false 27 | 28 | [Makefile] 29 | indent_style = tab 30 | 31 | [nginx.conf] 32 | indent_style = space 33 | indent_size = 2 34 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### OSX ### 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | ### SublimeText ### 7 | # cache files for sublime text 8 | *.tmlanguage.cache 9 | *.tmPreferences.cache 10 | *.stTheme.cache 11 | 12 | # workspace files are user-specific 13 | *.sublime-workspace 14 | 15 | # project files should be checked into the repository, unless a significant 16 | # proportion of contributors will probably not be using SublimeText 17 | # *.sublime-project 18 | 19 | # sftp configuration file 20 | sftp-config.json 21 | 22 | # Basics 23 | *.py[cod] 24 | __pycache__ 25 | 26 | # Logs 27 | logs 28 | *.log 29 | pip-log.txt 30 | npm-debug.log* 31 | 32 | # Unit test / coverage reports 33 | .coverage 34 | .tox 35 | nosetests.xml 36 | htmlcov 37 | 38 | # Translations 39 | *.mo 40 | *.pot 41 | 42 | # Pycharm 43 | .idea/* 44 | 45 | 46 | # Vim 47 | 48 | *~ 49 | *.swp 50 | *.swo 51 | 52 | # npm 53 | node_modules/ 54 | 55 | # Compass 56 | .sass-cache 57 | 58 | # virtual environments 59 | env 60 | 61 | # User-uploaded media 62 | celery_uncovered/media/ 63 | celerybeat-schedule.db 64 | 65 | 66 | staticfiles/ 67 | 68 | .cache/ 69 | 70 | -------------------------------------------------------------------------------- /.pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | load-plugins=pylint_common, pylint_django, pylint_celery 3 | 4 | [FORMAT] 5 | max-line-length=120 6 | 7 | [MESSAGES CONTROL] 8 | disable=missing-docstring,invalid-name 9 | 10 | [DESIGN] 11 | max-parents=13 12 | 13 | [TYPECHECK] 14 | generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | before_install: 3 | - sudo apt-get update -qq 4 | - sudo apt-get install -qq build-essential gettext python-dev zlib1g-dev libpq-dev xvfb 5 | - sudo apt-get install -qq libtiff4-dev libjpeg8-dev libfreetype6-dev liblcms1-dev libwebp-dev 6 | - sudo apt-get install -qq graphviz-dev python-setuptools python3-dev python-virtualenv python-pip 7 | - sudo apt-get install -qq firefox automake libtool libreadline6 libreadline6-dev libreadline-dev 8 | - sudo apt-get install -qq libsqlite3-dev libxml2 libxml2-dev libssl-dev libbz2-dev wget curl llvm 9 | language: python 10 | python: 11 | - "3.5" 12 | -------------------------------------------------------------------------------- /CONTRIBUTORS.txt: -------------------------------------------------------------------------------- 1 | xepa4ep 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # MailHog Dockerfile 3 | # 4 | 5 | FROM alpine:3.4 6 | 7 | # Install ca-certificates, required for the "release message" feature: 8 | RUN apk --no-cache add ca-certificates 9 | 10 | # Install MailHog: 11 | RUN apk --no-cache add --virtual build-dependencies go git && mkdir -p /root/gocode && export GOPATH=/root/gocode && go get github.com/mailhog/MailHog && mv /root/gocode/bin/MailHog /usr/local/bin && rm -rf /root/gocode && apk del --purge build-dependencies 12 | 13 | # Add mailhog user/group with uid/gid 1000. 14 | # This is a workaround for boot2docker issue #581, see 15 | # https://github.com/boot2docker/boot2docker/issues/581 16 | RUN adduser -D -u 1000 mailhog 17 | 18 | USER mailhog 19 | 20 | WORKDIR /home/mailhog 21 | 22 | ENTRYPOINT ["MailHog"] 23 | 24 | # Expose the SMTP and HTTP ports: 25 | EXPOSE 1025 8025 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | Copyright (c) 2017, xepa4ep 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Celery Uncovered 2 | ================ 3 | 4 | Supporting project for my `TopTal article`_. 5 | 6 | 7 | This repository is intended to help the beginners better understand celery by usecases. It also shows some really nice (undocumented) tricks that could give lots of benefits while developing celery-based projects. 8 | 9 | .. image:: https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg 10 | :target: https://github.com/pydanny/cookiecutter-django/ 11 | :alt: Built with Cookiecutter Django 12 | 13 | 14 | :License: MIT 15 | 16 | 17 | 18 | Django-Applications 19 | ------------ 20 | 21 | `toyex`_ 22 | ^^^^^^ 23 | 24 | contains widely used (simple) examples of using celery to solve background tasks 25 | 26 | advex 27 | ^^^^^^ 28 | 29 | contains generic patterns of using celery to facilitate workflow execution and many others (soon) 30 | 31 | `tricks`_ 32 | ^^^^^^^ 33 | 34 | contains generic examples of extending default ```celery.app.Task``` and some undocument tricks such as: 35 | - verbose logging 36 | - scope injection 37 | - freezing task 38 | 39 | 40 | 41 | 42 | Extra Details 43 | -------------- 44 | 45 | 46 | Celery 47 | ^^^^^^ 48 | 49 | This app comes with Celery. 50 | 51 | To run a celery worker: 52 | 53 | .. code-block:: bash 54 | 55 | cd celery_uncovered 56 | celery -A celery_uncovered worker -l info 57 | 58 | Please note: For Celery's import magic to work, it is important *where* the celery commands are run. If you are in the same folder with *manage.py*, you should be right. 59 | 60 | 61 | Email Server 62 | ^^^^^^^^^^^^ 63 | 64 | In development, it is often nice to be able to see emails that are being sent from your application. For that reason local SMTP server `MailHog`_ with a web interface is available as docker container. 65 | 66 | 67 | With MailHog running, to view messages that are sent by your application, open your browser and go to ``http://127.0.0.1:8025`` 68 | 69 | How to deploy and run it via docker you can refer to its [README.md](docker/mailhog/README.md). 70 | 71 | Further configuration options are available in `MailHog`_. 72 | 73 | 74 | 75 | 76 | Running tests with py.test 77 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 78 | 79 | :: 80 | 81 | $ chmod +x utility/unittest.sh 82 | $ ./utility/unittest.sh 83 | 84 | 85 | Live reloading and Sass CSS compilation 86 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 87 | 88 | Moved to `Live reloading and SASS compilation`_. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | Deployment 97 | ---------- 98 | 99 | The following details how to deploy this application. 100 | 101 | Credits 102 | ------ 103 | 104 | * `Sattar Stamkulov`_ - contributed example 105 | 106 | * `Mailubayev Yernar`_ - contributed example 107 | 108 | .. _`TopTal article`: https://www.toptal.com/python/orchestrating-celery-python-background-jobs 109 | .. _tricks: https://github.com/Rustem/toptal-blog-celery-toy-ex/tree/master/celery_uncovered/tricks#running-examples 110 | .. _toyex: https://github.com/Rustem/toptal-blog-celery-toy-ex/tree/master/celery_uncovered/toyex#running-examples 111 | .. _mailhog: https://github.com/mailhog/MailHog 112 | .. _`Live reloading and SASS compilation`: http://cookiecutter-django.readthedocs.io/en/latest/live-reloading-and-sass-compilation.html 113 | .. _`Sattar Stamkulov`: https://github.com/devishot 114 | .. _`Mailubayev Yernar`: https://github.com/Mafioso 115 | -------------------------------------------------------------------------------- /celery_uncovered/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | # This will make sure the app is always imported when 4 | # Django starts so that shared_task will use this app. 5 | from .celery import app as celery_app # noqa 6 | 7 | __all__ = ['celery_app'] 8 | 9 | 10 | __version__ = '0.0.1' 11 | __version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')]) 12 | 13 | 14 | -------------------------------------------------------------------------------- /celery_uncovered/advex/README.rst: -------------------------------------------------------------------------------- 1 | Running examples 2 | ---------------- 3 | 4 | here will be a getting started guide for each use case 5 | 6 | 7 | -------------------------------------------------------------------------------- /celery_uncovered/advex/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/advex/__init__.py -------------------------------------------------------------------------------- /celery_uncovered/advex/tasks.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/advex/tasks.py -------------------------------------------------------------------------------- /celery_uncovered/celery.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | 3 | import os 4 | from celery import Celery, signals 5 | 6 | 7 | # set the default Django settings module for the 'celery' program. 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local') 9 | 10 | # django.setup() 11 | 12 | app = Celery('celery_uncovered') 13 | 14 | # Using a string here means the worker will not have to 15 | # pickle the object when using Windows. 16 | app.config_from_object('django.conf:settings', namespace='CELERY') 17 | app.autodiscover_tasks() 18 | 19 | import celery_uncovered.tricks.celery_conf 20 | -------------------------------------------------------------------------------- /celery_uncovered/static/css/project.css: -------------------------------------------------------------------------------- 1 | /* These styles are generated from project.scss. */ 2 | 3 | .alert-debug { 4 | color: black; 5 | background-color: white; 6 | border-color: #d6e9c6; 7 | } 8 | 9 | .alert-error { 10 | color: #b94a48; 11 | background-color: #f2dede; 12 | border-color: #eed3d7; 13 | } 14 | 15 | /* This is a fix for the bootstrap4 alpha release */ 16 | @media (max-width: 47.9em) { 17 | .navbar-nav .nav-item { 18 | float: none; 19 | width: 100%; 20 | display: inline-block; 21 | } 22 | 23 | .navbar-nav .nav-item + .nav-item { 24 | margin-left: 0; 25 | } 26 | 27 | .nav.navbar-nav.pull-xs-right { 28 | float: none !important; 29 | } 30 | } 31 | 32 | /* Display django-debug-toolbar. 33 | See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742 34 | and https://github.com/pydanny/cookiecutter-django/issues/317 35 | */ 36 | [hidden][style="display: block;"] { 37 | display: block !important; 38 | } 39 | -------------------------------------------------------------------------------- /celery_uncovered/static/fonts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/static/fonts/.gitkeep -------------------------------------------------------------------------------- /celery_uncovered/static/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/static/images/favicon.ico -------------------------------------------------------------------------------- /celery_uncovered/static/js/project.js: -------------------------------------------------------------------------------- 1 | /* Project specific Javascript goes here. */ 2 | 3 | /* 4 | Formatting hack to get around crispy-forms unfortunate hardcoding 5 | in helpers.FormHelper: 6 | 7 | if template_pack == 'bootstrap4': 8 | grid_colum_matcher = re.compile('\w*col-(xs|sm|md|lg|xl)-\d+\w*') 9 | using_grid_layout = (grid_colum_matcher.match(self.label_class) or 10 | grid_colum_matcher.match(self.field_class)) 11 | if using_grid_layout: 12 | items['using_grid_layout'] = True 13 | 14 | Issues with the above approach: 15 | 16 | 1. Fragile: Assumes Bootstrap 4's API doesn't change (it does) 17 | 2. Unforgiving: Doesn't allow for any variation in template design 18 | 3. Really Unforgiving: No way to override this behavior 19 | 4. Undocumented: No mention in the documentation, or it's too hard for me to find 20 | */ 21 | $('.form-group').removeClass('row'); 22 | -------------------------------------------------------------------------------- /celery_uncovered/static/sass/project.scss: -------------------------------------------------------------------------------- 1 | 2 | // project specific CSS goes here 3 | 4 | //////////////////////////////// 5 | //Variables// 6 | //////////////////////////////// 7 | 8 | // Alert colors 9 | 10 | $white: #fff; 11 | $mint-green: #d6e9c6; 12 | $black: #000; 13 | $pink: #f2dede; 14 | $dark-pink: #eed3d7; 15 | $red: #b94a48; 16 | 17 | //////////////////////////////// 18 | //Alerts// 19 | //////////////////////////////// 20 | 21 | // bootstrap alert CSS, translated to the django-standard levels of 22 | // debug, info, success, warning, error 23 | 24 | .alert-debug { 25 | background-color: $white; 26 | border-color: $mint-green; 27 | color: $black; 28 | } 29 | 30 | .alert-error { 31 | background-color: $pink; 32 | border-color: $dark-pink; 33 | color: $red; 34 | } 35 | 36 | //////////////////////////////// 37 | //Navbar// 38 | //////////////////////////////// 39 | 40 | // This is a fix for the bootstrap4 alpha release 41 | 42 | .navbar { 43 | border-radius: 0px; 44 | } 45 | 46 | @media (max-width: 47.9em) { 47 | .navbar-nav .nav-item { 48 | display: inline-block; 49 | float: none; 50 | width: 100%; 51 | } 52 | 53 | .navbar-nav .nav-item + .nav-item { 54 | margin-left: 0; 55 | } 56 | 57 | .nav.navbar-nav.pull-xs-right { 58 | float: none !important; 59 | } 60 | } 61 | 62 | //////////////////////////////// 63 | //Django Toolbar// 64 | //////////////////////////////// 65 | 66 | // Display django-debug-toolbar. 67 | // See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742 68 | // and https://github.com/pydanny/cookiecutter-django/issues/317 69 | 70 | [hidden][style="display: block;"] { 71 | display: block !important; 72 | } 73 | -------------------------------------------------------------------------------- /celery_uncovered/templates/403_csrf.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block title %}Forbidden (403){% endblock %} 4 | 5 | {% block content %} 6 |

Forbidden (403)

7 | 8 |

CSRF verification failed. Request aborted.

9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /celery_uncovered/templates/404.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block title %}Page not found{% endblock %} 4 | 5 | {% block content %} 6 |

Page not found

7 | 8 |

This is not the page you were looking for.

9 | {% endblock content %} 10 | -------------------------------------------------------------------------------- /celery_uncovered/templates/500.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block title %}Server Error{% endblock %} 4 | 5 | {% block content %} 6 |

Ooops!!! 500

7 | 8 |

Looks like something went wrong!

9 | 10 |

We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.

11 | {% endblock content %} 12 | 13 | 14 | -------------------------------------------------------------------------------- /celery_uncovered/templates/base.html: -------------------------------------------------------------------------------- 1 | {% load staticfiles i18n %} 2 | 3 | 4 | 5 | 6 | {% block title %}Celery Uncovered{% endblock title %} 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | {% block css %} 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | {% endblock %} 26 | 27 | 28 | 29 | 30 | 31 |
32 | 68 | 69 |
70 | 71 |
72 | 73 | {% if messages %} 74 | {% for message in messages %} 75 |
{{ message }}
76 | {% endfor %} 77 | {% endif %} 78 | 79 | {% block content %} 80 |

Use this document as a way to quick start any new project.

81 | {% endblock content %} 82 | 83 |
84 | 85 | {% block modal %}{% endblock modal %} 86 | 87 | 89 | 90 | {% block javascript %} 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | {% endblock javascript %} 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /celery_uncovered/templates/pages/about.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} -------------------------------------------------------------------------------- /celery_uncovered/templates/pages/home.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} -------------------------------------------------------------------------------- /celery_uncovered/toyex/README.rst: -------------------------------------------------------------------------------- 1 | Running examples 2 | ---------------- 3 | 4 | Fetch Github Repositories Task 5 | ^^^^^^^^^^^^^^^^^^^^^ 6 | 7 | Uses Celery Groups for execute multiple requests to github and store report in CSV-file 8 | 9 | In order to launch and check an actual behavior of the task, first start the Celery process: 10 | 11 | .. code-block:: bash 12 | 13 | $ celery -A celery_uncovered worker -l info 14 | 15 | 16 | Then you will be able to test functionality via Shell: 17 | 18 | .. code-block:: python 19 | 20 | from celery_uncovered.toyex.tasks import produce_hot_repo_report 21 | produce_hot_repo_report('day') 22 | 23 | 24 | Finally, to see the result, navigate to the `celery_uncovered/media` directory and open the corresponding log file called similar to `github-hot-repos-2017-08-29.csv`. You might see something similar as below after running this task multiple times: 25 | 26 | .. code-block:: bash 27 | 28 | 1C Enterprise,arkuznetsov/scenex 29 | ASP,carsio/Projeto-Unity 30 | ActionScript,nicothezulu/EveryplayANE 31 | Arduino,braindead1/WemosD1_HomeMatic_StatusDisplay 32 | ... 33 | 34 | 35 | You also can test it by passing a kwarg `ref_date`. Task will fetch only repositories created after referred date: 36 | 37 | .. code-block:: python 38 | 39 | from celery_uncovered.toyex.tasks import produce_hot_repo_report 40 | produce_hot_repo_report(None, '2017-08-30') 41 | 42 | 43 | You will find the report in file called `github-hot-repos-2017-08-30.csv`. 44 | -------------------------------------------------------------------------------- /celery_uncovered/toyex/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/toyex/__init__.py -------------------------------------------------------------------------------- /celery_uncovered/toyex/dummy.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | return a + b 3 | 4 | 5 | def div(a, b): 6 | return a / b 7 | -------------------------------------------------------------------------------- /celery_uncovered/toyex/log_handlers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/toyex/log_handlers/__init__.py -------------------------------------------------------------------------------- /celery_uncovered/toyex/log_handlers/admin_email.py: -------------------------------------------------------------------------------- 1 | from django.utils.log import AdminEmailHandler as BaseAdminEmailHandler 2 | from celery_uncovered.toyex.tasks import report_error_task 3 | 4 | 5 | class AdminEmailHandler(BaseAdminEmailHandler): 6 | 7 | def send_mail(self, subject, message, *args, **kwargs): 8 | report_error_task.delay(subject, message, *args, **kwargs) 9 | -------------------------------------------------------------------------------- /celery_uncovered/toyex/models.py: -------------------------------------------------------------------------------- 1 | class Repository(object): 2 | def __init__(self, obj): 3 | self._wrapped_obj = obj 4 | self.language = obj[u'language'] or u'unknown' 5 | self.name = obj[u'full_name'] 6 | 7 | def __getattr__(self, attr): 8 | if attr in self.__dict__: 9 | return getattr(self, attr) 10 | else: 11 | return getattr(self._wrapped_obj, attr) 12 | -------------------------------------------------------------------------------- /celery_uncovered/toyex/tasks.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, unicode_literals 2 | 3 | import requests 4 | from celery import shared_task, group, chord 5 | from django.core.mail import mail_admins 6 | from django.conf import settings 7 | from .utils import make_csv, strf_date 8 | from .models import Repository 9 | import datetime 10 | 11 | 12 | @shared_task 13 | def send_test_email_task(): 14 | mail_admins( 15 | 'MailHog Test', 16 | 'Hello from Mailhog.', 17 | fail_silently=False,) 18 | 19 | r""" 20 | Responsible: Sattar Stamkukov 21 | 22 | 23 | Create a task that will fetch hottest repositories from github per day, week, month (say 500), group them by language and put the result to the csv file 24 | 25 | Implementation Details: 26 | 27 | 1. Create self containable task called `produce_hot_repo_report_task(ref_date, period='week')` 28 | 29 | 2. Investigate how and then use github api service https://developer.github.com/v3/search/#search-repositories 30 | 31 | 3. Return filepath where the result is stored /media/... 32 | 33 | 4. Define method `produce_hot_repo_report_task_for_week(period='week')` 34 | that will call produce_hot_repo_report_task with date today() 35 | 36 | Bonus tasks for readers: 37 | 38 | 1. Modify code so that if the result for that date is already exists, no need to send external request 39 | 40 | 2. What if we need to produce csv per language? 41 | hint: For that you need to use celery.canvas.group and modify `produce_hot_repo_report_task(language/topic, ref_date, period='week')` 42 | 43 | 3. Probably your client wants it to be automatically callable each day at 00:00, generate report for previous date and send it to dummy email. 44 | hint: periodic tasks 45 | 46 | Required Libraries: 47 | requests 48 | django.core.mail 49 | """ 50 | 51 | @shared_task 52 | def fetch_hot_repos(since, per_page, page): 53 | payload = { 54 | 'sort': 'stars', 'order': 'desc', 'q': 'created:>={date}'.format(date=since), 55 | 'per_page': per_page, 'page': page, 56 | 'access_token': settings.GITHUB_OAUTH} 57 | headers = {'Accept': 'application/vnd.github.v3+json'} 58 | connect_timeout, read_timeout = 5.0, 30.0 59 | r = requests.get( 60 | 'https://api.github.com/search/repositories', 61 | params=payload, 62 | headers=headers, 63 | timeout=(connect_timeout, read_timeout)) 64 | items = r.json()[u'items'] 65 | return items 66 | 67 | 68 | def produce_hot_repo_report(period, ref_date=None): 69 | # 1. parse date 70 | ref_date_str = strf_date(period, ref_date=ref_date) 71 | 72 | # 2. fetch and join 73 | fetch_jobs = group([ 74 | fetch_hot_repos.s(ref_date_str, 100, 1), 75 | fetch_hot_repos.s(ref_date_str, 100, 2), 76 | fetch_hot_repos.s(ref_date_str, 100, 3), 77 | fetch_hot_repos.s(ref_date_str, 100, 4), 78 | fetch_hot_repos.s(ref_date_str, 100, 5) 79 | ]) 80 | # 3. group by language and 81 | # 4. create csv 82 | return chord(fetch_jobs)(build_report_task.s(ref_date_str)).get() 83 | 84 | 85 | 86 | @shared_task 87 | def build_report_task(results, ref_date): 88 | all_repos = [] 89 | for repos in results: 90 | all_repos += [Repository(repo) for repo in repos] 91 | 92 | # 3. group by language 93 | grouped_repos = {} 94 | for repo in all_repos: 95 | if repo.language in grouped_repos: 96 | grouped_repos[repo.language].append(repo.name) 97 | else: 98 | grouped_repos[repo.language] = [repo.name] 99 | 100 | # 4. create csv 101 | lines = [] 102 | for lang in sorted(grouped_repos.keys()): 103 | lines.append([lang] + grouped_repos[lang]) 104 | 105 | filename = '{media}/github-hot-repos-{date}.csv'.format(media=settings.MEDIA_ROOT, date=ref_date) 106 | return make_csv(filename, lines) 107 | 108 | 109 | """ 110 | Responsible: Mailubayev Yernar 111 | 112 | Create a logging handler that will be able to track Server errors (50X) and report them to admins through via celery. I advice to thoroughly understand https://docs.djangoproject.com/en/1.11/howto/error-reporting/ 113 | 114 | Seems like you need to extend default 'django.utils.log.AdminEmailHandler', 115 | 116 | 117 | Implementation Details: 118 | 119 | 1. Create self containable task called `report_error_task/4 similar to `self.send_mail(subject, message, fail_silently=True, html_message=html_message)`` 120 | 121 | 2. Extend 'django.utils.log.AdminEmailHandler' in the way it will call report_error_task.delay with the required parameters 122 | 123 | 3. Return nothing (Ensure that ignore_result flag set to True) 124 | 125 | 4. Provide http tests that ensures that it is called 126 | 127 | Bonus tasks for readers: 128 | 129 | 1. Modify code so that task could be scheduled once per time range (1 hour, 6 hours) and all bugs will be collected and send as one email, rather than notifying often. 130 | Hint: you also need to create models.py that will store the HttpErrorEntries 131 | 132 | 133 | Required Libraries: 134 | django.core.mail 135 | django.util.log 136 | mailhog 137 | pytest 138 | """ 139 | 140 | @shared_task 141 | def report_error_task(subject, message, *args, **kwargs): 142 | mail_admins(subject, message, *args, **kwargs) 143 | -------------------------------------------------------------------------------- /celery_uncovered/toyex/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import csv 3 | import datetime 4 | 5 | 6 | def make_csv(filename, lines): 7 | dirname = os.path.dirname(filename) 8 | if not os.path.exists(dirname): 9 | os.makedirs(dirname) 10 | with open(filename, 'wb') as csvfile: 11 | trending_csv = csv.writer(csvfile) 12 | for line in lines: 13 | trending_csv.writerow(line) 14 | return filename 15 | 16 | 17 | 18 | def strf_date(mixed_date, ref_date=None): 19 | dt_str = None 20 | if ref_date is None: 21 | ref_date = datetime.date.today() 22 | if mixed_date in ('day', 'week', 'month'): 23 | delta = None 24 | if mixed_date is 'day': 25 | delta = datetime.timedelta(days=1) 26 | elif mixed_date is 'week': 27 | delta = datetime.timedelta(weeks=1) 28 | else: 29 | delta = datetime.timedelta(days=30) 30 | dt_str = (ref_date - delta).isoformat() 31 | 32 | elif type(ref_date) in (str, unicode): 33 | dt_str = ref_date 34 | 35 | elif type(ref_date) in (datetime.date, datetime.datetime): 36 | dt_str = ref_date.isoformat() 37 | return dt_str 38 | -------------------------------------------------------------------------------- /celery_uncovered/toyex/views.py: -------------------------------------------------------------------------------- 1 | from django.views.generic import View 2 | 3 | 4 | class ReportErrorView(View): 5 | 6 | def get(self, request, *args, **kwargs): 7 | return 1 / 0 8 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/README.rst: -------------------------------------------------------------------------------- 1 | Running examples 2 | ---------------- 3 | 4 | File Logging Per Task 5 | ^^^^^^^^^^^^^^^^^^^^^ 6 | 7 | Extend Celery so that each task logs its standard output and errors to files 8 | 9 | In order to launch and test how this task is working, first start the Celery process: 10 | 11 | .. code-block:: bash 12 | 13 | $ celery -A celery_uncovered worker -l info 14 | 15 | 16 | Then you will be able to test functionality via Shell: 17 | 18 | .. code-block:: python 19 | 20 | from datetime import date 21 | from celery_uncovered.tricks.tasks import add 22 | add.delay(1, 3) 23 | 24 | 25 | Finally, to see the result, navigate to the `celery_uncovered/logs` directory and open the corresponding log file called `celery_uncovered.tricks.tasks.add.log`. You might see something similar as below after running this task multiple times: 26 | 27 | .. code-block:: bash 28 | 29 | Result of 1 + 2 = 3 30 | Result of 1 + 2 = 3 31 | ... 32 | 33 | 34 | Scope-Aware Tasks 35 | ^^^^^^^^^^^^^^^^^^^^^ 36 | 37 | Automatically inherit scope from one execution context and inject it into the current execution context as a parameter. 38 | 39 | First start the Celery process: 40 | 41 | .. code-block:: bash 42 | 43 | $ celery -A celery_uncovered worker -l info 44 | 45 | 46 | Import and execute a dummy task from celery_uncovered/tricks/tasks.py: 47 | 48 | .. code-block:: python 49 | 50 | from celery_uncovered.tricks.tasks import read_scenario_file_task 51 | read_scenario_file_task.delay(scenario_id=2).get() 52 | 53 | 54 | You will see the following result 55 | 56 | .. code-block:: python 57 | 58 | Out[3]: {u'name': u'B'} 59 | 60 | 61 | You also can test it without passing a kwarg `scenario_id`. Celery implicitly will use activated scenario: 62 | 63 | .. code-block:: python 64 | 65 | from celery_uncovered.tricks.tasks import read_scenario_file_task 66 | read_scenario_file_task.delay(scenario_id=2).get() 67 | 68 | 69 | You will see the following result 70 | 71 | .. code-block:: python 72 | 73 | Out[4]: {u'name': u'A'} 74 | 75 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered/tricks/__init__.py -------------------------------------------------------------------------------- /celery_uncovered/tricks/celery_conf.py: -------------------------------------------------------------------------------- 1 | import os 2 | import logging 3 | from django.conf import settings # noqa 4 | from celery import signals 5 | from celery.task.control import inspect 6 | 7 | 8 | def copy_dict(ds): 9 | return {k: v for k, v in ds.iteritems()} 10 | 11 | 12 | @signals.celeryd_after_setup.connect 13 | def configure_task_logging(instance=None, **kwargs): 14 | tasks = instance.app.tasks.keys() 15 | LOGS_DIR = settings.ROOT_DIR.path('logs') 16 | 17 | if not os.path.exists(str(LOGS_DIR)): 18 | os.makedirs(str(LOGS_DIR)) 19 | print 'dir created' 20 | default_handler = { 21 | 'level': 'DEBUG', 22 | 'filters': None, 23 | 'class': 'logging.FileHandler', 24 | 'filename': '' 25 | } 26 | default_logger = { 27 | 'handlers': [], 28 | 'level': 'DEBUG', 29 | 'propogate': True 30 | } 31 | LOG_CONFIG = { 32 | 'version': 1, 33 | # 'incremental': True, 34 | 'disable_existing_loggers': False, 35 | 'handlers': {}, 36 | 'loggers': {} 37 | } 38 | for task in tasks: 39 | task = str(task) 40 | if not task.startswith('celery_uncovered.'): 41 | continue 42 | task_handler = copy_dict(default_handler) 43 | task_handler['filename'] = str(LOGS_DIR.path(task + ".log")) 44 | 45 | task_logger = copy_dict(default_logger) 46 | task_logger['handlers'] = [task] 47 | 48 | LOG_CONFIG['handlers'][task] = task_handler 49 | LOG_CONFIG['loggers'][task] = task_logger 50 | logging.config.dictConfig(LOG_CONFIG) 51 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/celery_ext.py: -------------------------------------------------------------------------------- 1 | from celery import current_app 2 | from celery.utils.log import get_task_logger 3 | from django.conf import settings 4 | from .models import get_current_scenario 5 | 6 | 7 | DEFAULT_SCENARIO_ID = getattr(settings, 'DEFAULT_SCENARIO_ID', 1) 8 | 9 | 10 | class LoggingTask(current_app.Task): 11 | abstract = True 12 | ignore_result = False 13 | 14 | @property 15 | def log(self): 16 | logger = get_task_logger(self.name) 17 | return logger 18 | 19 | def log_msg(self, msg, *msg_args): 20 | self.log.debug(msg, *msg_args) 21 | 22 | 23 | class ScopeBasedTask(current_app.Task): 24 | abstract = True 25 | ignore_result = False 26 | default_scenario_id = DEFAULT_SCENARIO_ID 27 | scope_args = ('scenario_id',) 28 | 29 | def __init__(self, *args, **kwargs): 30 | super(ScopeBasedTask, self).__init__(*args, **kwargs) 31 | self.set_scenario(scenario_id=kwargs.get('scenario_id', None)) 32 | 33 | def set_scenario(self, scenario_id=None): 34 | self.scenario_id = self.default_scenario_id 35 | if scenario_id: 36 | self.scenario_id = scenario_id 37 | else: 38 | self.scenario_id = get_current_scenario().id 39 | 40 | def apply_async(self, args=None, kwargs=None, **other_kwargs): 41 | self.inject_scope_args(kwargs) 42 | return super(ScopeBasedTask, self).apply_async(args=args, kwargs=kwargs, **other_kwargs) 43 | 44 | def __call__(self, *args, **kwargs): 45 | task_rv = super(ScopeBasedTask, self).__call__(*args, **kwargs) 46 | return task_rv 47 | 48 | def inject_scope_args(self, kwargs): 49 | for arg in self.scope_args: 50 | if arg not in kwargs: 51 | kwargs[arg] = getattr(self, arg) 52 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/fixtures/scenarios/sc_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "A" 3 | } 4 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/fixtures/scenarios/sc_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "B" 3 | } 4 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/models.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | 3 | 4 | DEFAULT_SCENARIO_ID = getattr(settings, 'DEFAULT_SCENARIO_ID') 5 | 6 | 7 | class Scenario(object): 8 | 9 | def __init__(self, id, name='unknown'): 10 | self.id = id 11 | self.name = name 12 | 13 | @classmethod 14 | def default(cls): 15 | return Scenario(DEFAULT_SCENARIO_ID) 16 | 17 | 18 | class ContextStack(object): 19 | 20 | def __init__(self): 21 | self.st = [] 22 | 23 | def current(self): 24 | return self.st[0] 25 | 26 | def push(self, obj): 27 | self.st.insert(0, obj) 28 | 29 | def pop(self): 30 | if len(self.st) == 1: 31 | return self.current 32 | return self.st.pop(0) 33 | 34 | 35 | class ScenarioContextStack(ContextStack): 36 | 37 | def __init__(self): 38 | super(ScenarioContextStack, self).__init__() 39 | self.push(Scenario.default()) 40 | 41 | def pop_(self): 42 | if len(self.st) == 1: 43 | return self.current 44 | return self.st.pop(0) 45 | 46 | 47 | context_stack = ScenarioContextStack() 48 | 49 | 50 | def get_current_scenario(): 51 | return context_stack.current() 52 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/tasks.py: -------------------------------------------------------------------------------- 1 | from celery import shared_task 2 | from .celery_ext import LoggingTask, ScopeBasedTask 3 | from .utils import read_fixture 4 | 5 | r""" 6 | Responsible: Rustem Kamun 7 | 8 | Configure celery in order to support verbose file logging per each task. 9 | 10 | Implementation details: 11 | 12 | 1. Extend base task so that it allows to write logs to corresponding file handler 13 | 14 | 2. Configure celery logging so that it will write output to file. Most approapriate way is to use `signals.celeryd_after_setup` hook. 15 | 16 | 3. Build dummy tasks that logs some messages, errors to the log file. 17 | 18 | 4. Test that std, err stream is written to corresponding task file 19 | 20 | Bonus tasks: 21 | 22 | 1. Celery completely tracks lifecycle of a task, including stages run and failure stages. Could u refine the code so that it will log task failure and task success stages? 23 | 24 | 2. Default logging configuration keeps corresponding task files opened during main process lifecycle. However it is common for enterprise software to have logs that are not kept open and therefore able to be deleted. For example, when I want to delete /logs/*log files, it must recreate them by appending new information. Current configuration does not allow that. You need to modify current logging configuration to support the following scenario: 25 | * append to the logfile name with the new loginformation 26 | * close file and release its descriptor 27 | 28 | Hint: Clue within appropriate log handlers. 29 | """ 30 | 31 | 32 | @shared_task(bind=True, base=LoggingTask) 33 | def add(self, a, b): 34 | c = a + b 35 | self.log_msg("Result of %i + %i = %i", a, b, c) 36 | return c 37 | 38 | 39 | r""" 40 | Responsible: Rustem Kamun 41 | 42 | Injecting scope to each scope-based task. Sometimes you need to maintain some global scope beyond one app process. For example, our application depends on scenario. Scenario locates family of tables (a table space) you want to access//modify. Scenarios has same structure, but different data. Say, we do some action in app process within scenario X. In turn this action triggers another action but execution will be offloaded to celery. Celery should encapsulate scope (in our case scenario X). There are two options to solve this problem: 43 | 44 | 1) Pass scenario_id as parameter directly 45 | 2) Injecting scope to each task that require it 46 | 47 | Of course if you have only a few tasks you prefer option (1) due to its simplicity. However, when you deal with execution topology which is hierarchical, you wish to solve it with option (2), because it is higher-level, less buggy and cleaner approach. 48 | 49 | Implementation details: 50 | 51 | 1. Extend base task so that it allows to inject current scope as `**kwargs`. For example, `scenario_id`=None 52 | 53 | 2. Test that scenario injected consistently on the following scenarios 54 | 2.1 call via delay and apply_async 55 | 2.3 call from app->celery 56 | 2.4 call from celery->celery (nested call) 57 | 58 | Bonus tasks 59 | 60 | 1. Currently u can't maintain consistent scenario passing when you call by signature. For example, u can't use celery.canvas utilities such as group, chain, chord. Modify it so that it will be possible to call it by signature and its aliases: subtask, signature, s, si. Modify also test suite to address this piece of functionality. 61 | 62 | 2. Allow this type of tasks to be loggable as well. You can reuse functionality of verbose logging trick. 63 | """ 64 | 65 | 66 | @shared_task(bind=True, base=ScopeBasedTask) 67 | def read_scenario_file_task(self, **kwargs): 68 | fixture_parts = ["scenarios", "sc_%i.json" % kwargs['scenario_id']] 69 | return read_fixture(*fixture_parts) 70 | 71 | r""" 72 | Responsible: Rustem Kamun 73 | If you merely want to refer to the result of a previously executed task or you want to track task in external storage, then that is definitely possible by freezing task. The meaning of freezing is finalizing signature instance. 74 | 75 | ```task_result = task.freeze()``` 76 | 77 | Next example is probably not best example, however I can't share a real case where I used this because of the privacy. 78 | 79 | Let's say you want to execute payment transaction via some payment broker. You don't want your user wait before actual transaction is accopmlished. You would rather want to show your user "Thank you" page and enqueue your payment tx. Tiny periodic `status_manager` observing [status=QUEUED] payments, marks them as PENDING. Tiny periodic `payment_dispatcher` tracks all PENDING tasks, registers them to `execute_payment_task`. So we don't want to execute PENDING tasks twice, so we are also assign to payment object exec_identifier as task uuid. Here we use freezing. 80 | 81 | 82 | 83 | Implementation details: 84 | 85 | 1. Define Payment object as simple as possible with status=[QUEUED, PENDING, SETTLED, DECLINED] 86 | 87 | 2. Tiny status manager which is responsible to prepare queued to pending 88 | 89 | 3. Tiny payment dispatcher which is responsible for assigning PENDING to execute_payment task and set exec identifier so that it will be executed only once. 90 | 91 | 92 | Bonus tasks: 93 | 94 | 1. freeze to access task result in indirect parent. 95 | 96 | a = A.s() 97 | a_result = a.freeze() 98 | 99 | workflow = (a | B.s() | C.s(a_result.as_tuple())) 100 | workflow.delay() 101 | 102 | https://github.com/celery/celery/issues/3666 103 | """ 104 | -------------------------------------------------------------------------------- /celery_uncovered/tricks/utils.py: -------------------------------------------------------------------------------- 1 | from json import loads 2 | import codecs 3 | import environ 4 | 5 | 6 | FIXTURE_PATH = (environ.Path(__file__) - 1).path('fixtures') 7 | 8 | 9 | def read_json(fpath): 10 | with codecs.open(fpath, 'rb', encoding='utf-8') as fp: 11 | return loads(fp.read()) 12 | 13 | 14 | def read_fixture(*subpath): 15 | fixture_file = str(FIXTURE_PATH.path(*subpath)) 16 | return read_json(fixture_file) 17 | -------------------------------------------------------------------------------- /celery_uncovered_dev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/celery_uncovered_dev -------------------------------------------------------------------------------- /config/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/config/__init__.py -------------------------------------------------------------------------------- /config/settings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/config/settings/__init__.py -------------------------------------------------------------------------------- /config/settings/base.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for Celery Uncovered project. 3 | 4 | For more information on this file, see 5 | https://docs.djangoproject.com/en/dev/topics/settings/ 6 | 7 | For the full list of settings and their values, see 8 | https://docs.djangoproject.com/en/dev/ref/settings/ 9 | """ 10 | import environ 11 | 12 | ROOT_DIR = environ.Path(__file__) - 3 # (celery_uncovered/config/settings/base.py - 3 = celery_uncovered/) 13 | APPS_DIR = ROOT_DIR.path('celery_uncovered') 14 | 15 | # Load operating system environment variables and then prepare to use them 16 | env = environ.Env() 17 | 18 | # .env file, should load only in development environment 19 | READ_DOT_ENV_FILE = env.bool('DJANGO_READ_DOT_ENV_FILE', default=False) 20 | 21 | if READ_DOT_ENV_FILE: 22 | # Operating System Environment variables have precedence over variables defined in the .env file, 23 | # that is to say variables from the .env files will only be used if not defined 24 | # as environment variables. 25 | env_file = str(ROOT_DIR.path('.env')) 26 | print('Loading : {}'.format(env_file)) 27 | env.read_env(env_file) 28 | print('The .env file has been loaded. See base.py for more information') 29 | 30 | # APP CONFIGURATION 31 | # ------------------------------------------------------------------------------ 32 | DJANGO_APPS = [ 33 | # Default Django apps: 34 | 'django.contrib.auth', 35 | 'django.contrib.contenttypes', 36 | # 'django.contrib.sessions', 37 | #'django.contrib.sites', 38 | # 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 41 | # Useful template tags: 42 | # 'django.contrib.humanize', 43 | 44 | # Admin 45 | 'django.contrib.admin', 46 | 47 | # celery 48 | 'django_celery_results', 49 | ] 50 | THIRD_PARTY_APPS = [ 51 | 52 | ] 53 | 54 | # Apps specific for this project go here. 55 | LOCAL_APPS = [ 56 | # custom users app 57 | 58 | # Your stuff: custom apps go here 59 | 'celery_uncovered.toyex', 60 | 'celery_uncovered.tricks' 61 | ] 62 | 63 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps 64 | INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS 65 | 66 | # MIDDLEWARE CONFIGURATION 67 | # ------------------------------------------------------------------------------ 68 | MIDDLEWARE = [ 69 | 'django.middleware.security.SecurityMiddleware', 70 | 'django.contrib.sessions.middleware.SessionMiddleware', 71 | 'django.middleware.common.CommonMiddleware', 72 | 'django.middleware.csrf.CsrfViewMiddleware', 73 | #'django.contrib.auth.middleware.AuthenticationMiddleware', 74 | 'django.contrib.messages.middleware.MessageMiddleware', 75 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 76 | ] 77 | 78 | # MIGRATIONS CONFIGURATION 79 | # ------------------------------------------------------------------------------ 80 | MIGRATION_MODULES = { 81 | } 82 | 83 | # DEBUG 84 | # ------------------------------------------------------------------------------ 85 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug 86 | DEBUG = env.bool('DJANGO_DEBUG', False) 87 | 88 | # FIXTURE CONFIGURATION 89 | # ------------------------------------------------------------------------------ 90 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS 91 | FIXTURE_DIRS = ( 92 | str(APPS_DIR.path('fixtures')), 93 | ) 94 | 95 | # EMAIL CONFIGURATION 96 | # ------------------------------------------------------------------------------ 97 | EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend') 98 | 99 | # MANAGER CONFIGURATION 100 | # ------------------------------------------------------------------------------ 101 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#admins 102 | ADMINS = [ 103 | ("""xepa4ep""", 'r.kamun@gmail.com'), 104 | ] 105 | 106 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#managers 107 | MANAGERS = ADMINS 108 | 109 | # DATABASE CONFIGURATION 110 | # ------------------------------------------------------------------------------ 111 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#databases 112 | DATABASES = { 113 | 'default': { 114 | 'ENGINE': 'django.db.backends.sqlite3', 115 | 'NAME': 'celery_uncovered_dev', 116 | } 117 | } 118 | 119 | 120 | 121 | # GENERAL CONFIGURATION 122 | # ------------------------------------------------------------------------------ 123 | # Local time zone for this installation. Choices can be found here: 124 | # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name 125 | # although not all choices may be available on all operating systems. 126 | # In a Windows environment this must be set to your system time zone. 127 | TIME_ZONE = 'UTC' 128 | 129 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code 130 | LANGUAGE_CODE = 'en-us' 131 | 132 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id 133 | SITE_ID = 1 134 | 135 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n 136 | USE_I18N = True 137 | 138 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n 139 | USE_L10N = True 140 | 141 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz 142 | USE_TZ = True 143 | 144 | # TEMPLATE CONFIGURATION 145 | # ------------------------------------------------------------------------------ 146 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#templates 147 | TEMPLATES = [ 148 | { 149 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND 150 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 151 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs 152 | 'DIRS': [ 153 | str(APPS_DIR.path('templates')), 154 | ], 155 | 'OPTIONS': { 156 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug 157 | 'debug': DEBUG, 158 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders 159 | # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types 160 | 'loaders': [ 161 | 'django.template.loaders.filesystem.Loader', 162 | 'django.template.loaders.app_directories.Loader', 163 | ], 164 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors 165 | 'context_processors': [ 166 | 'django.template.context_processors.debug', 167 | 'django.template.context_processors.request', 168 | 'django.contrib.auth.context_processors.auth', 169 | 'django.template.context_processors.i18n', 170 | 'django.template.context_processors.media', 171 | 'django.template.context_processors.static', 172 | 'django.template.context_processors.tz', 173 | 'django.contrib.messages.context_processors.messages', 174 | # Your stuff: custom template context processors go here 175 | ], 176 | }, 177 | }, 178 | ] 179 | 180 | # STATIC FILE CONFIGURATION 181 | # ------------------------------------------------------------------------------ 182 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root 183 | STATIC_ROOT = str(ROOT_DIR('staticfiles')) 184 | 185 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url 186 | STATIC_URL = '/static/' 187 | 188 | # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS 189 | STATICFILES_DIRS = [ 190 | str(APPS_DIR.path('static')), 191 | ] 192 | 193 | # See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders 194 | STATICFILES_FINDERS = [ 195 | 'django.contrib.staticfiles.finders.FileSystemFinder', 196 | 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 197 | ] 198 | 199 | # MEDIA CONFIGURATION 200 | # ------------------------------------------------------------------------------ 201 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root 202 | MEDIA_ROOT = str(APPS_DIR('media')) 203 | 204 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url 205 | MEDIA_URL = '/media/' 206 | 207 | # URL Configuration 208 | # ------------------------------------------------------------------------------ 209 | ROOT_URLCONF = 'config.urls' 210 | 211 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application 212 | WSGI_APPLICATION = 'config.wsgi.application' 213 | 214 | # PASSWORD STORAGE SETTINGS 215 | # ------------------------------------------------------------------------------ 216 | # See https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django 217 | PASSWORD_HASHERS = [ 218 | 'django.contrib.auth.hashers.Argon2PasswordHasher', 219 | 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 220 | 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 221 | 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', 222 | 'django.contrib.auth.hashers.BCryptPasswordHasher', 223 | ] 224 | 225 | # PASSWORD VALIDATION 226 | # https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators 227 | # ------------------------------------------------------------------------------ 228 | 229 | 230 | ########## CELERY 231 | 232 | # INSTALLED_APPS += ['celery_uncovered.taskapp.celery.CeleryConfig'] 233 | CELERY_ACCEPT_CONTENT = ['json'] 234 | CELERY_TASK_SERIALIZER = 'json' 235 | 236 | 237 | ########## END CELERY 238 | 239 | # Location of root django.contrib.admin URL, use {% url 'admin:index' %} 240 | ADMIN_URL = r'^admin/' 241 | 242 | # Your common stuff: Below this line define 3rd party library settings 243 | # ------------------------------------------------------------------------------ 244 | -------------------------------------------------------------------------------- /config/settings/local.py: -------------------------------------------------------------------------------- 1 | """ 2 | Local settings 3 | 4 | - Run in Debug mode 5 | 6 | - Use mailhog for emails 7 | 8 | - Add Django Debug Toolbar 9 | - Add django-extensions as app 10 | """ 11 | 12 | from .base import * 13 | import environ 14 | 15 | 16 | env = environ.Env() 17 | # DEBUG 18 | # ------------------------------------------------------------------------------ 19 | DEBUG = env.bool('DJANGO_DEBUG', default=True) 20 | TEMPLATES[0]['OPTIONS']['debug'] = DEBUG 21 | 22 | # SECRET CONFIGURATION 23 | # ------------------------------------------------------------------------------ 24 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key 25 | # Note: This key only used for development and testing. 26 | SECRET_KEY = env('DJANGO_SECRET_KEY', default='|ad(NW7~=O=5UF#q{ihH<2:-CBtafb[t8g%[T!M&4}pf:`1T0%') 27 | 28 | # Mail settings 29 | # ------------------------------------------------------------------------------ 30 | 31 | EMAIL_PORT = 1025 32 | 33 | EMAIL_HOST = env('EMAIL_HOST', default='mailhog') 34 | 35 | 36 | # Logging settings 37 | # ------------------------------------------------------------------------------ 38 | LOGGING = { 39 | 'version': 1, 40 | 'disable_existing_loggers': False, 41 | 'filters': { 42 | 'require_debug_false': { 43 | '()': 'django.utils.log.RequireDebugFalse', 44 | }, 45 | 'require_debug_true': { 46 | '()': 'django.utils.log.RequireDebugTrue', 47 | }, 48 | }, 49 | 'formatters': { 50 | 'django.server': { 51 | '()': 'django.utils.log.ServerFormatter', 52 | 'format': '[%(server_time)s] %(message)s', 53 | } 54 | }, 55 | 'handlers': { 56 | 'console': { 57 | 'level': 'INFO', 58 | 'filters': ['require_debug_true'], 59 | 'class': 'logging.StreamHandler', 60 | }, 61 | 'django.server': { 62 | 'level': 'INFO', 63 | 'class': 'logging.StreamHandler', 64 | 'formatter': 'django.server', 65 | }, 66 | 'mail_admins': { 67 | 'level': 'ERROR', 68 | 'filters': ['require_debug_true'], # ['require_debug_true'], 69 | 'class': 'celery_uncovered.toyex.log_handlers.admin_email.AdminEmailHandler' 70 | } 71 | }, 72 | 'loggers': { 73 | 'django': { 74 | 'handlers': ['console', 'mail_admins'], 75 | 'level': 'INFO', 76 | }, 77 | 'django.server': { 78 | 'handlers': ['django.server'], 79 | 'level': 'INFO', 80 | 'propagate': False, 81 | }, 82 | } 83 | } 84 | 85 | 86 | # CACHING 87 | # ------------------------------------------------------------------------------ 88 | CACHES = { 89 | 'default': { 90 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 91 | 'LOCATION': '' 92 | } 93 | } 94 | 95 | # django-debug-toolbar 96 | # ------------------------------------------------------------------------------ 97 | MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ] 98 | INSTALLED_APPS += ['debug_toolbar', ] 99 | 100 | INTERNAL_IPS = ['127.0.0.1', '10.0.2.2', ] 101 | 102 | 103 | import socket 104 | import os 105 | 106 | # tricks to have debug toolbar when developing with docker 107 | if os.environ.get('USE_DOCKER') == 'yes': 108 | ip = socket.gethostbyname(socket.gethostname()) 109 | INTERNAL_IPS += [ip[:-1] + '1'] 110 | 111 | DEBUG_TOOLBAR_CONFIG = { 112 | 'DISABLE_PANELS': [ 113 | 'debug_toolbar.panels.redirects.RedirectsPanel', 114 | ], 115 | 'SHOW_TEMPLATE_CONTEXT': True, 116 | } 117 | 118 | # django-extensions 119 | # ------------------------------------------------------------------------------ 120 | INSTALLED_APPS += ['django_extensions', ] 121 | 122 | # TESTING 123 | # ------------------------------------------------------------------------------ 124 | TEST_RUNNER = 'django.test.runner.DiscoverRunner' 125 | 126 | ########## CELERY 127 | # In development, all tasks will be executed locally by blocking until the task returns 128 | CELERY_TASK_ALWAYS_EAGER = env.bool('CELERY_TASK_ALWAYS_EAGER', default=True) 129 | 130 | CELERY_BROKER_URL = env('CELERY_BROKER_URL', default='amqp://guest:guest@localhost:5672//') 131 | CELERY_RESULT_BACKEND = 'django-db+sqlite:///results.sqlite' 132 | 133 | ########## END CELERY 134 | 135 | # Your local stuff: Below this line define 3rd party library settings 136 | # ------------------------------------------------------------------------------ 137 | DEFAULT_SCENARIO_ID = 1 138 | GITHUB_OAUTH = '4bd43b3d0e4b4ec03f6f95b9cc11b4b09cbb0dd3' 139 | -------------------------------------------------------------------------------- /config/settings/test.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Test settings 3 | 4 | - Used to run tests fast on the continuous integration server and locally 5 | ''' 6 | 7 | from .base import * # noqa 8 | 9 | 10 | # DEBUG 11 | # ------------------------------------------------------------------------------ 12 | # Turn debug off so tests run faster 13 | DEBUG = False 14 | TEMPLATES[0]['OPTIONS']['debug'] = False 15 | 16 | # SECRET CONFIGURATION 17 | # ------------------------------------------------------------------------------ 18 | # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key 19 | # Note: This key only used for development and testing. 20 | SECRET_KEY = env('DJANGO_SECRET_KEY', default='CHANGEME!!!') 21 | 22 | # Mail settings 23 | # ------------------------------------------------------------------------------ 24 | EMAIL_HOST = 'localhost' 25 | EMAIL_PORT = 1025 26 | 27 | # In-memory email backend stores messages in django.core.mail.outbox 28 | # for unit testing purposes 29 | EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' 30 | 31 | # CACHING 32 | # ------------------------------------------------------------------------------ 33 | # Speed advantages of in-memory caching without having to run Memcached 34 | CACHES = { 35 | 'default': { 36 | 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 37 | 'LOCATION': '' 38 | } 39 | } 40 | 41 | # TESTING 42 | # ------------------------------------------------------------------------------ 43 | TEST_RUNNER = 'django.test.runner.DiscoverRunner' 44 | 45 | 46 | # PASSWORD HASHING 47 | # ------------------------------------------------------------------------------ 48 | # Use fast password hasher so tests run faster 49 | PASSWORD_HASHERS = [ 50 | 'django.contrib.auth.hashers.MD5PasswordHasher', 51 | ] 52 | 53 | # TEMPLATE LOADERS 54 | # ------------------------------------------------------------------------------ 55 | # Keep templates in memory so tests run faster 56 | TEMPLATES[0]['OPTIONS']['loaders'] = [ 57 | ['django.template.loaders.cached.Loader', [ 58 | 'django.template.loaders.filesystem.Loader', 59 | 'django.template.loaders.app_directories.Loader', 60 | ], ], 61 | ] 62 | -------------------------------------------------------------------------------- /config/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.conf.urls import include, url 3 | from django.conf.urls.static import static 4 | from django.contrib import admin 5 | from django.views.generic import TemplateView 6 | from django.views import defaults as default_views 7 | from celery_uncovered.toyex.views import ReportErrorView 8 | 9 | 10 | urlpatterns = [ 11 | url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'), 12 | url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'), 13 | url(r'^report-error/', ReportErrorView.as_view(), name='report-error'), 14 | 15 | # Django Admin, use {% url 'admin:index' %} 16 | url(settings.ADMIN_URL, admin.site.urls), 17 | 18 | # Your stuff: custom urls includes go here 19 | 20 | 21 | ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 22 | 23 | if settings.DEBUG: 24 | # This allows the error pages to be debugged during development, just visit 25 | # these url in browser to see how these error pages look like. 26 | urlpatterns += [ 27 | url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception('Bad Request!')}), 28 | url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception('Permission Denied')}), 29 | url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception('Page not Found')}), 30 | url(r'^500/$', default_views.server_error), 31 | ] 32 | if 'debug_toolbar' in settings.INSTALLED_APPS: 33 | import debug_toolbar 34 | urlpatterns = [ 35 | url(r'^__debug__/', include(debug_toolbar.urls)), 36 | ] + urlpatterns 37 | -------------------------------------------------------------------------------- /config/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for Celery Uncovered project. 3 | 4 | This module contains the WSGI application used by Django's development server 5 | and any production WSGI deployments. It should expose a module-level variable 6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover 7 | this application via the ``WSGI_APPLICATION`` setting. 8 | 9 | Usually you will have the standard Django WSGI application here, but it also 10 | might make sense to replace the whole Django WSGI application with a custom one 11 | that later delegates to the Django one. For example, you could introduce WSGI 12 | middleware here, or combine a Django application with an application of another 13 | framework. 14 | 15 | """ 16 | import os 17 | import sys 18 | 19 | from django.core.wsgi import get_wsgi_application 20 | 21 | # This allows easy placement of apps within the interior 22 | # celery_uncovered directory. 23 | app_path = os.path.dirname(os.path.abspath(__file__)).replace('/config', '') 24 | sys.path.append(os.path.join(app_path, 'celery_uncovered')) 25 | 26 | 27 | 28 | # We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks 29 | # if running multiple sites in the same mod_wsgi process. To fix this, use 30 | # mod_wsgi daemon mode with each site in its own daemon process, or use 31 | # os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production" 32 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") 33 | 34 | # This application object is used by any WSGI server configured to use this 35 | # file. This includes Django's development server, if the WSGI_APPLICATION 36 | # setting points here. 37 | application = get_wsgi_application() 38 | 39 | # Apply WSGI middleware here. 40 | # from helloworld.wsgi import HelloWorldApplication 41 | # application = HelloWorldApplication(application) 42 | -------------------------------------------------------------------------------- /docker/mailhog/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # MailHog Dockerfile 3 | # 4 | 5 | FROM alpine:3.4 6 | 7 | # Install ca-certificates, required for the "release message" feature: 8 | RUN apk --no-cache add \ 9 | ca-certificates 10 | 11 | # Install MailHog: 12 | RUN apk --no-cache add --virtual build-dependencies \ 13 | go \ 14 | git \ 15 | && mkdir -p /root/gocode \ 16 | && export GOPATH=/root/gocode \ 17 | && go get github.com/mailhog/MailHog \ 18 | && mv /root/gocode/bin/MailHog /usr/local/bin \ 19 | && rm -rf /root/gocode \ 20 | && apk del --purge build-dependencies 21 | 22 | # Add mailhog user/group with uid/gid 1000. 23 | # This is a workaround for boot2docker issue #581, see 24 | # https://github.com/boot2docker/boot2docker/issues/581 25 | RUN adduser -D -u 1000 mailhog 26 | 27 | USER mailhog 28 | 29 | WORKDIR /home/mailhog 30 | 31 | ENTRYPOINT ["MailHog"] 32 | 33 | # Expose the SMTP and HTTP ports: 34 | EXPOSE 1025 8025 35 | -------------------------------------------------------------------------------- /docker/mailhog/README.md: -------------------------------------------------------------------------------- 1 | Image source: https://github.com/mailhog/MailHog/blob/master/Dockerfile. 2 | 3 | 4 | ## Usage with docker-compose: 5 | 6 | $ docker build . -f docker/mailhog/Dockerfile -t mailhog/mailhog:latest 7 | $ docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog 8 | $ navigate with your browser to localhost:8025 9 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/celery_uncovered.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/celery_uncovered.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/celery_uncovered" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/celery_uncovered" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /docs/__init__.py: -------------------------------------------------------------------------------- 1 | # Included so that Django's startproject comment runs against the docs directory 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Celery Uncovered documentation build configuration file, created by 2 | # sphinx-quickstart. 3 | # 4 | # This file is execfile()d with the current directory set to its containing dir. 5 | # 6 | # Note that not all possible configuration values are present in this 7 | # autogenerated file. 8 | # 9 | # All configuration values have a default; values that are commented out 10 | # serve to show the default. 11 | 12 | import os 13 | import sys 14 | 15 | # If extensions (or modules to document with autodoc) are in another directory, 16 | # add these directories to sys.path here. If the directory is relative to the 17 | # documentation root, use os.path.abspath to make it absolute, like shown here. 18 | # sys.path.insert(0, os.path.abspath('.')) 19 | 20 | # -- General configuration ----------------------------------------------------- 21 | 22 | # If your documentation needs a minimal Sphinx version, state it here. 23 | # needs_sphinx = '1.0' 24 | 25 | # Add any Sphinx extension module names here, as strings. They can be extensions 26 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 27 | extensions = [] 28 | 29 | # Add any paths that contain templates here, relative to this directory. 30 | templates_path = ['_templates'] 31 | 32 | # The suffix of source filenames. 33 | source_suffix = '.rst' 34 | 35 | # The encoding of source files. 36 | # source_encoding = 'utf-8-sig' 37 | 38 | # The master toctree document. 39 | master_doc = 'index' 40 | 41 | # General information about the project. 42 | project = 'Celery Uncovered' 43 | copyright = """2017, xepa4ep""" 44 | 45 | # The version info for the project you're documenting, acts as replacement for 46 | # |version| and |release|, also used in various other places throughout the 47 | # built documents. 48 | # 49 | # The short X.Y version. 50 | version = '0.1' 51 | # The full version, including alpha/beta/rc tags. 52 | release = '0.1' 53 | 54 | # The language for content autogenerated by Sphinx. Refer to documentation 55 | # for a list of supported languages. 56 | # language = None 57 | 58 | # There are two options for replacing |today|: either, you set today to some 59 | # non-false value, then it is used: 60 | # today = '' 61 | # Else, today_fmt is used as the format for a strftime call. 62 | # today_fmt = '%B %d, %Y' 63 | 64 | # List of patterns, relative to source directory, that match files and 65 | # directories to ignore when looking for source files. 66 | exclude_patterns = ['_build'] 67 | 68 | # The reST default role (used for this markup: `text`) to use for all documents. 69 | # default_role = None 70 | 71 | # If true, '()' will be appended to :func: etc. cross-reference text. 72 | # add_function_parentheses = True 73 | 74 | # If true, the current module name will be prepended to all description 75 | # unit titles (such as .. function::). 76 | # add_module_names = True 77 | 78 | # If true, sectionauthor and moduleauthor directives will be shown in the 79 | # output. They are ignored by default. 80 | # show_authors = False 81 | 82 | # The name of the Pygments (syntax highlighting) style to use. 83 | pygments_style = 'sphinx' 84 | 85 | # A list of ignored prefixes for module index sorting. 86 | # modindex_common_prefix = [] 87 | 88 | 89 | # -- Options for HTML output --------------------------------------------------- 90 | 91 | # The theme to use for HTML and HTML Help pages. See the documentation for 92 | # a list of builtin themes. 93 | html_theme = 'default' 94 | 95 | # Theme options are theme-specific and customize the look and feel of a theme 96 | # further. For a list of options available for each theme, see the 97 | # documentation. 98 | # html_theme_options = {} 99 | 100 | # Add any paths that contain custom themes here, relative to this directory. 101 | # html_theme_path = [] 102 | 103 | # The name for this set of Sphinx documents. If None, it defaults to 104 | # " v documentation". 105 | # html_title = None 106 | 107 | # A shorter title for the navigation bar. Default is the same as html_title. 108 | # html_short_title = None 109 | 110 | # The name of an image file (relative to this directory) to place at the top 111 | # of the sidebar. 112 | # html_logo = None 113 | 114 | # The name of an image file (within the static path) to use as favicon of the 115 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 116 | # pixels large. 117 | # html_favicon = None 118 | 119 | # Add any paths that contain custom static files (such as style sheets) here, 120 | # relative to this directory. They are copied after the builtin static files, 121 | # so a file named "default.css" will overwrite the builtin "default.css". 122 | html_static_path = ['_static'] 123 | 124 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 125 | # using the given strftime format. 126 | # html_last_updated_fmt = '%b %d, %Y' 127 | 128 | # If true, SmartyPants will be used to convert quotes and dashes to 129 | # typographically correct entities. 130 | # html_use_smartypants = True 131 | 132 | # Custom sidebar templates, maps document names to template names. 133 | # html_sidebars = {} 134 | 135 | # Additional templates that should be rendered to pages, maps page names to 136 | # template names. 137 | # html_additional_pages = {} 138 | 139 | # If false, no module index is generated. 140 | # html_domain_indices = True 141 | 142 | # If false, no index is generated. 143 | # html_use_index = True 144 | 145 | # If true, the index is split into individual pages for each letter. 146 | # html_split_index = False 147 | 148 | # If true, links to the reST sources are added to the pages. 149 | # html_show_sourcelink = True 150 | 151 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 152 | # html_show_sphinx = True 153 | 154 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 155 | # html_show_copyright = True 156 | 157 | # If true, an OpenSearch description file will be output, and all pages will 158 | # contain a tag referring to it. The value of this option must be the 159 | # base URL from which the finished HTML is served. 160 | # html_use_opensearch = '' 161 | 162 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 163 | # html_file_suffix = None 164 | 165 | # Output file base name for HTML help builder. 166 | htmlhelp_basename = 'celery_uncovereddoc' 167 | 168 | 169 | # -- Options for LaTeX output -------------------------------------------------- 170 | 171 | latex_elements = { 172 | # The paper size ('letterpaper' or 'a4paper'). 173 | # 'papersize': 'letterpaper', 174 | 175 | # The font size ('10pt', '11pt' or '12pt'). 176 | # 'pointsize': '10pt', 177 | 178 | # Additional stuff for the LaTeX preamble. 179 | # 'preamble': '', 180 | } 181 | 182 | # Grouping the document tree into LaTeX files. List of tuples 183 | # (source start file, target name, title, author, documentclass [howto/manual]). 184 | latex_documents = [ 185 | ('index', 186 | 'celery_uncovered.tex', 187 | 'Celery Uncovered Documentation', 188 | """xepa4ep""", 'manual'), 189 | ] 190 | 191 | # The name of an image file (relative to this directory) to place at the top of 192 | # the title page. 193 | # latex_logo = None 194 | 195 | # For "manual" documents, if this is true, then toplevel headings are parts, 196 | # not chapters. 197 | # latex_use_parts = False 198 | 199 | # If true, show page references after internal links. 200 | # latex_show_pagerefs = False 201 | 202 | # If true, show URL addresses after external links. 203 | # latex_show_urls = False 204 | 205 | # Documents to append as an appendix to all manuals. 206 | # latex_appendices = [] 207 | 208 | # If false, no module index is generated. 209 | # latex_domain_indices = True 210 | 211 | 212 | # -- Options for manual page output -------------------------------------------- 213 | 214 | # One entry per manual page. List of tuples 215 | # (source start file, name, description, authors, manual section). 216 | man_pages = [ 217 | ('index', 'celery_uncovered', 'Celery Uncovered Documentation', 218 | ["""xepa4ep"""], 1) 219 | ] 220 | 221 | # If true, show URL addresses after external links. 222 | # man_show_urls = False 223 | 224 | 225 | # -- Options for Texinfo output ------------------------------------------------ 226 | 227 | # Grouping the document tree into Texinfo files. List of tuples 228 | # (source start file, target name, title, author, 229 | # dir menu entry, description, category) 230 | texinfo_documents = [ 231 | ('index', 'celery_uncovered', 'Celery Uncovered Documentation', 232 | """xepa4ep""", 'Celery Uncovered', 233 | """A short description of the project.""", 'Miscellaneous'), 234 | ] 235 | 236 | # Documents to append as an appendix to all manuals. 237 | # texinfo_appendices = [] 238 | 239 | # If false, no module index is generated. 240 | # texinfo_domain_indices = True 241 | 242 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 243 | # texinfo_show_urls = 'footnote' 244 | -------------------------------------------------------------------------------- /docs/deploy.rst: -------------------------------------------------------------------------------- 1 | Deploy 2 | ======== 3 | 4 | This is where you describe how the project is deployed in production. 5 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. Celery Uncovered documentation master file, created by 2 | sphinx-quickstart. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Celery Uncovered's documentation! 7 | ==================================================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | install 15 | deploy 16 | docker_ec2 17 | tests 18 | 19 | 20 | 21 | Indices and tables 22 | ================== 23 | 24 | * :ref:`genindex` 25 | * :ref:`modindex` 26 | * :ref:`search` 27 | -------------------------------------------------------------------------------- /docs/install.rst: -------------------------------------------------------------------------------- 1 | Install 2 | ========= 3 | 4 | This is where you write how to get a new laptop to run this project. 5 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. linkcheck to check all external links for integrity 37 | echo. doctest to run all doctests embedded in the documentation if enabled 38 | goto end 39 | ) 40 | 41 | if "%1" == "clean" ( 42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 43 | del /q /s %BUILDDIR%\* 44 | goto end 45 | ) 46 | 47 | if "%1" == "html" ( 48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 49 | if errorlevel 1 exit /b 1 50 | echo. 51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 52 | goto end 53 | ) 54 | 55 | if "%1" == "dirhtml" ( 56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 57 | if errorlevel 1 exit /b 1 58 | echo. 59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 60 | goto end 61 | ) 62 | 63 | if "%1" == "singlehtml" ( 64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 68 | goto end 69 | ) 70 | 71 | if "%1" == "pickle" ( 72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished; now you can process the pickle files. 76 | goto end 77 | ) 78 | 79 | if "%1" == "json" ( 80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished; now you can process the JSON files. 84 | goto end 85 | ) 86 | 87 | if "%1" == "htmlhelp" ( 88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can run HTML Help Workshop with the ^ 92 | .hhp project file in %BUILDDIR%/htmlhelp. 93 | goto end 94 | ) 95 | 96 | if "%1" == "qthelp" ( 97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 98 | if errorlevel 1 exit /b 1 99 | echo. 100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 101 | .qhcp project file in %BUILDDIR%/qthelp, like this: 102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\celery_uncovered.qhcp 103 | echo.To view the help file: 104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\celery_uncovered.ghc 105 | goto end 106 | ) 107 | 108 | if "%1" == "devhelp" ( 109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 110 | if errorlevel 1 exit /b 1 111 | echo. 112 | echo.Build finished. 113 | goto end 114 | ) 115 | 116 | if "%1" == "epub" ( 117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 118 | if errorlevel 1 exit /b 1 119 | echo. 120 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 121 | goto end 122 | ) 123 | 124 | if "%1" == "latex" ( 125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 129 | goto end 130 | ) 131 | 132 | if "%1" == "text" ( 133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The text files are in %BUILDDIR%/text. 137 | goto end 138 | ) 139 | 140 | if "%1" == "man" ( 141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 145 | goto end 146 | ) 147 | 148 | if "%1" == "texinfo" ( 149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 150 | if errorlevel 1 exit /b 1 151 | echo. 152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 153 | goto end 154 | ) 155 | 156 | if "%1" == "gettext" ( 157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 158 | if errorlevel 1 exit /b 1 159 | echo. 160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 161 | goto end 162 | ) 163 | 164 | if "%1" == "changes" ( 165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 166 | if errorlevel 1 exit /b 1 167 | echo. 168 | echo.The overview file is in %BUILDDIR%/changes. 169 | goto end 170 | ) 171 | 172 | if "%1" == "linkcheck" ( 173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 174 | if errorlevel 1 exit /b 1 175 | echo. 176 | echo.Link check complete; look for any errors in the above output ^ 177 | or in %BUILDDIR%/linkcheck/output.txt. 178 | goto end 179 | ) 180 | 181 | if "%1" == "doctest" ( 182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 183 | if errorlevel 1 exit /b 1 184 | echo. 185 | echo.Testing of doctests in the sources finished, look at the ^ 186 | results in %BUILDDIR%/doctest/output.txt. 187 | goto end 188 | ) 189 | 190 | :end 191 | -------------------------------------------------------------------------------- /env.example: -------------------------------------------------------------------------------- 1 | 2 | # General settings 3 | # DJANGO_READ_DOT_ENV_FILE=True 4 | DJANGO_ADMIN_URL= 5 | DJANGO_SETTINGS_MODULE=config.settings.production 6 | DJANGO_SECRET_KEY=E5Z.NZGkG_A^>cOC+K0/*TPSn08A9k~{_7rHW:+Z^9r*:c`69? 7 | DJANGO_ALLOWED_HOSTS=.example.com 8 | 9 | # AWS Settings 10 | DJANGO_AWS_ACCESS_KEY_ID= 11 | DJANGO_AWS_SECRET_ACCESS_KEY= 12 | DJANGO_AWS_STORAGE_BUCKET_NAME= 13 | 14 | # Used with email 15 | DJANGO_MAILGUN_API_KEY= 16 | DJANGO_SERVER_EMAIL= 17 | MAILGUN_SENDER_DOMAIN= 18 | 19 | # Security! Better to use DNS for this task, but you can use redirect 20 | DJANGO_SECURE_SSL_REDIRECT=False 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local') 7 | 8 | try: 9 | from django.core.management import execute_from_command_line 10 | except ImportError: 11 | # The above import may fail for some other reason. Ensure that the 12 | # issue is really that Django is missing to avoid masking other 13 | # exceptions on Python 2. 14 | try: 15 | import django # noqa 16 | except ImportError: 17 | raise ImportError( 18 | "Couldn't import Django. Are you sure it's installed and " 19 | "available on your PYTHONPATH environment variable? Did you " 20 | "forget to activate a virtual environment?" 21 | ) 22 | raise 23 | 24 | # This allows easy placement of apps within the interior 25 | # celery_uncovered directory. 26 | current_path = os.path.dirname(os.path.abspath(__file__)) 27 | sys.path.append(os.path.join(current_path, 'celery_uncovered')) 28 | 29 | execute_from_command_line(sys.argv) 30 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE=config.settings.test 3 | python_functions = test_* 4 | python_files = *.py 5 | norecursedirs = env .tox 6 | 7 | -------------------------------------------------------------------------------- /requirements/base.txt: -------------------------------------------------------------------------------- 1 | # Wheel 0.25+ needed to install certain packages on CPython 3.5+ 2 | # like Pillow and psycopg2 3 | # See http://bitly.com/wheel-building-fails-CPython-35 4 | # Verified bug on Python 3.5.1 5 | wheel==0.29.0 6 | 7 | 8 | # Bleeding edge Django 9 | django==1.10.7 # pyup: >=1.10,<1.11 10 | 11 | 12 | # Models 13 | django-model-utils==3.0.0 14 | 15 | 16 | # Password storage 17 | argon2-cffi==16.3.0 18 | 19 | 20 | # Time zones support 21 | pytz==2017.2 22 | 23 | # Make requests 24 | requests==2.14.2 25 | 26 | celery==4.0.2 27 | django-celery-results==1.0.1 28 | 29 | 30 | # Your custom requirements go here 31 | 32 | 33 | django-environ==0.4.3 34 | -------------------------------------------------------------------------------- /requirements/local.txt: -------------------------------------------------------------------------------- 1 | # Local development dependencies go here 2 | -r base.txt 3 | 4 | coverage==4.4.1 5 | django-coverage-plugin==1.5.0 6 | 7 | Sphinx==1.6.1 8 | django-extensions==1.7.9 9 | Werkzeug==0.12.2 10 | django-test-plus==1.0.17 11 | factory-boy==2.8.1 12 | 13 | django-debug-toolbar==1.8 14 | 15 | # improved REPL 16 | ipdb==0.10.3 17 | 18 | pytest-django==3.1.2 19 | pytest-sugar==0.8.0 20 | -------------------------------------------------------------------------------- /requirements/production.txt: -------------------------------------------------------------------------------- 1 | # Pro-tip: Try not to put anything here. Avoid dependencies in 2 | # production that aren't in development. 3 | -r base.txt 4 | 5 | 6 | 7 | # WSGI Handler 8 | # ------------------------------------------------ 9 | gevent==1.2.1 10 | gunicorn==19.7.1 11 | 12 | # Static and Media Storage 13 | # ------------------------------------------------ 14 | boto==2.46.1 15 | django-storages-redux==1.3.2 16 | 17 | 18 | # Email backends for Mailgun, Postmark, SendGrid and more 19 | # ------------------------------------------------------- 20 | django-anymail==0.9 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /requirements/test.txt: -------------------------------------------------------------------------------- 1 | # Test dependencies go here. 2 | -r base.txt 3 | 4 | 5 | 6 | coverage==4.4.1 7 | flake8==3.3.0 # pyup: != 2.6.0 8 | django-test-plus==1.0.17 9 | factory-boy==2.8.1 10 | 11 | # pytest 12 | pytest-django==3.1.2 13 | pytest-sugar==0.8.0 14 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules 4 | 5 | [pycodestyle] 6 | max-line-length = 120 7 | exclude=.tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules 8 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/tests/__init__.py -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/tests/unit/__init__.py -------------------------------------------------------------------------------- /tests/unit/advex/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/tests/unit/advex/__init__.py -------------------------------------------------------------------------------- /tests/unit/toyex/README.md: -------------------------------------------------------------------------------- 1 | Running examples 2 | ---------------- 3 | 4 | here will be a getting started guide for each use case 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/unit/toyex/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/tests/unit/toyex/__init__.py -------------------------------------------------------------------------------- /tests/unit/toyex/dummy.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from celery_uncovered.toyex.dummy import add, div 3 | 4 | 5 | def test_add(): 6 | assert add(12, 13) == 25 7 | assert add(1, 1) == 2 8 | 9 | 10 | def test_div(): 11 | assert div(12, 3) == 4 12 | x = 12 13 | with pytest.raises(ZeroDivisionError): 14 | div(x, 0) 15 | 16 | -------------------------------------------------------------------------------- /tests/unit/tricks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rustem/toptal-blog-celery-toy-ex/6a640e79add1bdab0661d0b8e682f3d90118eab9/tests/unit/tricks/__init__.py -------------------------------------------------------------------------------- /utility/install_os_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WORK_DIR="$(dirname "$0")" 4 | DISTRO_NAME=$(lsb_release -sc) 5 | OS_REQUIREMENTS_FILENAME="requirements-$DISTRO_NAME.apt" 6 | 7 | cd $WORK_DIR 8 | 9 | # Check if a requirements file exist for the current distribution. 10 | if [ ! -r "$OS_REQUIREMENTS_FILENAME" ]; then 11 | cat <<-EOF >&2 12 | There is no requirements file for your distribution. 13 | You can see one of the files listed below to help search the equivalent package in your system: 14 | $(find ./ -name "requirements-*.apt" -printf " - %f\n") 15 | EOF 16 | exit 1; 17 | fi 18 | 19 | # Handle call with wrong command 20 | function wrong_command() 21 | { 22 | echo "${0##*/} - unknown command: '${1}'" >&2 23 | usage_message 24 | } 25 | 26 | # Print help / script usage 27 | function usage_message() 28 | { 29 | cat <<-EOF 30 | Usage: $WORK_DIR/${0##*/} 31 | Available commands are: 32 | list Print a list of all packages defined on ${OS_REQUIREMENTS_FILENAME} file 33 | help Print this help 34 | 35 | Commands that require superuser permission: 36 | install Install packages defined on ${OS_REQUIREMENTS_FILENAME} file. Note: This 37 | does not upgrade the packages already installed for new versions, even if 38 | new version is available in the repository. 39 | upgrade Same that install, but upgrade the already installed packages, if new 40 | version is available. 41 | EOF 42 | } 43 | 44 | # Read the requirements.apt file, and remove comments and blank lines 45 | function list_packages(){ 46 | grep -v "#" "${OS_REQUIREMENTS_FILENAME}" | grep -v "^$"; 47 | } 48 | 49 | function install_packages() 50 | { 51 | list_packages | xargs apt-get --no-upgrade install -y; 52 | } 53 | 54 | function upgrade_packages() 55 | { 56 | list_packages | xargs apt-get install -y; 57 | } 58 | 59 | function install_or_upgrade() 60 | { 61 | P=${1} 62 | PARAN=${P:-"install"} 63 | 64 | if [[ $EUID -ne 0 ]]; then 65 | cat <<-EOF >&2 66 | You must run this script with root privilege 67 | Please do: 68 | sudo $WORK_DIR/${0##*/} $PARAN 69 | EOF 70 | exit 1 71 | else 72 | 73 | apt-get update 74 | 75 | # Install the basic compilation dependencies and other required libraries of this project 76 | if [ "$PARAN" == "install" ]; then 77 | install_packages; 78 | else 79 | upgrade_packages; 80 | fi 81 | 82 | # cleaning downloaded packages from apt-get cache 83 | apt-get clean 84 | 85 | exit 0 86 | fi 87 | } 88 | 89 | # Handle command argument 90 | case "$1" in 91 | install) install_or_upgrade;; 92 | upgrade) install_or_upgrade "upgrade";; 93 | list) list_packages;; 94 | help|"") usage_message;; 95 | *) wrong_command "$1";; 96 | esac 97 | -------------------------------------------------------------------------------- /utility/install_python_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | WORK_DIR="$(dirname "$0")" 4 | PROJECT_DIR="$(dirname "$WORK_DIR")" 5 | 6 | pip --version >/dev/null 2>&1 || { 7 | echo >&2 -e "\npip is required but it's not installed." 8 | echo >&2 -e "You can install it by running the following command:\n" 9 | echo >&2 "wget https://bootstrap.pypa.io/get-pip.py --output-document=get-pip.py; chmod +x get-pip.py; sudo -H python3 get-pip.py" 10 | echo >&2 -e "\n" 11 | echo >&2 -e "\nFor more information, see pip documentation: https://pip.pypa.io/en/latest/" 12 | exit 1; 13 | } 14 | 15 | virtualenv --version >/dev/null 2>&1 || { 16 | echo >&2 -e "\nvirtualenv is required but it's not installed." 17 | echo >&2 -e "You can install it by running the following command:\n" 18 | echo >&2 "sudo -H pip3 install virtualenv" 19 | echo >&2 -e "\n" 20 | echo >&2 -e "\nFor more information, see virtualenv documentation: https://virtualenv.pypa.io/en/latest/" 21 | exit 1; 22 | } 23 | 24 | if [ -z "$VIRTUAL_ENV" ]; then 25 | echo >&2 -e "\nYou need activate a virtualenv first" 26 | echo >&2 -e 'If you do not have a virtualenv created, run the following command to create and automatically activate a new virtualenv named "venv" on current folder:\n' 27 | echo >&2 -e "virtualenv venv --python=\`which python3\`" 28 | echo >&2 -e "\nTo leave/disable the currently active virtualenv, run the following command:\n" 29 | echo >&2 "deactivate" 30 | echo >&2 -e "\nTo activate the virtualenv again, run the following command:\n" 31 | echo >&2 "source venv/bin/activate" 32 | echo >&2 -e "\nFor more information, see virtualenv documentation: https://virtualenv.pypa.io/en/latest/" 33 | echo >&2 -e "\n" 34 | exit 1; 35 | else 36 | 37 | pip install -r $PROJECT_DIR/requirements/local.txt 38 | pip install -r $PROJECT_DIR/requirements/test.txt 39 | 40 | fi 41 | -------------------------------------------------------------------------------- /utility/requirements-jessie.apt: -------------------------------------------------------------------------------- 1 | ##basic build dependencies of various Django apps for Debian Jessie 8.x 2 | #build-essential metapackage install: make, gcc, g++, 3 | build-essential 4 | #required to translate 5 | gettext 6 | python3-dev 7 | 8 | ##shared dependencies of: 9 | ##Pillow, pylibmc 10 | zlib1g-dev 11 | 12 | ##Postgresql and psycopg2 dependencies 13 | libpq-dev 14 | 15 | ##Pillow dependencies 16 | libtiff5-dev 17 | libjpeg62-turbo-dev 18 | libfreetype6-dev 19 | liblcms2-dev 20 | libwebp-dev 21 | 22 | ##django-extensions 23 | graphviz-dev 24 | -------------------------------------------------------------------------------- /utility/requirements-trusty.apt: -------------------------------------------------------------------------------- 1 | ##basic build dependencies of various Django apps for Ubuntu Trusty 14.04 2 | #build-essential metapackage install: make, gcc, g++, 3 | build-essential 4 | #required to translate 5 | gettext 6 | python3-dev 7 | 8 | ##shared dependencies of: 9 | ##Pillow, pylibmc 10 | zlib1g-dev 11 | 12 | ##Postgresql and psycopg2 dependencies 13 | libpq-dev 14 | 15 | ##Pillow dependencies 16 | libtiff4-dev 17 | libjpeg8-dev 18 | libfreetype6-dev 19 | liblcms1-dev 20 | libwebp-dev 21 | 22 | ##django-extensions 23 | graphviz-dev 24 | -------------------------------------------------------------------------------- /utility/requirements-xenial.apt: -------------------------------------------------------------------------------- 1 | ##basic build dependencies of various Django apps for Ubuntu Xenial 16.04 2 | #build-essential metapackage install: make, gcc, g++, 3 | build-essential 4 | #required to translate 5 | gettext 6 | python3-dev 7 | 8 | ##shared dependencies of: 9 | ##Pillow, pylibmc 10 | zlib1g-dev 11 | 12 | ##Postgresql and psycopg2 dependencies 13 | libpq-dev 14 | 15 | ##Pillow dependencies 16 | libtiff5-dev 17 | libjpeg8-dev 18 | libfreetype6-dev 19 | liblcms2-dev 20 | libwebp-dev 21 | 22 | ##django-extensions 23 | graphviz-dev 24 | -------------------------------------------------------------------------------- /utility/unittest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH_TO_SCRIPT=$(echo $PWD/${0##*/}) 3 | PATH_TO_FOLDER=`dirname "$PATH_TO_SCRIPT"` 4 | 5 | export PYTHONPATH=$PYTHONPATH:$PATH_TO_FOLDER 6 | cd $PATH_TO_FOLDER && py.test tests/unit 7 | --------------------------------------------------------------------------------