Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LEAP-1600: Add created_at for TaskLock #6583

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions label_studio/tasks/migrations/0051_tasklock_created_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2024-10-30 17:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tasks', '0050_alter_predictionmeta_failed_prediction_and_more'),
]

operations = [
migrations.AddField(
model_name='tasklock',
name='created_at',
field=models.DateTimeField(auto_now_add=True, help_text='Creation time', null=True, verbose_name='created at'),
),
]
58 changes: 58 additions & 0 deletions label_studio/tasks/migrations/0052_auto_20241030_1757.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 4.2.16 on 2024-10-30 17:57

from django.db import migrations
from django.db import connection
from django.conf import settings

from core.models import AsyncMigrationStatus
from core.redis import start_job_async_or_sync

import logging
logger = logging.getLogger(__name__)
migration_name = '0052_auto_20241030_1757'

if connection.vendor == 'sqlite':
sql_update_created_at = """
UPDATE tasks_tasklock
SET created_at = datetime(expire_at, %s);
"""
sql_params = (f'-{settings.TASK_LOCK_TTL} seconds',)
else:
sql_update_created_at = """
UPDATE tasks_tasklock
SET created_at = expire_at - INTERVAL %s;
"""
sql_params = ('%s seconds' % settings.TASK_LOCK_TTL,)

def forward_migration(migration_name):
migration = AsyncMigrationStatus.objects.create(
name=migration_name,
status=AsyncMigrationStatus.STATUS_STARTED,
)
logger.info(f'Start async migration {migration_name}')

with connection.cursor() as cursor:
cursor.execute(sql_update_created_at, sql_params)

migration.status = AsyncMigrationStatus.STATUS_FINISHED
migration.save()
logger.info(f'Async migration {migration_name} complete')

def forwards(apps, schema_editor):
# Dispatch migrations to rqworkers
start_job_async_or_sync(forward_migration, migration_name=migration_name)

def backwards(apps, schema_editor):
pass

class Migration(migrations.Migration):
atomic = False

dependencies = [
('tasks', '0051_tasklock_created_at'),
]

operations = [
migrations.RunPython(forwards, backwards),
]

1 change: 1 addition & 0 deletions label_studio/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ class TaskLock(models.Model):
on_delete=models.CASCADE,
help_text='User who locked this task',
)
created_at = models.DateTimeField(_('created at'), auto_now_add=True, help_text='Creation time', null=True)


class AnnotationDraft(models.Model):
Expand Down
Loading