Skip to content

Commit

Permalink
!feat:queue choicefield as callable (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Jun 29, 2024
1 parent 04199ed commit d37c8b2
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
cache-dependency-path: poetry.lock

- name: Install dependencies
Expand Down
72 changes: 29 additions & 43 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,29 @@ jobs:
name: "flake8 on code"
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5

- name: "Setup Python, Poetry and Dependencies"
uses: dsoftwareinc/setup-python-poetry-action@v1
with:
python-version: "3.11"
cache-dependency-path: poetry.lock
- name: Install poetry and dependencies
shell: bash
run: |
python -m pip --quiet install poetry
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
poetry install
python-version: "3.12"
poetry-version: "1.8.3"

- name: Run flake8
shell: bash
run: |
poetry run flake8 scheduler/
poetry run flake8
testRedis:
needs: [ 'flake8' ]
runs-on: ubuntu-latest
strategy:
max-parallel: 6
matrix:
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
django-version: [ '4.2.13', '5.0.6' ]
exclude:
- python-version: '3.9'
django-version: '5.0.6'
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
django-version: [ '5.0.6', '5.1b1' ]
include:
- python-version: '3.11'
django-version: '4.2.13'
- python-version: '3.12'
django-version: '5.0.6'
coverage: yes
services:
redis:
Expand All @@ -60,12 +53,15 @@ jobs:
version: ${{ steps.getVersion.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- name: "Setup Python, Poetry and Dependencies"
uses: dsoftwareinc/setup-python-poetry-action@v1
with:
python-version: ${{ matrix.python-version }}
cache-dependency-path: poetry.lock
- name: Install poetry and dependencies
python-version: "${{ matrix.python-version }}"
poetry-version: "1.8.3"
poetry-install-additional-args: "-E yaml"

- name: Install django version
shell: bash
run: |
python -m pip --quiet install poetry
Expand All @@ -79,6 +75,7 @@ jobs:
run: |
VERSION=$(poetry version -s --no-ansi -n)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Check for missing migrations
run: |
cd testproject
Expand Down Expand Up @@ -130,32 +127,20 @@ jobs:
strategy:
max-parallel: 6
matrix:
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
django-version: [ '4.2.13', '5.0.6' ]
exclude:
- python-version: '3.9'
django-version: '5.0.6'
include:
- python-version: '3.11'
django-version: '4.2.13'
coverage: yes
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
django-version: [ '5.0.6', '5.1b1' ]

outputs:
version: ${{ steps.getVersion.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- name: "Setup Python, Poetry and Dependencies"
uses: dsoftwareinc/setup-python-poetry-action@v1
with:
python-version: ${{ matrix.python-version }}
cache-dependency-path: poetry.lock
- name: Install poetry and dependencies
shell: bash
run: |
python -m pip --quiet install poetry
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
poetry install -E yaml
poetry run pip install django==${{ matrix.django-version }}
python-version: "${{ matrix.python-version }}"
poetry-version: "1.8.3"
poetry-install-additional-args: "-E yaml"

- name: Get version
id: getVersion
Expand All @@ -167,6 +152,7 @@ jobs:
run: |
cd testproject
poetry run python manage.py makemigrations --check
- name: Run Tests without coverage
run: |
cd testproject
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v2.0.0 🌈

### Breaking Changes

- Remove support for django 3.* and 4.*. Only support django 5.0 and above.

## v1.3.4 🌈

### 🧰 Maintenance
Expand Down
15 changes: 7 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "django-tasks-scheduler"
packages = [
{ include = "scheduler" },
]
version = "1.3.4"
version = "2.0.0"
description = "An async job scheduler for django using redis"
readme = "README.md"
keywords = ["redis", "django", "background-jobs", "job-queue", "task-queue", "redis-queue", "scheduled-jobs"]
Expand All @@ -25,18 +25,13 @@ classifiers = [
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Framework :: Django',
'Framework :: Django :: 5.0',
'Framework :: Django :: 4',
'Framework :: Django :: 4.0',
'Framework :: Django :: 4.1',
'Framework :: Django :: 4.2',
'Framework :: Django :: 3',
'Framework :: Django :: 3.2',
'Framework :: Django :: 5.1',
]
homepage = "https://github.com/dsoftwareinc/django-tasks-scheduler"
documentation = "https://django-tasks-scheduler.readthedocs.io/en/latest/"
Expand All @@ -46,8 +41,8 @@ documentation = "https://django-tasks-scheduler.readthedocs.io/en/latest/"
"Funding" = "https://github.com/sponsors/cunla"

[tool.poetry.dependencies]
python = "^3.9"
django = ">=3.2"
python = "^3.10"
django = ">=5.0"
croniter = "^2.0"
click = "^8.1"
rq = "^1.16"
Expand All @@ -69,7 +64,11 @@ yaml = ["pyyaml"]
max-line-length = 119
exclude = [
'scheduler/migrations',
'testproject',
'.venv',
'.github',
'__pycache',
]
include = [
'scheduler',
]
5 changes: 1 addition & 4 deletions scheduler/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ class SchedulerConfig(AppConfig):
verbose_name = _('Tasks Scheduler')

def ready(self):
from scheduler.models import BaseTask
from scheduler.settings import QUEUES

BaseTask.QUEUES = [(queue, queue) for queue in QUEUES.keys()]
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.1b1 on 2024-06-29 14:21

import scheduler.models.scheduled_task
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scheduler', '0017_remove_crontask_repeat_crontask_failed_runs_and_more'),
]

operations = [
migrations.AlterField(
model_name='crontask',
name='queue',
field=models.CharField(choices=scheduler.models.scheduled_task.get_queue_choices, help_text='Queue name', max_length=255, verbose_name='queue'),
),
migrations.AlterField(
model_name='repeatabletask',
name='queue',
field=models.CharField(choices=scheduler.models.scheduled_task.get_queue_choices, help_text='Queue name', max_length=255, verbose_name='queue'),
),
migrations.AlterField(
model_name='scheduledtask',
name='queue',
field=models.CharField(choices=scheduler.models.scheduled_task.get_queue_choices, help_text='Queue name', max_length=255, verbose_name='queue'),
),
]
8 changes: 6 additions & 2 deletions scheduler/models/scheduled_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from scheduler.models.args import TaskArg, TaskKwarg
from scheduler.queues import get_queue
from scheduler.rq_classes import DjangoQueue
from scheduler.settings import QUEUES
from scheduler.settings import logger

SCHEDULER_INTERVAL = settings.SCHEDULER_CONFIG['SCHEDULER_INTERVAL']
Expand Down Expand Up @@ -60,10 +61,13 @@ def success_callback(job, connection, result, *args, **kwargs):
task.save(schedule_job=True)


def get_queue_choices():
return [(queue, queue) for queue in QUEUES.keys()]


class BaseTask(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
QUEUES = [("default", "default"), ("low", "low"), ("high", "high")]
TASK_TYPE = 'BaseTask'
name = models.CharField(
_('name'), max_length=128, unique=True,
Expand All @@ -77,7 +81,7 @@ class BaseTask(models.Model):
'past jobs that should no longer be scheduled'),
)
queue = models.CharField(
_('queue'), max_length=255, choices=QUEUES,
_('queue'), max_length=255, choices=get_queue_choices,
help_text=_('Queue name'), )
job_id = models.CharField(
_('job id'), max_length=128, editable=False, blank=True, null=True,
Expand Down
3 changes: 3 additions & 0 deletions testproject/testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
'medium': {
'URL': 'redis://localhost:6379/1',
},
'another': {
'URL': 'redis://localhost:6379/1',
},
}
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Expand Down

0 comments on commit d37c8b2

Please sign in to comment.