Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Spacing changes for docs project #56

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 75 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ A Django app to register periodic Django Q tasks.

1. Install the package from PyPI:

```bash
python -m pip install django-q-registry
```
```bash
python -m pip install django-q-registry
```

2. Add the app to your Django project's `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
...,
"django_q_registry",
...,
]
```
```python
INSTALLED_APPS = [
...,
"django_q_registry",
...,
]
```

## Getting Started

Expand All @@ -42,77 +42,77 @@ There are three supported ways to register periodic tasks:

1. In a `tasks.py` file in a Django app, using the `@register_task` decorator:

```python
# tasks.py
from django.core.mail import send_mail
from django_q.models import Schedule
from django_q_registry import register_task


@register_task(
name="Send periodic test email",
schedule_type=Schedule.CRON,
# https://crontab.guru/#*/5_*_*_*_*
cron="*/5 * * * *",
)
def send_test_email():
send_mail(
subject="Test email",
message="This is a test email.",
from_email="[email protected]",
recipient_list=["[email protected]"],
)
```
```python
# tasks.py
from django.core.mail import send_mail
from django_q.models import Schedule
from django_q_registry import register_task


@register_task(
name="Send periodic test email",
schedule_type=Schedule.CRON,
# https://crontab.guru/#*/5_*_*_*_*
cron="*/5 * * * *",
)
def send_test_email():
send_mail(
subject="Test email",
message="This is a test email.",
from_email="[email protected]",
recipient_list=["[email protected]"],
)
```

2. In a `tasks.py` file in a Django app, using the `registry.register` function directly:

```python
# tasks.py
from django.core.mail import send_mail
from django_q.models import Schedule
from django_q_registry.registry import registry


registry.register(
send_mail,
name="Send periodic test email",
kwargs={
"subject": "Test email",
"message": "This is a test email.",
"from_email": "[email protected]",
"recipient_list": ["[email protected]"],
},
schedule_type=Schedule.CRON,
# https://crontab.guru/#*/5_*_*_*_*
cron="*/5 * * * *",
)
```
```python
# tasks.py
from django.core.mail import send_mail
from django_q.models import Schedule
from django_q_registry.registry import registry


registry.register(
send_mail,
name="Send periodic test email",
kwargs={
"subject": "Test email",
"message": "This is a test email.",
"from_email": "[email protected]",
"recipient_list": ["[email protected]"],
},
schedule_type=Schedule.CRON,
# https://crontab.guru/#*/5_*_*_*_*
cron="*/5 * * * *",
)
```

3. In a Django project's `settings.py` file, using the `Q_REGISTRY["TASKS"]` setting:

```python
# settings.py
from django_q.models import Schedule


Q_REGISTRY = {
"TASKS": [
{
"name": "Send periodic test email",
"func": "django.core.mail.send_mail",
"kwargs": {
"subject": "Test email",
"message": "This is a test email.",
"from_email": "[email protected]",
"recipient_list": ["[email protected]"],
},
"schedule_type": Schedule.CRON,
# https://crontab.guru/#*/5_*_*_*_*
"cron": "*/5 * * * *",
},
],
}
```
```python
# settings.py
from django_q.models import Schedule


Q_REGISTRY = {
"TASKS": [
{
"name": "Send periodic test email",
"func": "django.core.mail.send_mail",
"kwargs": {
"subject": "Test email",
"message": "This is a test email.",
"from_email": "[email protected]",
"recipient_list": ["[email protected]"],
},
"schedule_type": Schedule.CRON,
# https://crontab.guru/#*/5_*_*_*_*
"cron": "*/5 * * * *",
},
],
}
```

### Setting up Periodic Tasks in Production

Expand Down