Skip to content

Commit

Permalink
fix: DEV-2589: Move calculate_stats_all_orgs to rq_workers, swap migr…
Browse files Browse the repository at this point in the history
…ation (HumanSignal#2569)
  • Loading branch information
makseq authored Jun 27, 2022
1 parent 0d76e69 commit 55f09c7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


def forwards(apps, schema_editor):
# This migration was moved to 0024_manual_migrate_counters_again.py

"""
from tasks.functions import calculate_stats_all_orgs
from django.conf import settings
Expand All @@ -25,6 +28,8 @@ def forwards(apps, schema_editor):
logger.debug('=> Starting calculate_stats_all_orgs for task counters')
calculate_stats_all_orgs(from_scratch=False, redis=True)
"""
return


def backwards(apps, schema_editor):
Expand All @@ -34,7 +39,7 @@ def backwards(apps, schema_editor):
class Migration(migrations.Migration):
atomic = False

dependencies = [('tasks', '0017_auto_20220330_1310'), ('core', '0001_initial')]
dependencies = [('tasks', '0017_auto_20220330_1310'), ]

operations = [
migrations.RunPython(forwards, backwards),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys
import logging

from django.db import migrations

logger = logging.getLogger(__name__)


def forwards(apps, schema_editor):
from tasks.functions import calculate_stats_all_orgs
from django.conf import settings

if settings.VERSION_EDITION == 'Community':
run_command = 'label-studio calculate_stats_all_orgs'
else:
run_command = 'cd /label-studio-enterprise/label_studio_enterprise && ' \
'python3 manage.py calculate_stats_all_orgs'

if '--skip-long-migrations' in sys.argv:
logger.error(
f"You used --skip-long-migrations, so you should run the migration manually as a separate process "
f"to recalculate task counters, please use Django command `{run_command}`"
)
return

logger.debug('=> Starting calculate_stats_all_orgs for task counters again')
calculate_stats_all_orgs(from_scratch=False, redis=True)


def backwards(apps, schema_editor):
pass


class Migration(migrations.Migration):
atomic = False

dependencies = [('tasks', '0023_auto_20220620_1007'), ('core', '0001_initial')]

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

0 comments on commit 55f09c7

Please sign in to comment.