Skip to content

Commit 5179e2a

Browse files
committed
fix: DEV-2589: Move calculate_stats_all_orgs to rq_workers, swap migration
1 parent 0d76e69 commit 5179e2a

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

label_studio/tasks/migrations/0018_manual_migrate_counters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88

99
def forwards(apps, schema_editor):
10+
# This migration was moved to 0024_manual_migrate_counters_again.py
11+
12+
"""
1013
from tasks.functions import calculate_stats_all_orgs
1114
from django.conf import settings
1215
@@ -25,6 +28,8 @@ def forwards(apps, schema_editor):
2528
2629
logger.debug('=> Starting calculate_stats_all_orgs for task counters')
2730
calculate_stats_all_orgs(from_scratch=False, redis=True)
31+
"""
32+
return
2833

2934

3035
def backwards(apps, schema_editor):
@@ -34,7 +39,7 @@ def backwards(apps, schema_editor):
3439
class Migration(migrations.Migration):
3540
atomic = False
3641

37-
dependencies = [('tasks', '0017_auto_20220330_1310'), ('core', '0001_initial')]
42+
dependencies = [('tasks', '0017_auto_20220330_1310'), ]
3843

3944
operations = [
4045
migrations.RunPython(forwards, backwards),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
import logging
3+
4+
from django.db import migrations
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
def forwards(apps, schema_editor):
10+
from tasks.functions import calculate_stats_all_orgs
11+
from django.conf import settings
12+
13+
if settings.VERSION_EDITION == 'Community':
14+
run_command = 'label-studio calculate_stats_all_orgs'
15+
else:
16+
run_command = 'cd /label-studio-enterprise/label_studio_enterprise && ' \
17+
'python3 manage.py calculate_stats_all_orgs'
18+
19+
if '--skip-long-migrations' in sys.argv:
20+
logger.error(
21+
f"You used --skip-long-migrations, so you should run the migration manually as a separate process "
22+
f"to recalculate task counters, please use Django command `{run_command}`"
23+
)
24+
return
25+
26+
logger.debug('=> Starting calculate_stats_all_orgs for task counters again')
27+
calculate_stats_all_orgs(from_scratch=False, redis=True)
28+
29+
30+
def backwards(apps, schema_editor):
31+
pass
32+
33+
34+
class Migration(migrations.Migration):
35+
atomic = False
36+
37+
dependencies = [('tasks', '0023_auto_20220620_1007'), ('core', '0001_initial')]
38+
39+
operations = [
40+
migrations.RunPython(forwards, backwards),
41+
]

0 commit comments

Comments
 (0)