-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4268 from ozer550/fix_celery_race_condition
Resolve Celery TaskObject Race Condition
- Loading branch information
Showing
14 changed files
with
272 additions
and
158 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
contentcuration/contentcuration/migrations/0145_custom_task_metadata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 3.2.19 on 2023-09-14 05:08 | ||
import django.core.validators | ||
import django.db.models.deletion | ||
from celery import states | ||
from django.conf import settings | ||
from django.db import migrations | ||
from django.db import models | ||
|
||
def transfer_data(apps, schema_editor): | ||
CustomTaskMetadata = apps.get_model('contentcuration', 'CustomTaskMetadata') | ||
TaskResult = apps.get_model('django_celery_results', 'taskresult') | ||
|
||
old_task_results = TaskResult.objects.filter(status__in=states.UNREADY_STATES) | ||
|
||
for old_task_result in old_task_results: | ||
CustomTaskMetadata.objects.create( | ||
task_id=old_task_result.task_id, | ||
user=old_task_result.user, | ||
channel_id=old_task_result.channel_id, | ||
progress=old_task_result.progress, | ||
signature=old_task_result.signature, | ||
) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contentcuration', '0144_soft_delete_user'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CustomTaskMetadata', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('task_id', models.CharField(max_length=255, unique=True)), | ||
('channel_id', models.UUIDField(blank=True, db_index=True, null=True)), | ||
('progress', models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])), | ||
('signature', models.CharField(max_length=32, null=True)), | ||
('date_created', models.DateTimeField(auto_now_add=True, help_text='Datetime field when the custom_metadata for task was created in UTC', verbose_name='Created DateTime')), | ||
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='tasks', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.AddIndex( | ||
model_name='customtaskmetadata', | ||
index=models.Index(fields=['signature'], name='task_result_signature'), | ||
), | ||
migrations.RunPython(transfer_data), | ||
] |
37 changes: 37 additions & 0 deletions
37
contentcuration/contentcuration/migrations/0146_drop_taskresult_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 3.2.19 on 2023-09-14 10:42 | ||
from django.db import migrations | ||
|
||
class Migration(migrations.Migration): | ||
|
||
replaces = [('django_celery_results', '0145_custom_task_metadata'),] | ||
|
||
def __init__(self, name, app_label): | ||
super(Migration, self).__init__(name, 'django_celery_results') | ||
|
||
dependencies = [ | ||
('contentcuration', '0145_custom_task_metadata'), | ||
('contentcuration', '0141_add_task_signature'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='taskresult', | ||
name='channel_id', | ||
), | ||
migrations.RemoveField( | ||
model_name='taskresult', | ||
name='progress', | ||
), | ||
migrations.RemoveField( | ||
model_name='taskresult', | ||
name='user', | ||
), | ||
migrations.RemoveField( | ||
model_name='taskresult', | ||
name='signature', | ||
), | ||
migrations.RemoveIndex( | ||
model_name='taskresult', | ||
name='task_result_signature_idx', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.