Skip to content

Commit ae52e3b

Browse files
committed
Remove jsonfield dependency and switch to enum choices
1 parent 40ebd81 commit ae52e3b

File tree

4 files changed

+24
-72
lines changed

4 files changed

+24
-72
lines changed
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
1+
# Generated by Django 3.2rc1 on 2021-04-05 14:31
32

4-
from django.db import models, migrations
5-
import jsonfield.fields
3+
from django.db import migrations, models
64
import uuid
75

8-
from django.db.models import UUIDField
9-
106

117
class Migration(migrations.Migration):
128

9+
initial = True
10+
1311
dependencies = []
1412

1513
operations = [
@@ -18,38 +16,39 @@ class Migration(migrations.Migration):
1816
fields=[
1917
(
2018
"id",
21-
UUIDField(
22-
serialize=False,
23-
editable=False,
19+
models.UUIDField(
2420
default=uuid.uuid4,
21+
editable=False,
2522
primary_key=True,
23+
serialize=False,
2624
),
2725
),
28-
("created", models.DateTimeField(db_index=True, auto_now_add=True)),
26+
("created", models.DateTimeField(auto_now_add=True, db_index=True)),
2927
("modified", models.DateTimeField(auto_now=True)),
3028
("name", models.CharField(max_length=100)),
3129
(
3230
"state",
3331
models.CharField(
34-
db_index=True,
35-
max_length=20,
36-
default="NEW",
3732
choices=[
38-
("NEW", "NEW"),
39-
("READY", "READY"),
40-
("PROCESSING", "PROCESSING"),
41-
("FAILED", "FAILED"),
42-
("COMPLETE", "COMPLETE"),
33+
("NEW", "New"),
34+
("READY", "Ready"),
35+
("PROCESSING", "Processing"),
36+
("FAILED", "Failed"),
37+
("COMPLETE", "Complete"),
4338
],
39+
db_index=True,
40+
default="NEW",
41+
max_length=20,
4442
),
4543
),
46-
("next_task", models.CharField(max_length=100, blank=True)),
47-
("workspace", jsonfield.fields.JSONField(null=True)),
44+
("next_task", models.CharField(blank=True, max_length=100)),
45+
("workspace", models.JSONField(null=True)),
4846
(
4947
"queue_name",
50-
models.CharField(db_index=True, max_length=20, default="default"),
48+
models.CharField(db_index=True, default="default", max_length=20),
5149
),
50+
("priority", models.SmallIntegerField(db_index=True, default=0)),
5251
],
53-
options={"ordering": ["-created"],},
52+
options={"ordering": ["-priority", "created"],},
5453
),
5554
]

django_dbq/migrations/0002_auto_20151016_1027.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

django_dbq/migrations/0003_auto_20180713_1000.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

django_dbq/models.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
get_failure_hook_name,
77
get_creation_hook_name,
88
)
9-
from jsonfield import JSONField
10-
from django.db.models import UUIDField, Count
9+
from django.db.models import JSONField, UUIDField, Count, TextChoices
1110
import datetime
1211
import logging
1312
import uuid
@@ -74,27 +73,19 @@ def to_process(self, queue_name):
7473

7574

7675
class Job(models.Model):
77-
class STATES:
76+
class STATES(TextChoices):
7877
NEW = "NEW"
7978
READY = "READY"
8079
PROCESSING = "PROCESSING"
8180
FAILED = "FAILED"
8281
COMPLETE = "COMPLETE"
8382

84-
STATE_CHOICES = [
85-
(STATES.NEW, "NEW"),
86-
(STATES.READY, "READY"),
87-
(STATES.PROCESSING, "PROCESSING"),
88-
(STATES.FAILED, "FAILED"),
89-
(STATES.COMPLETE, "COMPLETE"),
90-
]
91-
9283
id = UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
9384
created = models.DateTimeField(auto_now_add=True, db_index=True)
9485
modified = models.DateTimeField(auto_now=True)
9586
name = models.CharField(max_length=100)
9687
state = models.CharField(
97-
max_length=20, choices=STATE_CHOICES, default=STATES.NEW, db_index=True
88+
max_length=20, choices=STATES.choices, default=STATES.NEW, db_index=True
9889
)
9990
next_task = models.CharField(max_length=100, blank=True)
10091
workspace = JSONField(null=True)

0 commit comments

Comments
 (0)