Skip to content

Commit d37c8b2

Browse files
committed
!feat:queue choicefield as callable (#134)
1 parent 04199ed commit d37c8b2

File tree

10 files changed

+93
-69
lines changed

10 files changed

+93
-69
lines changed

.github/workflows/publish-documentation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Python
2121
uses: actions/setup-python@v5
2222
with:
23-
python-version: "3.11"
23+
python-version: "3.12"
2424
- name: Configure Git Credentials
2525
run: |
2626
git config user.name github-actions[bot]

.github/workflows/publish.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v4
23+
2324
- name: Set up Python
2425
uses: actions/setup-python@v5
2526
with:
26-
python-version: '3.11'
27+
python-version: '3.12'
2728
cache-dependency-path: poetry.lock
2829

2930
- name: Install dependencies

.github/workflows/test.yml

+29-43
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,29 @@ jobs:
1515
name: "flake8 on code"
1616
steps:
1717
- uses: actions/checkout@v4
18-
- name: Setup Python
19-
uses: actions/setup-python@v5
18+
19+
- name: "Setup Python, Poetry and Dependencies"
20+
uses: dsoftwareinc/setup-python-poetry-action@v1
2021
with:
21-
python-version: "3.11"
22-
cache-dependency-path: poetry.lock
23-
- name: Install poetry and dependencies
24-
shell: bash
25-
run: |
26-
python -m pip --quiet install poetry
27-
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
28-
poetry install
22+
python-version: "3.12"
23+
poetry-version: "1.8.3"
24+
2925
- name: Run flake8
3026
shell: bash
3127
run: |
32-
poetry run flake8 scheduler/
28+
poetry run flake8
3329
3430
testRedis:
3531
needs: [ 'flake8' ]
3632
runs-on: ubuntu-latest
3733
strategy:
3834
max-parallel: 6
3935
matrix:
40-
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
41-
django-version: [ '4.2.13', '5.0.6' ]
42-
exclude:
43-
- python-version: '3.9'
44-
django-version: '5.0.6'
36+
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
37+
django-version: [ '5.0.6', '5.1b1' ]
4538
include:
46-
- python-version: '3.11'
47-
django-version: '4.2.13'
39+
- python-version: '3.12'
40+
django-version: '5.0.6'
4841
coverage: yes
4942
services:
5043
redis:
@@ -60,12 +53,15 @@ jobs:
6053
version: ${{ steps.getVersion.outputs.VERSION }}
6154
steps:
6255
- uses: actions/checkout@v4
63-
- name: Set up Python ${{ matrix.python-version }}
64-
uses: actions/setup-python@v5
56+
57+
- name: "Setup Python, Poetry and Dependencies"
58+
uses: dsoftwareinc/setup-python-poetry-action@v1
6559
with:
66-
python-version: ${{ matrix.python-version }}
67-
cache-dependency-path: poetry.lock
68-
- name: Install poetry and dependencies
60+
python-version: "${{ matrix.python-version }}"
61+
poetry-version: "1.8.3"
62+
poetry-install-additional-args: "-E yaml"
63+
64+
- name: Install django version
6965
shell: bash
7066
run: |
7167
python -m pip --quiet install poetry
@@ -79,6 +75,7 @@ jobs:
7975
run: |
8076
VERSION=$(poetry version -s --no-ansi -n)
8177
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
78+
8279
- name: Check for missing migrations
8380
run: |
8481
cd testproject
@@ -130,32 +127,20 @@ jobs:
130127
strategy:
131128
max-parallel: 6
132129
matrix:
133-
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
134-
django-version: [ '4.2.13', '5.0.6' ]
135-
exclude:
136-
- python-version: '3.9'
137-
django-version: '5.0.6'
138-
include:
139-
- python-version: '3.11'
140-
django-version: '4.2.13'
141-
coverage: yes
130+
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
131+
django-version: [ '5.0.6', '5.1b1' ]
142132

143133
outputs:
144134
version: ${{ steps.getVersion.outputs.VERSION }}
145135
steps:
146136
- uses: actions/checkout@v4
147-
- name: Set up Python ${{ matrix.python-version }}
148-
uses: actions/setup-python@v5
137+
138+
- name: "Setup Python, Poetry and Dependencies"
139+
uses: dsoftwareinc/setup-python-poetry-action@v1
149140
with:
150-
python-version: ${{ matrix.python-version }}
151-
cache-dependency-path: poetry.lock
152-
- name: Install poetry and dependencies
153-
shell: bash
154-
run: |
155-
python -m pip --quiet install poetry
156-
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
157-
poetry install -E yaml
158-
poetry run pip install django==${{ matrix.django-version }}
141+
python-version: "${{ matrix.python-version }}"
142+
poetry-version: "1.8.3"
143+
poetry-install-additional-args: "-E yaml"
159144

160145
- name: Get version
161146
id: getVersion
@@ -167,6 +152,7 @@ jobs:
167152
run: |
168153
cd testproject
169154
poetry run python manage.py makemigrations --check
155+
170156
- name: Run Tests without coverage
171157
run: |
172158
cd testproject

docs/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v2.0.0 🌈
4+
5+
### Breaking Changes
6+
7+
- Remove support for django 3.* and 4.*. Only support django 5.0 and above.
8+
39
## v1.3.4 🌈
410

511
### 🧰 Maintenance

poetry.lock

+7-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+9-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "django-tasks-scheduler"
77
packages = [
88
{ include = "scheduler" },
99
]
10-
version = "1.3.4"
10+
version = "2.0.0"
1111
description = "An async job scheduler for django using redis"
1212
readme = "README.md"
1313
keywords = ["redis", "django", "background-jobs", "job-queue", "task-queue", "redis-queue", "scheduled-jobs"]
@@ -25,18 +25,13 @@ classifiers = [
2525
'License :: OSI Approved :: MIT License',
2626
'Operating System :: OS Independent',
2727
'Programming Language :: Python',
28-
'Programming Language :: Python :: 3.9',
2928
'Programming Language :: Python :: 3.10',
3029
'Programming Language :: Python :: 3.11',
3130
'Programming Language :: Python :: 3.12',
31+
'Programming Language :: Python :: 3.13',
3232
'Framework :: Django',
3333
'Framework :: Django :: 5.0',
34-
'Framework :: Django :: 4',
35-
'Framework :: Django :: 4.0',
36-
'Framework :: Django :: 4.1',
37-
'Framework :: Django :: 4.2',
38-
'Framework :: Django :: 3',
39-
'Framework :: Django :: 3.2',
34+
'Framework :: Django :: 5.1',
4035
]
4136
homepage = "https://github.com/dsoftwareinc/django-tasks-scheduler"
4237
documentation = "https://django-tasks-scheduler.readthedocs.io/en/latest/"
@@ -46,8 +41,8 @@ documentation = "https://django-tasks-scheduler.readthedocs.io/en/latest/"
4641
"Funding" = "https://github.com/sponsors/cunla"
4742

4843
[tool.poetry.dependencies]
49-
python = "^3.9"
50-
django = ">=3.2"
44+
python = "^3.10"
45+
django = ">=5.0"
5146
croniter = "^2.0"
5247
click = "^8.1"
5348
rq = "^1.16"
@@ -69,7 +64,11 @@ yaml = ["pyyaml"]
6964
max-line-length = 119
7065
exclude = [
7166
'scheduler/migrations',
67+
'testproject',
7268
'.venv',
7369
'.github',
7470
'__pycache',
7571
]
72+
include = [
73+
'scheduler',
74+
]

scheduler/apps.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,4 @@ class SchedulerConfig(AppConfig):
88
verbose_name = _('Tasks Scheduler')
99

1010
def ready(self):
11-
from scheduler.models import BaseTask
12-
from scheduler.settings import QUEUES
13-
14-
BaseTask.QUEUES = [(queue, queue) for queue in QUEUES.keys()]
11+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 5.1b1 on 2024-06-29 14:21
2+
3+
import scheduler.models.scheduled_task
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('scheduler', '0017_remove_crontask_repeat_crontask_failed_runs_and_more'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='crontask',
16+
name='queue',
17+
field=models.CharField(choices=scheduler.models.scheduled_task.get_queue_choices, help_text='Queue name', max_length=255, verbose_name='queue'),
18+
),
19+
migrations.AlterField(
20+
model_name='repeatabletask',
21+
name='queue',
22+
field=models.CharField(choices=scheduler.models.scheduled_task.get_queue_choices, help_text='Queue name', max_length=255, verbose_name='queue'),
23+
),
24+
migrations.AlterField(
25+
model_name='scheduledtask',
26+
name='queue',
27+
field=models.CharField(choices=scheduler.models.scheduled_task.get_queue_choices, help_text='Queue name', max_length=255, verbose_name='queue'),
28+
),
29+
]

scheduler/models/scheduled_task.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from scheduler.models.args import TaskArg, TaskKwarg
2323
from scheduler.queues import get_queue
2424
from scheduler.rq_classes import DjangoQueue
25+
from scheduler.settings import QUEUES
2526
from scheduler.settings import logger
2627

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

6263

64+
def get_queue_choices():
65+
return [(queue, queue) for queue in QUEUES.keys()]
66+
67+
6368
class BaseTask(models.Model):
6469
created = models.DateTimeField(auto_now_add=True)
6570
modified = models.DateTimeField(auto_now=True)
66-
QUEUES = [("default", "default"), ("low", "low"), ("high", "high")]
6771
TASK_TYPE = 'BaseTask'
6872
name = models.CharField(
6973
_('name'), max_length=128, unique=True,
@@ -77,7 +81,7 @@ class BaseTask(models.Model):
7781
'past jobs that should no longer be scheduled'),
7882
)
7983
queue = models.CharField(
80-
_('queue'), max_length=255, choices=QUEUES,
84+
_('queue'), max_length=255, choices=get_queue_choices,
8185
help_text=_('Queue name'), )
8286
job_id = models.CharField(
8387
_('job id'), max_length=128, editable=False, blank=True, null=True,

testproject/testproject/settings.py

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@
127127
'medium': {
128128
'URL': 'redis://localhost:6379/1',
129129
},
130+
'another': {
131+
'URL': 'redis://localhost:6379/1',
132+
},
130133
}
131134
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
132135

0 commit comments

Comments
 (0)