Skip to content

Commit 06c8340

Browse files
fix review comments
1 parent 05a7eed commit 06c8340

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

scripts/populate_subscriptions.py renamed to scripts/populate_notification_subscriptions.py

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from osf.models import OSFUser, Node, NotificationSubscription, NotificationType
1212

1313

14-
@celery_app.task(name='scripts.populate_subscriptions')
15-
def populate_subscriptions():
14+
@celery_app.task(name='scripts.populate_notification_subscriptions')
15+
def populate_notification_subscriptions():
1616
created = 0
1717
user_file_nt = NotificationType.Type.USER_FILE_UPDATED.instance
1818
review_nt = NotificationType.Type.REVIEWS_SUBMISSION_STATUS.instance
@@ -44,33 +44,50 @@ def populate_subscriptions():
4444
node_notifications_sq,
4545
output_field=IntegerField(),
4646
),
47-
)
48-
.exclude(contributors_count=F('notifications_count'))
47+
).exclude(contributors_count=F('notifications_count'))
4948
)
5049

51-
for user in reviews_qs:
52-
_, is_created = NotificationSubscription.objects.get_or_create(
53-
notification_type=review_nt,
54-
user=user,
55-
content_type=user_ct,
56-
object_id=user.id,
57-
message_frequency='instantly',
58-
)
59-
if is_created:
60-
created += 1
50+
print(f"Creating REVIEWS_SUBMISSION_STATUS subscriptions for {reviews_qs.count()} users.")
51+
for id, user in enumerate(reviews_qs, 1):
52+
print(f"Processing user {id} / {reviews_qs.count()}")
53+
try:
54+
_, is_created = NotificationSubscription.objects.get_or_create(
55+
notification_type=review_nt,
56+
user=user,
57+
content_type=user_ct,
58+
object_id=user.id,
59+
defaults={
60+
'message_frequency': 'none',
61+
},
62+
)
63+
if is_created:
64+
created += 1
65+
except Exception as exeption:
66+
print(exeption)
67+
continue
6168

62-
for user in files_qs:
63-
_, is_created = NotificationSubscription.objects.get_or_create(
64-
notification_type=user_file_nt,
65-
user=user,
66-
content_type=user_ct,
67-
object_id=user.id,
68-
message_frequency='instantly',
69-
)
70-
if is_created:
71-
created += 1
69+
print(f"Creating USER_FILE_UPDATED subscriptions for {files_qs.count()} users.")
70+
for id, user in enumerate(files_qs, 1):
71+
print(f"Processing user {id} / {files_qs.count()}")
72+
try:
73+
_, is_created = NotificationSubscription.objects.get_or_create(
74+
notification_type=user_file_nt,
75+
user=user,
76+
content_type=user_ct,
77+
object_id=user.id,
78+
defaults={
79+
'message_frequency': 'none',
80+
},
81+
)
82+
if is_created:
83+
created += 1
84+
except Exception as exeption:
85+
print(exeption)
86+
continue
7287

73-
for node in nodes_qs:
88+
print(f"Creating NODE_FILE_UPDATED subscriptions for {nodes_qs.count()} nodes.")
89+
for id, node in enumerate(nodes_qs, 1):
90+
print(f"Processing node {id} / {nodes_qs.count()}")
7491
for contributor in node.contributors.all():
7592
try:
7693
_, is_created = NotificationSubscription.objects.get_or_create(
@@ -79,15 +96,16 @@ def populate_subscriptions():
7996
content_type=node_ct,
8097
object_id=node.id,
8198
defaults={
82-
'message_frequency': 'instantly',
99+
'message_frequency': 'none',
83100
},
84101
)
85102
if is_created:
86103
created += 1
87-
except Exception:
104+
except Exception as exeption:
105+
print(exeption)
88106
continue
89107

90108
print(f"Created {created} subscriptions")
91109

92110
if __name__ == '__main__':
93-
populate_subscriptions.delay()
111+
populate_notification_subscriptions.delay()

website/settings/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class CeleryConfig:
450450
'osf.management.commands.monthly_reporters_go',
451451
'osf.management.commands.ingest_cedar_metadata_templates',
452452
'osf.metrics.reporters',
453-
'scripts.populate_subscriptions',
453+
'scripts.populate_notification_subscriptions',
454454
}
455455

456456
med_pri_modules = {
@@ -579,7 +579,7 @@ class CeleryConfig:
579579
'osf.management.commands.monthly_reporters_go',
580580
'osf.external.spam.tasks',
581581
'api.share.utils',
582-
'scripts.populate_subscriptions',
582+
'scripts.populate_notification_subscriptions',
583583
)
584584

585585
# Modules that need metrics and release requirements

0 commit comments

Comments
 (0)