Metadata-Version: 2.1
Name: django-serverless-cron
Version: 0.1.1a7
Summary: Django Serverless Cron
Home-page: https://github.com/paulonteri/django-serverless-cron
Author: Paul Onteri
Author-email: me@paulonteri.com
License: MIT
Keywords: django-serverless-cron
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
License-File: LICENSE
License-File: AUTHORS.rst
Requires-Dist: coverage (==4.4.1)

=============================
django-serverless-cron
=============================

.. image:: https://badge.fury.io/py/django-serverless-cron.svg
    :target: https://badge.fury.io/py/django-serverless-cron

.. image:: https://github.com/paulonteri/django-serverless-cron/actions/workflows/tests.yml/badge.svg
    :target: https://github.com/paulonteri/django-serverless-cron/actions/workflows/tests.yml

.. image:: https://codecov.io/gh/paulonteri/django-serverless-cron/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/paulonteri/django-serverless-cron

.. image:: https://readthedocs.org/projects/django-serverless-cron/badge/?version=latest
     :target: http://django-serverless-cron.readthedocs.io/?badge=latest

django-serverless-cron is a Django app with a simpler approach running cron jobs (mostly in a serverless environment) through HTTP requests with an integration with the Django admin. This allows you to run any task without having to manage always-on infrastructure.

There is also an option to run jobs via management commands and the Django admin.

Documentation
-------------

Documentation is graciously hosted at https://django-serverless-cron.readthedocs.io.

Quickstart
----------

Installation
^^^^^^^^^^^^

Install Django Serverless Cron::

    pip install django-serverless-cron


Settings
^^^^^^^^

Add it to your `INSTALLED_APPS`:

.. code-block:: python

    INSTALLED_APPS = (
        # ...
        'django_serverless_cron'
        # ...
    )

Add jobs to your settings file:

.. code-block:: python

    CRONJOBS = [
        # (
        #   '1_hours',                       # frequency (days, minutes, hours, weeks) -> in this case, every one hour
        #   'mail.jobs.send_mail_function',  # path to task/function functions -> in this case, send_mail_function()
        #   {'kwarg1': 'foo'}                # kwargs passed to the function
        # ),
        (
            '1_day',
            'your_app.services.your_job_function',
            {'kwarg1': 'foo', 'kwarg2': 'bar'}
        ),
        (
            '1_hour',
            'mail.jobs.send_mail_function',
            {"is_bulk": True}
        ),
    ]


URL patterns
^^^^^^^^^^^^
Add the jobs to your URL patterns:

.. code-block:: python

    from django_serverless_cron import urls as django_serverless_cron_urls


    urlpatterns = [
        # ...
        url(r'^', include(django_serverless_cron_urls))
        #...
    ]

Running Jobs
------------

In Development
^^^^^^^^^^^^^^

Running Jobs through HTTP requests
"""""""""""""""""""""""""""""""""""

Call the `/run` path to run all jobs:

Example:

.. code-block:: bash

    curl http://localhost:8000/run

or

.. code-block:: python

    import requests

    x = requests.get('http://localhost:8000/run')

In Production
^^^^^^^^^^^^^

Similar to in development, we can call the `/run` path via managed services which are usually ridiculously cheap. Examples:

- https://cron-job.org
- https://cloud.google.com/scheduler
- https://www.easycron.com
- https://cronhub.io


Tests
-------------

Does the code actually work?

::

    source <YOURVIRTUALENV>/bin/activate
    (myenv) $ pip install tox
    (myenv) $ tox


Development commands
---------------------

::

    pip install -r requirements_dev.txt
    invoke -l


Related
-------

- https://dev.to/googlecloud/when-you-re-not-around-trigger-cloud-run-on-a-schedule-53p4


Credits
-------

Tools used in rendering this package:

*  Cookiecutter_
*  `cookiecutter-djangopackage`_

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage





