├── .coveragerc ├── .editorconfig ├── .flake8 ├── .github ├── ISSUE_TEMPLATE.md └── workflows │ ├── publish.yml │ ├── stale.yml │ └── tests.yml ├── .gitignore ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── README.rst ├── django_serverless_cron ├── __init__.py ├── admin.py ├── app_settings.py ├── apps.py ├── management │ ├── __init__.py │ └── commands │ │ ├── __init__.py │ │ └── serverless_cron_run.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py ├── services.py ├── urls.py ├── utils.py └── views.py ├── docs ├── Makefile ├── authors.rst ├── conf.py ├── contributing.rst ├── history.rst ├── index.rst ├── make.bat └── readme.rst ├── manage.py ├── requirements.txt ├── requirements_dev.txt ├── requirements_test.txt ├── runtests.py ├── setup.cfg ├── setup.py ├── tasks.py ├── tests ├── README.md ├── __init__.py ├── example │ ├── __init__.py │ ├── jobs.py │ └── urls.py ├── requirements.txt ├── settings.py ├── test_admin.py ├── test_management_commands.py ├── test_models.py ├── test_services.py ├── test_utils.py ├── test_views.py ├── urls.py └── wsgi.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = true 3 | 4 | [report] 5 | omit = 6 | *site-packages* 7 | *tests* 8 | *.tox* 9 | show_missing = True 10 | exclude_lines = 11 | raise NotImplementedError 12 | -------------------------------------------------------------------------------- /.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 | [*.{html,css,scss,json,yml}] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false 21 | 22 | [Makefile] 23 | indent_style = tab 24 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | exclude = 3 | migrations 4 | __pycache__ 5 | manage.py 6 | settings.py 7 | env 8 | .env 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | * Django Serverless Cron version: 2 | * Django version: 3 | * Python version: 4 | * Operating System: 5 | 6 | ### Description 7 | 8 | Describe what you were trying to get done. 9 | Tell us what happened, what went wrong, and what you expected to happen. 10 | 11 | ### What I Did 12 | 13 | ``` 14 | Paste the command(s) you ran and the output. 15 | If there was a crash, please include the traceback here. 16 | ``` 17 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Upload Package 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | test: 9 | name: "Run tests" 10 | uses: paulonteri/django-serverless-cron/.github/workflows/tests.yml@master 11 | 12 | deploy: 13 | needs: 14 | - test 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | 21 | - name: Set up Python 22 | uses: actions/setup-python@v2 23 | with: 24 | python-version: "3.x" 25 | 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install -r requirements_dev.txt 30 | 31 | - name: Build package 32 | run: python setup.py bdist_wheel 33 | 34 | - name: Publish package 35 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 36 | with: 37 | user: __token__ 38 | password: ${{ secrets.PYPI_API_TOKEN }} 39 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. 2 | # 3 | # You can adjust the behavior by modifying this file. 4 | # For more information, see: 5 | # https://github.com/actions/stale 6 | name: Mark stale issues and pull requests 7 | 8 | on: 9 | schedule: 10 | - cron: '45 21 * * *' 11 | 12 | jobs: 13 | stale: 14 | 15 | runs-on: ubuntu-latest 16 | permissions: 17 | issues: write 18 | pull-requests: write 19 | 20 | steps: 21 | - uses: actions/stale@v3 22 | with: 23 | repo-token: ${{ secrets.GITHUB_TOKEN }} 24 | stale-issue-message: 'Stale issue message' 25 | stale-pr-message: 'Stale pull request message' 26 | stale-issue-label: 'no-issue-activity' 27 | stale-pr-label: 'no-pr-activity' 28 | days-before-pr-stale: 30 29 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | workflow_dispatch: 5 | workflow_call: 6 | push: 7 | paths: 8 | - "**.py" 9 | - "django_serverless_cron/**" 10 | - "tests/**" 11 | - "setup.cfg" 12 | - "requirements.txt" 13 | - "requirements_dev.txt" 14 | - "!django_serverless_cron/__init__.py" 15 | pull_request: 16 | branches: [master] 17 | 18 | jobs: 19 | test: 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Set up Python 26 | uses: actions/setup-python@v2 27 | with: 28 | python-version: "3.7" 29 | 30 | - name: Install dependencies 31 | run: | 32 | python -m pip install --upgrade pip 33 | python -m pip install flake8 34 | python -m pip install -r requirements_test.txt 35 | 36 | - name: Lint with flake8 37 | run: | 38 | # stop the build if there are Python syntax errors or undefined names 39 | flake8 django_serverless_cron tests --count --select=E9,F63,F7,F82 --show-source --statistics 40 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 41 | flake8 django_serverless_cron tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 42 | 43 | - name: Test 44 | run: | 45 | tox 46 | coverage xml 47 | 48 | - name: Upload coverage to Codecov 49 | uses: codecov/codecov-action@v2 50 | # with: 51 | # fail_ci_if_error: true 52 | # token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | __pycache__ 3 | 4 | # C extensions 5 | *.so 6 | 7 | # Packages 8 | *.egg 9 | *.egg-info 10 | dist 11 | build 12 | eggs 13 | parts 14 | bin 15 | var 16 | sdist 17 | develop-eggs 18 | .installed.cfg 19 | lib 20 | lib64 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | htmlcov 30 | 31 | # Translations 32 | *.mo 33 | 34 | # Mr Developer 35 | .mr.developer.cfg 36 | .project 37 | .pydevproject 38 | 39 | # Pycharm/Intellij 40 | .idea 41 | 42 | # VsCode 43 | .vscode 44 | 45 | # Complexity 46 | output/*.html 47 | output/*/index.html 48 | 49 | # Sphinx 50 | docs/_build 51 | 52 | .DS_Store 53 | 54 | db.sqlite3 55 | 56 | # virtual environment 57 | ./venv 58 | ./env 59 | coverage.xml 60 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | 3 | language: python 4 | 5 | python: 6 | - "3.6" 7 | 8 | env: 9 | - TOX_ENV=py36-django-111 10 | - TOX_ENV=py35-django-111 11 | - TOX_ENV=py27-django-111 12 | - TOX_ENV=py37-django-21 13 | - TOX_ENV=py36-django-21 14 | - TOX_ENV=py35-django-21 15 | 16 | matrix: 17 | fast_finish: true 18 | 19 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 20 | install: pip install -r requirements_test.txt 21 | 22 | # command to run tests using coverage, e.g. python setup.py test 23 | script: tox -e $TOX_ENV 24 | 25 | after_success: 26 | - codecov -e TOX_ENV 27 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Paul Onteri 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | You can contribute in many ways: 9 | 10 | Types of Contributions 11 | ---------------------- 12 | 13 | Report Bugs 14 | ~~~~~~~~~~~ 15 | 16 | Report bugs at https://github.com/paulonteri/django-serverless-cron/issues. 17 | 18 | If you are reporting a bug, please include: 19 | 20 | * Your operating system name and version. 21 | * Any details about your local setup that might be helpful in troubleshooting. 22 | * Detailed steps to reproduce the bug. 23 | 24 | Fix Bugs 25 | ~~~~~~~~ 26 | 27 | Look through the GitHub issues for bugs. Anything tagged with "bug" 28 | is open to whoever wants to implement it. 29 | 30 | Implement Features 31 | ~~~~~~~~~~~~~~~~~~ 32 | 33 | Look through the GitHub issues for features. Anything tagged with "feature" 34 | is open to whoever wants to implement it. 35 | 36 | Write Documentation 37 | ~~~~~~~~~~~~~~~~~~~ 38 | 39 | Django Serverless Cron could always use more documentation, whether as part of the 40 | official Django Serverless Cron docs, in docstrings, or even on the web in blog posts, 41 | articles, and such. 42 | 43 | Submit Feedback 44 | ~~~~~~~~~~~~~~~ 45 | 46 | The best way to send feedback is to file an issue at https://github.com/paulonteri/django-serverless-cron/issues. 47 | 48 | If you are proposing a feature: 49 | 50 | * Explain in detail how it would work. 51 | * Keep the scope as narrow as possible, to make it easier to implement. 52 | * Remember that this is a volunteer-driven project, and that contributions 53 | are welcome :) 54 | 55 | Get Started! 56 | ------------ 57 | 58 | Ready to contribute? Here's how to set up `django-serverless-cron` for local development. 59 | 60 | 1. Fork the `django-serverless-cron` repo on GitHub. 61 | 2. Clone your fork locally:: 62 | 63 | $ git clone git@github.com:your_name_here/django-serverless-cron.git 64 | 65 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 66 | 67 | $ mkvirtualenv django-serverless-cron 68 | $ cd django-serverless-cron/ 69 | $ python setup.py develop 70 | 71 | 4. Create a branch for local development:: 72 | 73 | $ git checkout -b name-of-your-bugfix-or-feature 74 | 75 | Now you can make your changes locally. 76 | 77 | 5. When you're done making changes, check that your changes pass flake8 and the 78 | tests, including testing other Python versions with tox:: 79 | 80 | $ flake8 django_serverless_cron tests 81 | $ python setup.py test 82 | $ tox 83 | 84 | To get flake8 and tox, just pip install them into your virtualenv. 85 | 86 | 6. Commit your changes and push your branch to GitHub:: 87 | 88 | $ git add . 89 | $ git commit -m "Your detailed description of your changes." 90 | $ git push origin name-of-your-bugfix-or-feature 91 | 92 | 7. Submit a pull request through the GitHub website. 93 | 94 | Pull Request Guidelines 95 | ----------------------- 96 | 97 | Before you submit a pull request, check that it meets these guidelines: 98 | 99 | 1. The pull request should include tests. 100 | 2. If the pull request adds functionality, the docs should be updated. Put 101 | your new functionality into a function with a docstring, and add the 102 | feature to the list in README.rst. 103 | 3. The pull request should work for Python 2.6, 2.7, and 3.3, and for PyPy. Check 104 | https://travis-ci.org/paulonteri/django-serverless-cron/pull_requests 105 | and make sure that the tests pass for all supported Python versions. 106 | 107 | Tips 108 | ---- 109 | 110 | To run a subset of tests:: 111 | 112 | $ python -m unittest tests.test_django_serverless_cron 113 | 114 | Tests 115 | ------------- 116 | 117 | Does the code actually work? 118 | 119 | :: 120 | 121 | source /bin/activate 122 | (myenv) $ pip install tox 123 | (myenv) $ tox 124 | 125 | 126 | Development commands 127 | --------------------- 128 | 129 | :: 130 | 131 | pip install -r requirements_dev.txt 132 | invoke -l 133 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | .. :changelog: 2 | 3 | History 4 | ------- 5 | 6 | 0.1.3 (2022-01-02) 7 | ^^^^^^^^^^^^^^^^^^ 8 | 9 | - fix bug in running the management command 10 | - wrap `run_all_jobs()` in a class 11 | 12 | 0.1.2 (2022-01-01) 13 | ^^^^^^^^^^^^^^^^^^ 14 | 15 | - Fix typo in the docs 16 | 17 | 0.1.1 (2022-01-01) 18 | ^^^^^^^^^^^^^^^^^^ 19 | 20 | Birth: First release on PyPI. 21 | 22 | Has the ability to: 23 | 24 | - Run jobs via the `/run` path 25 | - Run jobs via the management command `serverless_cron_run.py` 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | MIT License 3 | 4 | Copyright (c) 2022, Paul Onteri 5 | 6 | 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: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | 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. 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS.rst 2 | include CONTRIBUTING.rst 3 | include HISTORY.rst 4 | include LICENSE 5 | include README.rst 6 | include requirements.txt 7 | recursive-include django_serverless_cron *.html *.png *.gif *js *.css *jpg *jpeg *svg *py 8 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============================= 2 | django-serverless-cron 🦡 3 | ============================= 4 | 5 | .. image:: https://badge.fury.io/py/django-serverless-cron.svg 6 | :target: https://badge.fury.io/py/django-serverless-cron 7 | 8 | .. image:: https://github.com/paulonteri/django-serverless-cron/actions/workflows/tests.yml/badge.svg 9 | :target: https://github.com/paulonteri/django-serverless-cron/actions/workflows/tests.yml 10 | 11 | .. image:: https://codecov.io/gh/paulonteri/django-serverless-cron/branch/master/graph/badge.svg 12 | :target: https://codecov.io/gh/paulonteri/django-serverless-cron 13 | 14 | .. image:: https://readthedocs.org/projects/django-serverless-cron/badge/?version=latest 15 | :target: http://django-serverless-cron.readthedocs.io/?badge=latest 16 | 17 | 18 | django-serverless-cron is a Django app with a simpler approach running cron jobs. 19 | This is done through exposing a HTTP endpoint to invoke the jobs that allows you to run any task without having to manage always-on infrastructure. 20 | 21 | There is also an option to run jobs via management commands and the Django admin. 22 | 23 | Why? 24 | ---- 25 | 26 | This is essentially a replacement/supplement for a traditional OS 'cron' or 'job scheduler' system: 27 | 28 | - Serverless cron jobs no-longer a pain. Note that if you have alternatives like django-crontab or celery working well for you, good for you! You probably don't need this. However, it's okay to be curious. 29 | - Schedule jobs to run at a frequency that is less than 1 min. (crontab is limited to 1 min) 30 | - The machine running crontab is no longer a single point of failure. 31 | - The problem with the above systems is that they are often configured at the operating system level, which means their configuration is probably not easily 'portable' and 'debug-able' (if you are developing on Windows, the scheduler works differently from Linux or Unix). Also can not easily be integrated into a development environment. 32 | - Manually triggered cron jobs. Eg: via the Django Admin. 33 | - Alternative to cron services that aren't always available on free (and sometimes paid) web hosting services. 34 | - Easier access to cron job execution logs and monitoring execution failures. 35 | - No need to learn crontab. Think of it as a friendlier alternative to traditional cron jobs. Simple cron job creation. No need for cron syntax, no guessing on job frequency. Easy controls. 36 | - Designed around services like `Google Cloud Scheduler` and `Amazon EventBridge`. 37 | 38 | Documentation 39 | ------------- 40 | 41 | Documentation is graciously hosted at https://django-serverless-cron.readthedocs.io. 42 | 43 | Contributions 44 | ------------- 45 | 46 | Feel free to make pull requests and submit issues/requests. 47 | Find more detailed instructions under the `contributing` section. 48 | 49 | Alternatively, you can leave a star on the repo to show your support. 🙂 50 | 51 | Quickstart 52 | ---------- 53 | 54 | Installation 55 | ^^^^^^^^^^^^ 56 | 57 | Install Django Serverless Cron:: 58 | 59 | pip install django-serverless-cron 60 | 61 | 62 | Settings 63 | ^^^^^^^^ 64 | 65 | Add it to your `INSTALLED_APPS`: 66 | 67 | .. code-block:: python 68 | 69 | INSTALLED_APPS = ( 70 | # ... 71 | 'django_serverless_cron' 72 | # ... 73 | ) 74 | 75 | Add jobs to your settings file: 76 | 77 | .. code-block:: python 78 | 79 | SERVERLESS_CRONJOBS = [ 80 | # ( 81 | # '1_hours', # frequency (seconds, minutes, hours, days, weeks) -> in this case, every one hour 82 | # 'mail.jobs.send_mail_function', # path to task/function functions -> in this case, send_mail_function() 83 | # {'kwarg1': 'foo'} # kwargs passed to the function 84 | # ), 85 | ( 86 | '1_days', 87 | 'your_app.services.your_job_function', 88 | {'kwarg1': 'foo', 'kwarg2': 'bar', "is_bulk": True} 89 | ), 90 | ( 91 | '1_hours', 92 | 'mail.jobs.send_mail_function', 93 | {} # job without kwargs 94 | ), 95 | ] 96 | 97 | 98 | URL patterns 99 | ^^^^^^^^^^^^ 100 | Add the jobs to your URL patterns: 101 | 102 | .. code-block:: python 103 | 104 | from django.urls import path, re_path, include #add re_path and include 105 | from django_serverless_cron import urls as django_serverless_cron_urls 106 | 107 | 108 | urlpatterns = [ 109 | # ... 110 | re_path(r'^', include(django_serverless_cron_urls)), 111 | #... 112 | ] 113 | 114 | Migrate 115 | ^^^^^^^ 116 | 117 | .. code-block:: bash 118 | 119 | python manage.py migrate 120 | 121 | Running Jobs 122 | ------------ 123 | 124 | In Development 125 | ^^^^^^^^^^^^^^ 126 | 127 | Running Jobs through HTTP requests 128 | """""""""""""""""""""""""""""""""" 129 | 130 | Call the `/run` path to run all jobs: 131 | 132 | Example: 133 | 134 | .. code-block:: bash 135 | 136 | curl http://localhost:8000/run 137 | 138 | or 139 | 140 | .. code-block:: python 141 | 142 | import requests 143 | 144 | x = requests.get('http://localhost:8000/run') 145 | 146 | 147 | Running Jobs through the management command 148 | """"""""""""""""""""""""""""""""""""""""""" 149 | 150 | This will run the jobs every 30 seconds: 151 | 152 | .. code-block:: bash 153 | 154 | python manage.py serverless_cron_run 155 | 156 | You can alternatively add the `--single_run='True'` option to run the jobs just once. 157 | 158 | In Production 159 | ^^^^^^^^^^^^^ 160 | 161 | Similar to in development, we can call the `/run` path via fully managed services which are usually ridiculously cheap. Examples: 162 | 163 | - https://cloud.google.com/scheduler -> Great feature set, easy to use, reasonable free tier & very cheap. 164 | - https://aws.amazon.com/eventbridge 165 | - https://azure.microsoft.com/en-gb/services/logic-apps formerly https://docs.microsoft.com/en-us/azure/scheduler/scheduler-intro 166 | - https://cron-job.org/en/ -> Absolutely free and open-source: https://github.com/pschlan/cron-job.org 167 | - https://www.easycron.com 168 | - https://cronhub.io 169 | - https://cronless.com -> Has 30 Second Cron Jobs 170 | - https://github.com/features/actions; https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onschedule -> eg making a HTTP request using `curl` in a step 171 | - https://www.cronjob.de 172 | - https://zeplo.io 173 | - https://catalyst.zoho.com/help/cron.html 174 | - https://www.cronjobservices.com 175 | 176 | Related media 177 | ------------- 178 | 179 | For more learning check out: 180 | 181 | - https://dev.to/googlecloud/when-you-re-not-around-trigger-cloud-run-on-a-schedule-53p4 | https://youtu.be/XIwbIimM49Y 182 | - https://aws.amazon.com/blogs/compute/using-api-destinations-with-amazon-eventbridge/ 183 | - https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html 184 | - https://www.ibm.com/cloud/blog/how-to-schedule-rest-api-calls-on-ibm-cloud 185 | - https://vercel.com/docs/concepts/solutions/cron-jobs 186 | - cron-like recurring task scheduler design https://stackoverflow.com/a/3980935/10904662 187 | - https://www.dailyhostnews.com/google-cloud-launches-fully-managed-cron-job-scheduler-for-enterprises 188 | - Cloud Scheduler from Fireship https://www.youtube.com/watch?v=WUPEUjvSBW8 189 | 190 | Credits 191 | ------- 192 | 193 | Tools used in rendering this package: 194 | 195 | * Cookiecutter_ 196 | * `cookiecutter-djangopackage`_ 197 | 198 | .. _Cookiecutter: https://github.com/audreyr/cookiecutter 199 | .. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage 200 | -------------------------------------------------------------------------------- /django_serverless_cron/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.1.3' 2 | -------------------------------------------------------------------------------- /django_serverless_cron/admin.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from django.contrib import admin 4 | 5 | from .models import JobRun 6 | from .services import Job 7 | 8 | 9 | def run_selected_jobs(modeladmin, request, queryset): 10 | for job_run in queryset: 11 | job = Job(function_path=job_run.function_path, kwargs=job_run.kwargs) 12 | job.run() 13 | 14 | 15 | run_selected_jobs.short_description = 'Re-run selected jobs' 16 | 17 | 18 | @admin.register(JobRun) 19 | class JobRunAdmin(admin.ModelAdmin): 20 | list_display = ( 21 | "function_path", "kwargs", 22 | "frequency", "time_attempted_running", "time_finished_running" 23 | ) 24 | list_filter = ("function_path", ) 25 | actions = (run_selected_jobs,) 26 | -------------------------------------------------------------------------------- /django_serverless_cron/app_settings.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Settings(): 4 | def __init__(self, settings): 5 | self.SERVERLESS_CRONJOBS = getattr(settings, 'SERVERLESS_CRONJOBS', []) 6 | -------------------------------------------------------------------------------- /django_serverless_cron/apps.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 2 | from django.apps import AppConfig 3 | 4 | 5 | class DjangoServerlessCronConfig(AppConfig): 6 | name = 'django_serverless_cron' 7 | -------------------------------------------------------------------------------- /django_serverless_cron/management/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | -------------------------------------------------------------------------------- /django_serverless_cron/management/commands/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | -------------------------------------------------------------------------------- /django_serverless_cron/management/commands/serverless_cron_run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from datetime import datetime 5 | 6 | from django.conf import settings 7 | from django.core.management.base import BaseCommand 8 | 9 | from django_serverless_cron.services import RunJobs 10 | 11 | 12 | class Command(BaseCommand): 13 | help = 'Runs all jobs defined in your settings file' 14 | 15 | def add_arguments(self, parser): 16 | parser.add_argument( 17 | '--single_run', type=eval, 18 | choices=[True, False], 19 | default='False', 20 | help='The jobs should be executed once (instead of every 30 seconds). Default=False.' 21 | ) 22 | 23 | def handle(self, *args, **kwargs): 24 | single_run = kwargs['single_run'] 25 | 26 | if single_run is True: 27 | print("----------------------------- Jobs running once -----------------------------") 28 | RunJobs.run_all_jobs() 29 | return 30 | 31 | last_run_time = None 32 | while True: 33 | if last_run_time is None or (datetime.now() - last_run_time).seconds >= 30: 34 | print("----------------------- Jobs running. Will run again in 30 seconds --------------------------") 35 | last_run_time = datetime.now() 36 | RunJobs.run_all_jobs() 37 | 38 | # not run loop if in testing mode 39 | try: 40 | if settings.IS_IN_DEV_TESTING == True: 41 | break 42 | except AttributeError: 43 | pass 44 | -------------------------------------------------------------------------------- /django_serverless_cron/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2.11 on 2022-01-27 11:12 2 | 3 | from django.db import migrations, models 4 | import django.utils.timezone 5 | import uuid 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='JobRun', 18 | fields=[ 19 | ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), 20 | ('function_path', models.CharField(help_text='The path to the function executed.', max_length=255)), 21 | ('kwargs', models.JSONField(blank=True, help_text='The kwargs to passed to the function.', null=True)), 22 | ('frequency', models.CharField(blank=True, help_text='The frequency that was set for the job.', max_length=255, null=True)), 23 | ('time_attempted_running', models.DateTimeField(default=django.utils.timezone.now, help_text='Time when first attempted to run the job')), 24 | ('time_finished_running', models.DateTimeField(blank=True, help_text='Time when the job finished running', null=True)), 25 | ('error', models.TextField(blank=True, null=True)), 26 | ], 27 | options={ 28 | 'ordering': ('-time_attempted_running',), 29 | }, 30 | ), 31 | ] 32 | -------------------------------------------------------------------------------- /django_serverless_cron/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paulonteri/django-serverless-cron/b52c625b7187756bb3ca1b63b7c992cc7988f304/django_serverless_cron/migrations/__init__.py -------------------------------------------------------------------------------- /django_serverless_cron/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import uuid 4 | 5 | from django.db import models 6 | from django.utils import timezone 7 | 8 | 9 | class JobRun(models.Model): 10 | """ 11 | Django model that stores all job executions 12 | """ 13 | id = models.UUIDField( 14 | primary_key=True, default=uuid.uuid4, editable=False) 15 | 16 | function_path = models.CharField( 17 | max_length=255, 18 | help_text="The path to the function executed." 19 | ) 20 | kwargs = models.JSONField( 21 | null=True, blank=True, 22 | help_text="The kwargs to passed to the function." 23 | ) 24 | frequency = models.CharField( 25 | max_length=255, null=True, blank=True, 26 | help_text="The frequency that was set for the job." 27 | ) 28 | # is_running = models.BooleanField( 29 | # default=False, 30 | # help_text="Whether the job is currently running." 31 | # ) 32 | time_attempted_running = models.DateTimeField( 33 | default=timezone.now, 34 | help_text="Time when first attempted to run the job" 35 | ) 36 | time_finished_running = models.DateTimeField( 37 | null=True, blank=True, 38 | help_text="Time when the job finished running" 39 | ) 40 | error = models.TextField(null=True, blank=True) 41 | 42 | objects = models.Manager() 43 | 44 | class Meta: 45 | ordering = ('-time_attempted_running',) 46 | 47 | def __str__(self): 48 | return f"{self.function_path} {str(self.kwargs)} {self.frequency}" 49 | -------------------------------------------------------------------------------- /django_serverless_cron/services.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import datetime 4 | import logging 5 | from typing import Dict 6 | 7 | from django.core.exceptions import ObjectDoesNotExist 8 | from django.db import transaction 9 | from django.utils import timezone 10 | 11 | from .app_settings import Settings 12 | from .models import JobRun 13 | from .utils import run_function_from_path 14 | 15 | from django.conf import settings 16 | 17 | 18 | logger = logging.getLogger(__name__) 19 | 20 | 21 | class Job: 22 | """ 23 | A class used to represent a Job that should be executed 24 | 25 | Attributes 26 | ---------- 27 | frequency: str | None 28 | the frequency in which the jobs should be executed 29 | function_path: str 30 | the path to the function to be executed 31 | kwargs: Dict 32 | kwargs passed to to the function to be executed 33 | 34 | Methods 35 | ------- 36 | run() 37 | Attempts to execute the job. 38 | """ 39 | 40 | def __init__(self, *, frequency: str = None, function_path: str, kwargs: Dict): 41 | self.frequency = frequency 42 | self.kwargs = kwargs 43 | self.function_path = function_path 44 | 45 | @transaction.atomic 46 | def run(self): 47 | """ 48 | Runs the job and records the job ran to the database. \n 49 | Jobs that are not valid to run (based on their frequency) are skipped . 50 | """ 51 | logger.info(f"Running job: {self.__str__()}") 52 | if not self._is_valid_time_for_job_to_run(): 53 | logger.info(f"Job terminated. Not valid time for job run: {self.__str__()}") 54 | return 55 | 56 | job_run = JobRun.objects.create( 57 | function_path=self.function_path, 58 | kwargs=self.kwargs, 59 | frequency=self.frequency, 60 | ) 61 | 62 | try: 63 | with transaction.atomic(): # ? 64 | run_function_from_path(self.function_path, self.kwargs) 65 | except Exception as e: 66 | job_run.error = str(e) 67 | logger.info(f"Error running job: {str(e)}") 68 | else: 69 | job_run.time_finished_running = timezone.now() 70 | finally: 71 | job_run.save() 72 | logger.info(f"Job run complete: {self.__str__()}") 73 | 74 | def _is_valid_time_for_job_to_run(self) -> bool: 75 | """ 76 | Checks whether it is a valid time to run the job based on its frequency. 77 | This is by checking the last run (time_attempted_running) comparing it with the current time. \n 78 | If the frequency is None then the job will always be run. 79 | """ 80 | if not self.frequency: 81 | return True 82 | 83 | try: 84 | last_run = JobRun.objects.filter( 85 | function_path=self.function_path, 86 | kwargs=self.kwargs, 87 | frequency=self.frequency 88 | ).exclude( 89 | time_attempted_running=None 90 | ).latest( 91 | 'time_attempted_running' 92 | ) 93 | except ObjectDoesNotExist: 94 | return True 95 | else: 96 | value, unit = self.frequency.split("_") 97 | value = int(value) 98 | 99 | invalid_runs_start_time = timezone.now()\ 100 | - datetime.timedelta(**{unit: value}) 101 | 102 | # print("last_run.time_attempted_running", "invalid_runs_start_time") 103 | # print(last_run.time_attempted_running, invalid_runs_start_time) 104 | if last_run.time_attempted_running > invalid_runs_start_time: 105 | return False 106 | 107 | return True 108 | 109 | def __str__(self) -> str: 110 | return f"{self.function_path} {str(self.kwargs)} {self.frequency}" 111 | 112 | def __repr__(self) -> str: 113 | return self.__str__() 114 | 115 | 116 | class RunJobs: 117 | """ 118 | A class used to run jobs defined in settings 119 | 120 | Methods 121 | ------- 122 | run_all_jobs() 123 | Runs all jobs defined in settings 124 | """ 125 | 126 | @staticmethod 127 | def run_all_jobs(): 128 | """ 129 | Runs all jobs defined in settings 130 | """ 131 | app_settings = Settings(settings) 132 | jobs = [ 133 | Job(frequency=frequency, function_path=function_path, kwargs=kwargs) 134 | for frequency, function_path, kwargs in app_settings.SERVERLESS_CRONJOBS 135 | ] 136 | 137 | for job in jobs: 138 | job.run() 139 | -------------------------------------------------------------------------------- /django_serverless_cron/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | from django.urls import re_path 5 | from .views import RunJobsView 6 | 7 | app_name = 'django_serverless_cron' 8 | urlpatterns = [ 9 | re_path( 10 | "^run/$", 11 | RunJobsView.as_view(), 12 | name='django-serverless-cron-run-jobs' 13 | ), 14 | ] 15 | -------------------------------------------------------------------------------- /django_serverless_cron/utils.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | from typing import Dict 3 | 4 | 5 | def run_function_from_path(function_path: str, kwargs: Dict): 6 | """ 7 | Runs a function given its path 8 | ... 9 | Parameters 10 | ---------- 11 | function_path: str 12 | the path to the function to be executed 13 | kwargs: Dict 14 | kwargs passed to to the function to be executed 15 | """ 16 | 17 | module_name, function_name = function_path.rsplit('.', 1) 18 | module = importlib.import_module(module_name) 19 | 20 | task = getattr(module, function_name) 21 | 22 | return task(**kwargs) 23 | -------------------------------------------------------------------------------- /django_serverless_cron/views.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from django.http import HttpResponse 4 | from django.views import View 5 | 6 | from .services import RunJobs 7 | 8 | 9 | class RunJobsView(View): 10 | 11 | def get(self, request, *args, **kwargs): 12 | RunJobs.run_all_jobs() 13 | return HttpResponse('Done') 14 | -------------------------------------------------------------------------------- /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 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/complexity.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/complexity.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/complexity" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/complexity" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # complexity documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | cwd = os.getcwd() 22 | parent = os.path.dirname(cwd) 23 | sys.path.append(parent) 24 | 25 | import django_serverless_cron 26 | 27 | # -- General configuration ----------------------------------------------------- 28 | 29 | # If your documentation needs a minimal Sphinx version, state it here. 30 | #needs_sphinx = '1.0' 31 | 32 | # Add any Sphinx extension module names here, as strings. They can be extensions 33 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 34 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ['_templates'] 38 | 39 | # The suffix of source filenames. 40 | source_suffix = '.rst' 41 | 42 | # The encoding of source files. 43 | #source_encoding = 'utf-8-sig' 44 | 45 | # The master toctree document. 46 | master_doc = 'index' 47 | 48 | # General information about the project. 49 | project = u'Django Serverless Cron' 50 | copyright = u'2022, Paul Onteri' 51 | 52 | # The version info for the project you're documenting, acts as replacement for 53 | # |version| and |release|, also used in various other places throughout the 54 | # built documents. 55 | # 56 | # The short X.Y version. 57 | version = django_serverless_cron.__version__ 58 | # The full version, including alpha/beta/rc tags. 59 | release = django_serverless_cron.__version__ 60 | 61 | # The language for content autogenerated by Sphinx. Refer to documentation 62 | # for a list of supported languages. 63 | #language = None 64 | 65 | # There are two options for replacing |today|: either, you set today to some 66 | # non-false value, then it is used: 67 | #today = '' 68 | # Else, today_fmt is used as the format for a strftime call. 69 | #today_fmt = '%B %d, %Y' 70 | 71 | # List of patterns, relative to source directory, that match files and 72 | # directories to ignore when looking for source files. 73 | exclude_patterns = ['_build'] 74 | 75 | # The reST default role (used for this markup: `text`) to use for all documents. 76 | #default_role = None 77 | 78 | # If true, '()' will be appended to :func: etc. cross-reference text. 79 | #add_function_parentheses = True 80 | 81 | # If true, the current module name will be prepended to all description 82 | # unit titles (such as .. function::). 83 | #add_module_names = True 84 | 85 | # If true, sectionauthor and moduleauthor directives will be shown in the 86 | # output. They are ignored by default. 87 | #show_authors = False 88 | 89 | # The name of the Pygments (syntax highlighting) style to use. 90 | pygments_style = 'sphinx' 91 | 92 | # A list of ignored prefixes for module index sorting. 93 | #modindex_common_prefix = [] 94 | 95 | # If true, keep warnings as "system message" paragraphs in the built documents. 96 | #keep_warnings = False 97 | 98 | 99 | # -- Options for HTML output --------------------------------------------------- 100 | 101 | # The theme to use for HTML and HTML Help pages. See the documentation for 102 | # a list of builtin themes. 103 | html_theme = 'default' 104 | 105 | # Theme options are theme-specific and customize the look and feel of a theme 106 | # further. For a list of options available for each theme, see the 107 | # documentation. 108 | #html_theme_options = {} 109 | 110 | # Add any paths that contain custom themes here, relative to this directory. 111 | #html_theme_path = [] 112 | 113 | # The name for this set of Sphinx documents. If None, it defaults to 114 | # " v documentation". 115 | #html_title = None 116 | 117 | # A shorter title for the navigation bar. Default is the same as html_title. 118 | #html_short_title = None 119 | 120 | # The name of an image file (relative to this directory) to place at the top 121 | # of the sidebar. 122 | #html_logo = None 123 | 124 | # The name of an image file (within the static path) to use as favicon of the 125 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 126 | # pixels large. 127 | #html_favicon = None 128 | 129 | # Add any paths that contain custom static files (such as style sheets) here, 130 | # relative to this directory. They are copied after the builtin static files, 131 | # so a file named "default.css" will overwrite the builtin "default.css". 132 | html_static_path = ['_static'] 133 | 134 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 135 | # using the given strftime format. 136 | #html_last_updated_fmt = '%b %d, %Y' 137 | 138 | # If true, SmartyPants will be used to convert quotes and dashes to 139 | # typographically correct entities. 140 | #html_use_smartypants = True 141 | 142 | # Custom sidebar templates, maps document names to template names. 143 | #html_sidebars = {} 144 | 145 | # Additional templates that should be rendered to pages, maps page names to 146 | # template names. 147 | #html_additional_pages = {} 148 | 149 | # If false, no module index is generated. 150 | #html_domain_indices = True 151 | 152 | # If false, no index is generated. 153 | #html_use_index = True 154 | 155 | # If true, the index is split into individual pages for each letter. 156 | #html_split_index = False 157 | 158 | # If true, links to the reST sources are added to the pages. 159 | #html_show_sourcelink = True 160 | 161 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 162 | #html_show_sphinx = True 163 | 164 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 165 | #html_show_copyright = True 166 | 167 | # If true, an OpenSearch description file will be output, and all pages will 168 | # contain a tag referring to it. The value of this option must be the 169 | # base URL from which the finished HTML is served. 170 | #html_use_opensearch = '' 171 | 172 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 173 | #html_file_suffix = None 174 | 175 | # Output file base name for HTML help builder. 176 | htmlhelp_basename = 'django-serverless-crondoc' 177 | 178 | 179 | # -- Options for LaTeX output -------------------------------------------------- 180 | 181 | latex_elements = { 182 | # The paper size ('letterpaper' or 'a4paper'). 183 | #'papersize': 'letterpaper', 184 | 185 | # The font size ('10pt', '11pt' or '12pt'). 186 | #'pointsize': '10pt', 187 | 188 | # Additional stuff for the LaTeX preamble. 189 | #'preamble': '', 190 | } 191 | 192 | # Grouping the document tree into LaTeX files. List of tuples 193 | # (source start file, target name, title, author, documentclass [howto/manual]). 194 | latex_documents = [ 195 | ('index', 'django-serverless-cron.tex', u'Django Serverless Cron Documentation', 196 | u'Paul Onteri', 'manual'), 197 | ] 198 | 199 | # The name of an image file (relative to this directory) to place at the top of 200 | # the title page. 201 | #latex_logo = None 202 | 203 | # For "manual" documents, if this is true, then toplevel headings are parts, 204 | # not chapters. 205 | #latex_use_parts = False 206 | 207 | # If true, show page references after internal links. 208 | #latex_show_pagerefs = False 209 | 210 | # If true, show URL addresses after external links. 211 | #latex_show_urls = False 212 | 213 | # Documents to append as an appendix to all manuals. 214 | #latex_appendices = [] 215 | 216 | # If false, no module index is generated. 217 | #latex_domain_indices = True 218 | 219 | 220 | # -- Options for manual page output -------------------------------------------- 221 | 222 | # One entry per manual page. List of tuples 223 | # (source start file, name, description, authors, manual section). 224 | man_pages = [ 225 | ('index', 'django-serverless-cron', u'Django Serverless Cron Documentation', 226 | [u'Paul Onteri'], 1) 227 | ] 228 | 229 | # If true, show URL addresses after external links. 230 | #man_show_urls = False 231 | 232 | 233 | # -- Options for Texinfo output ------------------------------------------------ 234 | 235 | # Grouping the document tree into Texinfo files. List of tuples 236 | # (source start file, target name, title, author, 237 | # dir menu entry, description, category) 238 | texinfo_documents = [ 239 | ('index', 'django-serverless-cron', u'Django Serverless Cron Documentation', 240 | u'Paul Onteri', 'django-serverless-cron', 'One line description of project.', 241 | 'Miscellaneous'), 242 | ] 243 | 244 | # Documents to append as an appendix to all manuals. 245 | #texinfo_appendices = [] 246 | 247 | # If false, no module index is generated. 248 | #texinfo_domain_indices = True 249 | 250 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 251 | #texinfo_show_urls = 'footnote' 252 | 253 | # If true, do not generate a @detailmenu in the "Top" node's menu. 254 | #texinfo_no_detailmenu = False 255 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst 2 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. complexity documentation master file, created by 2 | sphinx-quickstart on Tue Jul 9 22:26:36 2013. 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 Django Serverless Cron's documentation! 7 | ================================================================= 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | readme 15 | contributing 16 | authors 17 | history 18 | -------------------------------------------------------------------------------- /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. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\complexity.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\complexity.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import unicode_literals, absolute_import 4 | 5 | import os 6 | import sys 7 | 8 | if __name__ == "__main__": 9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") 10 | from django.core.management import execute_from_command_line 11 | 12 | execute_from_command_line(sys.argv) 13 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | coverage==4.4.1 2 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | invoke 2 | twine 3 | wheel 4 | zest.releaser 5 | -------------------------------------------------------------------------------- /requirements_test.txt: -------------------------------------------------------------------------------- 1 | coverage==4.4.1 2 | mock>=1.0.1 3 | flake8>=2.1.0 4 | tox>=1.7.0 5 | codecov>=2.0.0 -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 3 | from __future__ import unicode_literals, absolute_import 4 | 5 | import os 6 | import sys 7 | 8 | import django 9 | from django.conf import settings 10 | from django.test.utils import get_runner 11 | 12 | 13 | def run_tests(*test_args): 14 | if not test_args: 15 | test_args = ['tests'] 16 | 17 | os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' 18 | django.setup() 19 | TestRunner = get_runner(settings) 20 | test_runner = TestRunner() 21 | failures = test_runner.run_tests(test_args) 22 | sys.exit(bool(failures)) 23 | 24 | 25 | if __name__ == '__main__': 26 | run_tests(*sys.argv[1:]) 27 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [wheel] 2 | universal = 1 3 | 4 | [flake8] 5 | ignore = D203 6 | exclude = 7 | django_serverless_cron/migrations, 8 | .git, 9 | .tox, 10 | docs/conf.py, 11 | build, 12 | dist 13 | max-line-length = 119 14 | 15 | [zest.releaser] 16 | python-file-with-version = django_serverless_cron/__init__.py 17 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | import os 4 | import re 5 | import sys 6 | 7 | try: 8 | from setuptools import setup 9 | except ImportError: 10 | from distutils.core import setup 11 | 12 | 13 | def get_version(*file_paths): 14 | """Retrieves the version from django_serverless_cron/__init__.py""" 15 | filename = os.path.join(os.path.dirname(__file__), *file_paths) 16 | version_file = open(filename).read() 17 | version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", 18 | version_file, re.M) 19 | if version_match: 20 | return version_match.group(1) 21 | raise RuntimeError('Unable to find version string.') 22 | 23 | 24 | version = get_version("django_serverless_cron", "__init__.py") 25 | 26 | 27 | if sys.argv[-1] == 'publish': 28 | try: 29 | import wheel 30 | print("Wheel version: ", wheel.__version__) 31 | except ImportError: 32 | print('Wheel library missing. Please run "pip install wheel"') 33 | sys.exit() 34 | os.system('python setup.py sdist upload') 35 | os.system('python setup.py bdist_wheel upload') 36 | sys.exit() 37 | 38 | if sys.argv[-1] == 'tag': 39 | print("Tagging the version on git:") 40 | os.system("git tag -a %s -m 'version %s'" % (version, version)) 41 | os.system("git push --tags") 42 | sys.exit() 43 | 44 | readme = open('README.rst').read() 45 | history = open('HISTORY.rst').read().replace('.. :changelog:', '') 46 | requirements = open('requirements.txt').readlines() 47 | 48 | setup( 49 | name='django-serverless-cron', 50 | version=version, 51 | description="""Django Serverless Cron 🦡""", 52 | long_description=readme + '\n\n' + history, 53 | author='Paul Onteri', 54 | author_email='me@paulonteri.com', 55 | url='https://github.com/paulonteri/django-serverless-cron', 56 | packages=[ 57 | 'django_serverless_cron', 58 | ], 59 | include_package_data=True, 60 | install_requires=requirements, 61 | license="MIT", 62 | zip_safe=False, 63 | keywords='django-serverless-cron', 64 | classifiers=[ 65 | 'Development Status :: 3 - Alpha', 66 | 'Framework :: Django :: 3.1', 67 | 'Framework :: Django :: 3.2', 68 | # 'Framework :: Django :: 4.0', 69 | 'Intended Audience :: Developers', 70 | 'License :: OSI Approved :: BSD License', 71 | 'Natural Language :: English', 72 | 'Programming Language :: Python :: 3.5', 73 | 'Programming Language :: Python :: 3.6', 74 | 'Programming Language :: Python :: 3.7', 75 | 'Programming Language :: Python :: 3.8', 76 | 'Programming Language :: Python :: 3.9', 77 | 'Programming Language :: Python :: 3.10', 78 | ], 79 | ) 80 | -------------------------------------------------------------------------------- /tasks.py: -------------------------------------------------------------------------------- 1 | import os 2 | import webbrowser 3 | 4 | from invoke import task 5 | 6 | 7 | def open_browser(path): 8 | try: 9 | from urllib import pathname2url 10 | except: 11 | from urllib.request import pathname2url 12 | webbrowser.open("file://" + pathname2url(os.path.abspath(path))) 13 | 14 | 15 | @task 16 | def clean_build(c): 17 | """ 18 | Remove build artifacts 19 | """ 20 | c.run("rm -fr build/") 21 | c.run("rm -fr dist/") 22 | c.run("rm -fr *.egg-info") 23 | 24 | 25 | @task 26 | def clean_pyc(c): 27 | """ 28 | Remove python file artifacts 29 | """ 30 | c.run("find . -name '*.pyc' -exec rm -f {} +") 31 | c.run("find . -name '*.pyo' -exec rm -f {} +") 32 | c.run("find . -name '*~' -exec rm -f {} +") 33 | 34 | 35 | @task 36 | def coverage(c): 37 | """ 38 | check code coverage quickly with the default Python 39 | """ 40 | c.run("coverage run --source django-serverless-cron runtests.py tests") 41 | c.run("coverage report -m") 42 | c.run("coverage html") 43 | c.run("open htmlcov/index.html") 44 | 45 | 46 | @task 47 | def docs(c): 48 | """ 49 | Build the documentation and open it in the browser 50 | """ 51 | c.run("rm -f docs/django-serverless-cron.rst") 52 | c.run("rm -f docs/modules.rst") 53 | c.run("sphinx-apidoc -o docs/ django_serverless_cron") 54 | 55 | c.run("sphinx-build -E -b html docs docs/_build") 56 | open_browser(path='docs/_build/html/index.html') 57 | 58 | 59 | @task 60 | def test_all(c): 61 | """ 62 | Run tests on every python version with tox 63 | """ 64 | c.run("tox") 65 | 66 | 67 | @task 68 | def clean(c): 69 | """ 70 | Remove python file and build artifacts 71 | """ 72 | clean_build(c) 73 | clean_pyc(c) 74 | 75 | 76 | @task 77 | def unittest(c): 78 | """ 79 | Run unittests 80 | """ 81 | c.run("python manage.py test") 82 | 83 | 84 | @task 85 | def lint(c): 86 | """ 87 | Check style with flake8 88 | """ 89 | c.run("flake8 django-serverless-cron tests") 90 | 91 | 92 | @task(help={'bumpsize': 'Bump either for a "feature" or "breaking" change'}) 93 | def release(c, bumpsize=''): 94 | """ 95 | Package and upload a release 96 | """ 97 | clean(c) 98 | if bumpsize: 99 | bumpsize = '--' + bumpsize 100 | 101 | c.run("bumpversion {bump} --no-input".format(bump=bumpsize)) 102 | 103 | import django_serverless_cron 104 | c.run("python setup.py sdist bdist_wheel") 105 | c.run("twine upload dist/*") 106 | 107 | c.run('git tag -a {version} -m "New version: {version}"'.format(version=django_serverless_cron.__version__)) 108 | c.run("git push --tags") 109 | c.run("git push origin master") 110 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | ## Example Project for django_serverless_cron 2 | 3 | This example is provided as a convenience feature to allow potential users to try the app straight from the app repo without having to create a django project. 4 | 5 | It can also be used to develop the app in place. 6 | 7 | To run this example, follow these instructions: 8 | 9 | 1. Navigate to the root directory of your application (same as `manage.py`) 10 | 2. Install the requirements for the package: 11 | 12 | pip install -r requirements.txt 13 | 14 | 3. Make and apply migrations 15 | 16 | python manage.py makemigrations 17 | 18 | python manage.py migrate 19 | 20 | 4. Run the server 21 | 22 | python manage.py runserver 23 | 24 | 5. Access from the browser at `http://127.0.0.1:8000` 25 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paulonteri/django-serverless-cron/b52c625b7187756bb3ca1b63b7c992cc7988f304/tests/__init__.py -------------------------------------------------------------------------------- /tests/example/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paulonteri/django-serverless-cron/b52c625b7187756bb3ca1b63b7c992cc7988f304/tests/example/__init__.py -------------------------------------------------------------------------------- /tests/example/jobs.py: -------------------------------------------------------------------------------- 1 | def example_job_1(): 2 | pass 3 | 4 | 5 | def example_job_2(): 6 | pass 7 | 8 | 9 | def example_job_with_exception(exception_str="Job with exception"): 10 | raise Exception(exception_str) 11 | -------------------------------------------------------------------------------- /tests/example/urls.py: -------------------------------------------------------------------------------- 1 | """example URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import re_path, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.urls import re_path, include 17 | from django.contrib import admin 18 | 19 | 20 | urlpatterns = [ 21 | re_path(r'^admin/', admin.site.urls), 22 | re_path(r'', include('django_serverless_cron.urls', namespace='django_serverless_cron')), 23 | ] 24 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | # Your app requirements. 2 | -r ../requirements_test.txt 3 | 4 | # Your app in editable mode. 5 | -e ../ 6 | -------------------------------------------------------------------------------- /tests/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for example project. 3 | 4 | Generated by Cookiecutter Django Package 5 | """ 6 | 7 | import os 8 | 9 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 10 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 11 | 12 | # Quick-start development settings - unsuitable for production 13 | # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ 14 | 15 | # SECURITY WARNING: keep the secret key used in production secret! 16 | SECRET_KEY = "5lqzb5hw#mm-cos6so3@7x=%(x5jj_3phhy)t^=+ws44z$jq0^" 17 | 18 | # SECURITY WARNING: don't run with debug turned on in production! 19 | DEBUG = True 20 | 21 | ALLOWED_HOSTS = [] 22 | 23 | # Application definition 24 | 25 | INSTALLED_APPS = [ 26 | 'django.contrib.admin', 27 | 'django.contrib.auth', 28 | 'django.contrib.contenttypes', 29 | 'django.contrib.sessions', 30 | 'django.contrib.messages', 31 | 'django.contrib.staticfiles', 32 | 33 | 'django_serverless_cron', 34 | 35 | 36 | # if your app has other dependencies that need to be added to the site 37 | # they should be added here 38 | ] 39 | 40 | MIDDLEWARE = [ 41 | 'django.middleware.security.SecurityMiddleware', 42 | 'django.contrib.sessions.middleware.SessionMiddleware', 43 | 'django.middleware.common.CommonMiddleware', 44 | 'django.middleware.csrf.CsrfViewMiddleware', 45 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 46 | 'django.contrib.messages.middleware.MessageMiddleware', 47 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 48 | ] 49 | 50 | ROOT_URLCONF = 'tests.urls' 51 | 52 | TEMPLATES = [ 53 | { 54 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 55 | 'DIRS': [os.path.join(BASE_DIR, 'templates'), ], 56 | 'APP_DIRS': True, 57 | 'OPTIONS': { 58 | 'context_processors': [ 59 | 'django.template.context_processors.debug', 60 | 'django.template.context_processors.request', 61 | 'django.contrib.auth.context_processors.auth', 62 | 'django.contrib.messages.context_processors.messages', 63 | ], 64 | }, 65 | }, 66 | ] 67 | 68 | WSGI_APPLICATION = 'tests.wsgi.application' 69 | 70 | # Database 71 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases 72 | 73 | DATABASES = { 74 | 'default': { 75 | 'ENGINE': 'django.db.backends.sqlite3', 76 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 77 | } 78 | } 79 | 80 | # Password validation 81 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators 82 | 83 | AUTH_PASSWORD_VALIDATORS = [ 84 | { 85 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 86 | }, 87 | { 88 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 89 | }, 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 95 | }, 96 | ] 97 | 98 | # Internationalization 99 | # https://docs.djangoproject.com/en/1.9/topics/i18n/ 100 | 101 | LANGUAGE_CODE = 'en-us' 102 | 103 | TIME_ZONE = 'UTC' 104 | 105 | USE_I18N = True 106 | 107 | USE_L10N = True 108 | 109 | USE_TZ = True 110 | 111 | # Static files (CSS, JavaScript, Images) 112 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ 113 | 114 | STATIC_URL = '/static/' 115 | 116 | 117 | IS_IN_DEV_TESTING = True 118 | -------------------------------------------------------------------------------- /tests/test_admin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_django_serverless_cron 6 | ------------ 7 | 8 | Tests for `django_serverless_cron` admin module. 9 | """ 10 | 11 | from django.test import TestCase 12 | from django.utils import timezone 13 | 14 | from django_serverless_cron.admin import run_selected_jobs 15 | from django_serverless_cron.models import JobRun 16 | 17 | 18 | class TestAdminRunSelectedJobs(TestCase): 19 | 20 | def test_run_selected_jobs_runs_jobs(self): 21 | # create fake job runs 22 | JobRun.objects.create( 23 | function_path='tests.example.jobs.example_job_1', 24 | kwargs={}, 25 | frequency='1_second', 26 | time_finished_running=timezone.now() 27 | ) 28 | JobRun.objects.create( 29 | function_path='tests.example.jobs.example_job_2', 30 | kwargs={}, 31 | frequency='1_second', 32 | time_finished_running=timezone.now() 33 | ) 34 | self.assertEqual(JobRun.objects.all().count(), 2) 35 | # run jobs 36 | run_selected_jobs(None, None, JobRun.objects.all()) 37 | # check if the jobs ran 38 | self.assertEqual(JobRun.objects.all().count(), 4) 39 | -------------------------------------------------------------------------------- /tests/test_management_commands.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_django_serverless_cron 6 | ------------ 7 | 8 | Tests for `django_serverless_cron` management commands. 9 | """ 10 | 11 | from django.test import TestCase 12 | from django.test.utils import override_settings 13 | 14 | from django_serverless_cron.management.commands.serverless_cron_run import \ 15 | Command 16 | from django_serverless_cron.models import JobRun 17 | 18 | 19 | class TestCommandServerlessCronRun(TestCase): 20 | 21 | @override_settings(SERVERLESS_CRONJOBS=[ 22 | ('5_minutes', 'tests.example.jobs.example_job_1', {}), 23 | ('1_minutes', 'tests.example.jobs.example_job_2', {}), 24 | ('5_minutes', 'tests.example.jobs.example_job_2', {}), 25 | ]) 26 | def test_serverless_cron_run_command_handle(self): 27 | self.assertEqual(JobRun.objects.all().count(), 0) 28 | command = Command() 29 | command.handle(single_run=False) 30 | self.assertEqual(JobRun.objects.all().count(), 3) 31 | 32 | @override_settings(SERVERLESS_CRONJOBS=[ 33 | ('5_minutes', 'tests.example.jobs.example_job_1', {}), 34 | ('1_minutes', 'tests.example.jobs.example_job_2', {}), 35 | ('5_minutes', 'tests.example.jobs.example_job_2', {}), 36 | ]) 37 | def test_serverless_cron_run_command_handle_single_run(self): 38 | self.assertEqual(JobRun.objects.all().count(), 0) 39 | command = Command() 40 | command.handle(single_run=True) 41 | self.assertEqual(JobRun.objects.all().count(), 3) 42 | -------------------------------------------------------------------------------- /tests/test_models.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_django_serverless_cron 6 | ------------ 7 | 8 | Tests for `django_serverless_cron` models module. 9 | """ 10 | 11 | from django.test import TestCase 12 | 13 | from django_serverless_cron.models import JobRun 14 | 15 | 16 | class TestJobRun(TestCase): 17 | 18 | def test_the__str___method(self): 19 | function_path = 'tests.example.jobs.example_job_1' 20 | kwargs = {'foo': 'bar'} 21 | frequency = '1_second' 22 | 23 | job_run = JobRun.objects.create( 24 | function_path=function_path, 25 | kwargs=kwargs, 26 | frequency=frequency, 27 | ) 28 | 29 | self.assertEqual( 30 | f"{function_path} {str(kwargs)} {frequency}", 31 | job_run.__str__() 32 | ) 33 | -------------------------------------------------------------------------------- /tests/test_services.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_django_serverless_cron 6 | ------------ 7 | 8 | Tests for `django_serverless_cron` services module. 9 | """ 10 | 11 | from django.test import TestCase 12 | from django.test.utils import override_settings 13 | 14 | from django_serverless_cron.models import JobRun 15 | from django_serverless_cron.services import Job, RunJobs 16 | 17 | 18 | class TestJobs(TestCase): 19 | 20 | def test_run_job_runs_job(self): 21 | self.assertEqual(JobRun.objects.all().count(), 0) 22 | job_one = Job(frequency="1_minutes", function_path='tests.example.jobs.example_job_1', kwargs={}) 23 | job_one.run() 24 | self.assertEqual(JobRun.objects.all().count(), 1) 25 | 26 | def test_run_job_handles_exception(self): 27 | # run job 28 | exception_str = "Job with exception" 29 | job_one = Job( 30 | frequency="1_minutes", 31 | function_path='tests.example.jobs.example_job_with_exception', 32 | kwargs={"exception_str": exception_str} 33 | ) 34 | job_one.run() 35 | # check job handled and saved the exception 36 | job = JobRun.objects.all().last() 37 | self.assertEqual(job.error, exception_str) 38 | 39 | def test_run_skips_jobs_not_valid_to_run(self): 40 | # run job 41 | job_one = Job(frequency="1_days", function_path='tests.example.jobs.example_job_1', kwargs={}) 42 | job_one.run() 43 | self.assertEqual(JobRun.objects.all().count(), 1) 44 | # ensure the jobs didn't run again 45 | job_one.run() 46 | self.assertEqual(JobRun.objects.all().count(), 1) 47 | 48 | def test_is_valid_time_for_job_to_run_works(self): 49 | job_one = Job(frequency="1_minutes", function_path='tests.example.jobs.example_job_1', kwargs={}) 50 | self.assertTrue(job_one._is_valid_time_for_job_to_run()) 51 | job_one.run() 52 | self.assertFalse(job_one._is_valid_time_for_job_to_run()) 53 | 54 | 55 | class TestRunAllJobs(TestCase): 56 | 57 | @override_settings(SERVERLESS_CRONJOBS=[ 58 | ('5_minutes', 'tests.example.jobs.example_job_1', {}), 59 | ('1_minutes', 'tests.example.jobs.example_job_1', {}), 60 | ]) 61 | def test_run_all_jobs_runs_jobs(self): 62 | self.assertEqual(JobRun.objects.all().count(), 0) 63 | RunJobs.run_all_jobs() 64 | self.assertEqual(JobRun.objects.all().count(), 2) 65 | -------------------------------------------------------------------------------- /tests/test_utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_django_serverless_cron 6 | ------------ 7 | 8 | Tests for `django_serverless_cron` utils module. 9 | """ 10 | 11 | from django.test import TestCase 12 | 13 | from django_serverless_cron.utils import run_function_from_path 14 | 15 | 16 | def function_that_returns_true(**kwargs): 17 | """Function that is used to test the run_function_from_path function""" 18 | return True 19 | 20 | 21 | class TestRunFunctionFromPath(TestCase): 22 | 23 | def test_run_function_from_path_runs_function(self): 24 | result = run_function_from_path('tests.test_utils.function_that_returns_true', {}) 25 | self.assertTrue(result) 26 | -------------------------------------------------------------------------------- /tests/test_views.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | test_django_serverless_cron 6 | ------------ 7 | 8 | Tests for `django_serverless_cron` views module. 9 | """ 10 | 11 | from django.test import TestCase 12 | from django.test.utils import override_settings 13 | from django.urls import reverse 14 | 15 | from django_serverless_cron.models import JobRun 16 | 17 | 18 | class TestRunJobsView(TestCase): 19 | 20 | @override_settings(SERVERLESS_CRONJOBS=[ 21 | ('5_minutes', 'tests.example.jobs.example_job_1', {}), 22 | ('1_minutes', 'tests.example.jobs.example_job_1', {}), 23 | ]) 24 | def test_run_jobs_view_runs_jobs(self): 25 | self.assertEqual(JobRun.objects.all().count(), 0) 26 | url = reverse("django_serverless_cron:django-serverless-cron-run-jobs") 27 | 28 | response = self.client.get(url) 29 | self.assertEqual(response.status_code, 200) 30 | self.assertEqual(JobRun.objects.all().count(), 2) 31 | -------------------------------------------------------------------------------- /tests/urls.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals, absolute_import 3 | 4 | from django.urls import re_path, include 5 | from django.contrib import admin 6 | 7 | urlpatterns = [ 8 | re_path(r'^admin/', admin.site.urls), 9 | re_path(r'^', include('django_serverless_cron.urls', namespace='django_serverless_cron')), 10 | ] 11 | -------------------------------------------------------------------------------- /tests/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for example project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | django31-py{python3.6,python3.7,python3.8,python3.9} 4 | django32-py{python3.6,python3.7,python3.8,python3.9,3.10} 5 | ; django40-py{python3.8,python3.9,3.10} 6 | 7 | [testenv] 8 | setenv = 9 | PYTHONPATH = {toxinidir}:{toxinidir}/django_serverless_cron 10 | commands = coverage run --source django_serverless_cron runtests.py 11 | deps = 12 | django31: {[django]3.1} 13 | django32: {[django]3.2} 14 | django40: {[django]4.0} 15 | -r{toxinidir}/requirements_test.txt 16 | 17 | [django] 18 | 3.1 = 19 | Django>=3.1.0,<3.1.14 20 | 3.2 = 21 | Django>=3.2.0,<3.2.11 22 | 4.0 = 23 | Django>=4.0.0,<4.0.1 24 | --------------------------------------------------------------------------------