Skip to content

Commit 984aaba

Browse files
committed
Migrate Jobs model to django
1 parent f4fbc6a commit 984aaba

File tree

9 files changed

+145
-323
lines changed

9 files changed

+145
-323
lines changed

kolibri/core/auth/tasks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from kolibri.core.tasks.utils import DatabaseLockedError
4747
from kolibri.core.tasks.utils import get_current_job
4848
from kolibri.core.tasks.validation import JobValidator
49-
from kolibri.utils.time_utils import naive_utc_datetime
5049
from kolibri.utils.translation import gettext as _
5150

5251

@@ -472,7 +471,7 @@ def enqueue_soud_sync_processing():
472471

473472
# Check if there is already an enqueued job
474473
try:
475-
converted_next_run = naive_utc_datetime(timezone.now() + next_run)
474+
converted_next_run = timezone.now() + next_run
476475
orm_job = job_storage.get_orm_job(SOUD_SYNC_PROCESSING_JOB_ID)
477476
if (
478477
orm_job.state not in (State.COMPLETED, State.FAILED, State.CANCELED)

kolibri/core/tasks/api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
from django.http.response import Http404
44
from django.utils.decorators import method_decorator
5-
from django.utils.timezone import make_aware
65
from django.views.decorators.csrf import csrf_protect
7-
from pytz import utc
86
from rest_framework import decorators
97
from rest_framework import serializers
108
from rest_framework import status
@@ -100,8 +98,7 @@ def _job_to_response(self, job):
10098
"args": job.args,
10199
"kwargs": job.kwargs,
102100
"extra_metadata": job.extra_metadata,
103-
# Output is UTC naive, coerce to UTC aware.
104-
"scheduled_datetime": make_aware(orm_job.scheduled_time, utc).isoformat(),
101+
"scheduled_datetime": orm_job.scheduled_time.isoformat(),
105102
"repeat": orm_job.repeat,
106103
"repeat_interval": orm_job.interval,
107104
"retry_interval": orm_job.retry_interval,

kolibri/core/tasks/job.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import traceback
55
import uuid
66
from collections import namedtuple
7-
from datetime import timedelta
87

98
from kolibri.core.tasks.constants import ( # noqa F401 - imported for backwards compatibility
109
Priority,
@@ -102,13 +101,6 @@ def default_status_text(job):
102101

103102
ALLOWED_RETRY_IN_KWARGS = {"priority", "repeat", "interval", "retry_interval"}
104103

105-
RETRY_ON_DELAY = timedelta(
106-
seconds=5
107-
) # Delay before retrying a job that failed due to a retryable exception
108-
MAX_RETRIES = (
109-
3 # Maximum number of retries for a job that failed due to a retryable exception
110-
)
111-
112104

113105
class Job(object):
114106
"""

kolibri/core/tasks/main.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
from django.utils.functional import SimpleLazyObject
44

55
from kolibri.core.tasks.storage import Storage
6-
from kolibri.core.tasks.utils import db_connection
76
from kolibri.core.tasks.worker import Worker
87
from kolibri.utils import conf
98

109

1110
logger = logging.getLogger(__name__)
1211

1312

14-
connection = SimpleLazyObject(db_connection)
15-
16-
1713
def __job_storage():
18-
return Storage(
19-
connection=connection,
20-
)
14+
return Storage()
2115

2216

2317
# This storage instance should be used to access job_storage db.
@@ -28,7 +22,6 @@ def __job_storage():
2822
def initialize_workers(log_queue=None):
2923
logger.info("Starting async task workers.")
3024
return Worker(
31-
connection=connection,
3225
regular_workers=conf.OPTIONS["Tasks"]["REGULAR_PRIORITY_WORKERS"],
3326
high_workers=conf.OPTIONS["Tasks"]["HIGH_PRIORITY_WORKERS"],
3427
log_queue=log_queue,

kolibri/core/tasks/models.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,9 @@ def allow_migrate(self, db, app_label, model_name=None, **hints):
4747
return None
4848

4949

50+
# The Job model has been migrated from SqlAlchemy to use django models
51+
# generated by Copilot and tweaked
5052
class Job(models.Model):
51-
"""
52-
Django model corresponding to the 'jobs' table in SQLAlchemy.
53-
54-
This model is not meant to be used for normal CRUD operations (yet).
55-
It exists solely for Django to manage the migrations
56-
of the 'jobs' table, which is handled by SQLAlchemy.
57-
"""
5853

5954
# The hex UUID given to the job upon first creation.
6055
id = models.CharField(max_length=36, primary_key=True)

0 commit comments

Comments
 (0)