Coverage for src/couchers/jobs/definitions.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

7 statements  

1from datetime import timedelta 

2 

3from google.protobuf import empty_pb2 

4 

5from couchers.jobs.handlers import ( 

6 process_add_users_to_email_list, 

7 process_enforce_community_membership, 

8 process_generate_message_notifications, 

9 process_handle_email_digests, 

10 process_handle_email_notifications, 

11 process_handle_notification, 

12 process_purge_account_deletion_tokens, 

13 process_purge_login_tokens, 

14 process_purge_password_reset_tokens, 

15 process_send_email, 

16 process_send_message_notifications, 

17 process_send_onboarding_emails, 

18 process_send_reference_reminders, 

19 process_send_request_notifications, 

20 process_update_recommendation_scores, 

21) 

22from couchers.models import BackgroundJobType 

23from proto.internal import jobs_pb2 

24 

25# job definitions, tuples of (BackgroundJobType, message, function) 

26JOBS = { 

27 BackgroundJobType.send_email: (jobs_pb2.SendEmailPayload, process_send_email), 

28 BackgroundJobType.purge_login_tokens: (empty_pb2.Empty, process_purge_login_tokens), 

29 BackgroundJobType.purge_password_reset_tokens: (empty_pb2.Empty, process_purge_password_reset_tokens), 

30 BackgroundJobType.purge_account_deletion_tokens: (empty_pb2.Empty, process_purge_account_deletion_tokens), 

31 BackgroundJobType.send_message_notifications: (empty_pb2.Empty, process_send_message_notifications), 

32 BackgroundJobType.send_onboarding_emails: (empty_pb2.Empty, process_send_onboarding_emails), 

33 BackgroundJobType.add_users_to_email_list: (empty_pb2.Empty, process_add_users_to_email_list), 

34 BackgroundJobType.send_request_notifications: (empty_pb2.Empty, process_send_request_notifications), 

35 BackgroundJobType.enforce_community_membership: (empty_pb2.Empty, process_enforce_community_membership), 

36 BackgroundJobType.send_reference_reminders: (empty_pb2.Empty, process_send_reference_reminders), 

37 BackgroundJobType.handle_notification: (jobs_pb2.HandleNotificationPayload, process_handle_notification), 

38 BackgroundJobType.handle_email_notifications: (empty_pb2.Empty, process_handle_email_notifications), 

39 BackgroundJobType.handle_email_digests: (empty_pb2.Empty, process_handle_email_digests), 

40 BackgroundJobType.generate_message_notifications: ( 

41 jobs_pb2.GenerateMessageNotificationsPayload, 

42 process_generate_message_notifications, 

43 ), 

44 BackgroundJobType.update_recommendation_scores: (empty_pb2.Empty, process_update_recommendation_scores), 

45} 

46 

47SCHEDULE = [ 

48 (BackgroundJobType.purge_login_tokens, timedelta(hours=24)), 

49 (BackgroundJobType.purge_password_reset_tokens, timedelta(hours=24)), 

50 (BackgroundJobType.purge_account_deletion_tokens, timedelta(hours=24)), 

51 (BackgroundJobType.send_message_notifications, timedelta(minutes=3)), 

52 (BackgroundJobType.send_onboarding_emails, timedelta(hours=1)), 

53 (BackgroundJobType.add_users_to_email_list, timedelta(hours=1)), 

54 (BackgroundJobType.send_request_notifications, timedelta(minutes=3)), 

55 (BackgroundJobType.enforce_community_membership, timedelta(minutes=15)), 

56 (BackgroundJobType.send_reference_reminders, timedelta(hours=1)), 

57 (BackgroundJobType.handle_email_notifications, timedelta(minutes=1)), 

58 (BackgroundJobType.handle_email_digests, timedelta(minutes=15)), 

59 (BackgroundJobType.update_recommendation_scores, timedelta(hours=24)), 

60]