Populate execution_time for existing jobs
This commit is contained in:
parent
19bdc9c7f7
commit
09cd3f2dfd
|
|
@ -1,4 +1,15 @@
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
from django.db.models import DurationField, ExpressionWrapper, F
|
||||||
|
|
||||||
|
|
||||||
|
def populate_execution_time(apps, schema_editor):
|
||||||
|
"""
|
||||||
|
Populate execution_time for existing jobs which have both a start and completion time recorded.
|
||||||
|
"""
|
||||||
|
Job = apps.get_model("core", "Job")
|
||||||
|
Job.objects.filter(started__isnull=False, completed__isnull=False).update(
|
||||||
|
execution_time=ExpressionWrapper(F("completed") - F("started"), output_field=DurationField())
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
@ -13,4 +24,8 @@ class Migration(migrations.Migration):
|
||||||
name="execution_time",
|
name="execution_time",
|
||||||
field=models.DurationField(blank=True, editable=False, null=True),
|
field=models.DurationField(blank=True, editable=False, null=True),
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=populate_execution_time,
|
||||||
|
reverse_code=migrations.RunPython.noop,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue