Skip to content

Commit 4542184

Browse files
authored
Sync suppressed emails daily (#21998)
* Raname suppression sync task * Add cron job to sync suppressed emails daily
1 parent 5f84d0c commit 4542184

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

scripts/crontab/crontab.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ HOME=/tmp
2727
30 9 * * * %(z_cron)s update_user_ratings
2828
0 22 * * * %(z_cron)s gc
2929
0 23 * * * %(z_cron)s write_sitemaps
30+
0 23 * * * %(z_cron)s sync_suppressed_emails_cron
3031

3132
# Once per day after metrics import is done
3233
30 12 * * * %(z_cron)s update_addon_weekly_downloads

src/olympia/lib/settings_base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ def get_db_config(environ_var, atomic_requests=True):
922922
'queue': 'cron'
923923
},
924924
'olympia.reviewers.tasks.recalculate_post_review_weight': {'queue': 'cron'},
925-
'olympia.users.tasks.sync_blocked_emails': {'queue': 'cron'},
925+
'olympia.users.tasks.sync_suppressed_emails_task': {'queue': 'cron'},
926926
'olympia.users.tasks.send_suppressed_email_confirmation': {'queue': 'devhub'},
927927
'olympia.users.tasks.check_suppressed_email_confirmation': {'queue': 'devhub'},
928928
# Reviewers.
@@ -1461,6 +1461,7 @@ def read_only_mode(env):
14611461
'upload_mlbf_to_remote_settings': 'olympia.blocklist.cron',
14621462
'update_blog_posts': 'olympia.devhub.cron',
14631463
'update_user_ratings': 'olympia.users.cron',
1464+
'sync_suppressed_emails_cron': 'olympia.users.cron',
14641465
}
14651466

14661467
RECOMMENDATION_ENGINE_URL = env(

src/olympia/users/cron.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from olympia.amo import VALID_ADDON_STATUSES
88
from olympia.amo.utils import chunked
99

10-
from .tasks import update_user_ratings_task
10+
from .tasks import sync_suppressed_emails_task, update_user_ratings_task
1111

1212

1313
task_log = olympia.core.logger.getLogger('z.task')
@@ -45,3 +45,11 @@ def update_user_ratings():
4545
ts = [update_user_ratings_task.subtask(args=[chunk]) for chunk in chunked(d, 1000)]
4646

4747
group(ts).apply_async()
48+
49+
50+
def sync_suppressed_emails_cron():
51+
"""
52+
Sync suppressed emails daily
53+
"""
54+
55+
sync_suppressed_emails_task.delay()
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from django.core.management.base import BaseCommand
22

3-
from olympia.users.tasks import sync_blocked_emails
3+
from olympia.users.tasks import sync_suppressed_emails_task
44

55

66
class Command(BaseCommand):
77
"""Sync Socket labs suppression list to database."""
88

99
def handle(self, *args, **options):
10-
sync_blocked_emails.apply()
10+
sync_suppressed_emails_task.apply()

src/olympia/users/tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def assert_socket_labs_settings_defined():
103103

104104

105105
@task(autoretry_for=(HTTPError, Timeout), max_retries=5, retry_backoff=True)
106-
def sync_blocked_emails(batch_size=BATCH_SIZE, **kw):
106+
def sync_suppressed_emails_task(batch_size=BATCH_SIZE, **kw):
107107
assert_socket_labs_settings_defined()
108108

109109
task_log.info('fetching suppression list from socket labs...')

src/olympia/users/tests/test_tasks.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
delete_photo,
3333
resize_photo,
3434
send_suppressed_email_confirmation,
35-
sync_blocked_emails,
35+
sync_suppressed_emails_task,
3636
)
3737

3838

@@ -219,7 +219,7 @@ def test_fails_missing_settings(self):
219219
):
220220
with pytest.raises(Exception) as exc:
221221
setattr(settings, setting, None)
222-
sync_blocked_emails.s().apply(throw=True)
222+
sync_suppressed_emails_task.s().apply(throw=True)
223223
assert exc.match('SOCKET_LABS_TOKEN is not defined')
224224

225225
def test_retry_if_api_returns_bad_response(self):
@@ -229,7 +229,7 @@ def test_retry_if_api_returns_bad_response(self):
229229
status=500,
230230
)
231231

232-
task = sync_blocked_emails.s()
232+
task = sync_suppressed_emails_task.s()
233233

234234
with pytest.raises(Retry):
235235
task.apply(throw=True)
@@ -244,7 +244,7 @@ def timeout_callback(request):
244244
callback=timeout_callback,
245245
)
246246

247-
task = sync_blocked_emails.s()
247+
task = sync_suppressed_emails_task.s()
248248

249249
with pytest.raises(Retry):
250250
task.apply(throw=True)
@@ -259,7 +259,7 @@ def test_empty_csv(self):
259259
status=200,
260260
)
261261

262-
sync_blocked_emails()
262+
sync_suppressed_emails_task()
263263

264264
assert SuppressedEmail.objects.count() == 0
265265

@@ -277,7 +277,7 @@ def test_existing_email(self):
277277

278278
SuppressedEmail.objects.create(email=user.email)
279279

280-
sync_blocked_emails()
280+
sync_suppressed_emails_task()
281281

282282
email_block = SuppressedEmail.objects.get(email=user.email)
283283

@@ -296,7 +296,7 @@ def test_unique_email(self):
296296
status=200,
297297
)
298298

299-
sync_blocked_emails()
299+
sync_suppressed_emails_task()
300300

301301
email_block = SuppressedEmail.objects.get(email=user.email)
302302

0 commit comments

Comments
 (0)