Skip to content

Commit 226c33a

Browse files
committed
convert slack_notify to generic notify
1 parent 1ea9bb1 commit 226c33a

File tree

11 files changed

+73
-42
lines changed

11 files changed

+73
-42
lines changed

apps/accounts/events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# HTK Imports
77
from htk.utils import htk_setting
8-
from htk.utils.notifications import slack_notify
8+
from htk.utils.notifications import notify
99

1010

1111
def failed_recaptcha_on_login(user, request=None):
@@ -26,12 +26,12 @@ def failed_recaptcha_on_login(user, request=None):
2626
user.username,
2727
user.email,
2828
)
29-
slack_notify(slack_message, level='warning')
29+
notify(slack_message, level='warning', use_messages=False)
3030

3131

3232
def failed_recaptcha_on_account_register(request=None):
3333
message = 'Failed reCAPTCHA. Suspicious account registration detected.'
3434

3535
rollbar.report_message(message, request=request)
3636

37-
slack_notify(message, level='warning')
37+
notify(message, level='warning', use_messages=False)

apps/accounts/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def activate(
561561
sender=email_sender,
562562
)
563563

564-
slack_notify(
564+
notify(
565565
'*%s* has activated their account on %s'
566566
% (
567567
user.email,

apps/invitations/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from htk.utils.cache_descriptors import CachedAttribute
1313
from htk.utils.datetime_utils import relative_time
1414
from htk.utils.enums import get_enum_symbolic_name
15-
from htk.utils.notifications import slack_notify
15+
from htk.utils.notifications import notify
1616

1717

1818
# isort: off
@@ -96,7 +96,7 @@ def connect_user(self, user):
9696
self.get_relative_time(),
9797
)
9898
)
99-
slack_notify(msg)
99+
notify(msg, use_messages=False)
100100

101101
def complete(self, user=None):
102102
"""Completes the invitation lifecycle
@@ -127,4 +127,4 @@ def complete(self, user=None):
127127
self.get_relative_time(),
128128
)
129129
)
130-
slack_notify(msg)
130+
notify(msg, use_messages=False)

apps/invitations/services.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from htk.apps.sites.utils import get_site_name
55
from htk.services import HtkBaseService
66
from htk.utils import htk_setting
7-
from htk.utils.notifications import slack_notify
7+
from htk.utils.notifications import notify
88

99

1010
# isort: off
@@ -46,7 +46,7 @@ def process_user_created(self, user):
4646
invitation.get_relative_time(),
4747
)
4848
)
49-
slack_notify(msg)
49+
notify(msg, use_messages=False)
5050

5151
def process_user_email_confirmation(self, user_email):
5252
"""Invoked when `user_email` is confirmed

apps/organizations/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
htk_setting,
1414
resolve_model_dynamically,
1515
)
16-
from htk.utils.notifications import slack_notify
16+
from htk.utils.notifications import notify
1717

1818

1919
# isort: off
@@ -38,7 +38,7 @@ def organization_invitation_created_or_updated(
3838
msg_builder = INVITATION_ACCEPTANCE_MESSAGE_BUILDERS[msg_builder_key]
3939
msg = msg_builder()
4040

41-
slack_notify(msg)
41+
notify(msg, use_messages=False)
4242

4343

4444
class HtkOrganizationAppConfig(HtkAppConfig):

apps/prelaunch/models/base.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# Third Party (PyPI) Imports
55
import rollbar
6-
from baws.utils.urls import get_full_url
76

87
# Django Imports
98
from django.contrib.sites.models import Site
@@ -15,11 +14,9 @@
1514
prelaunch_email,
1615
)
1716
from htk.utils import htk_setting
18-
from htk.utils.notifications import (
19-
notify,
20-
slack_notify,
21-
)
17+
from htk.utils.notifications import notify
2218
from htk.utils.request import get_current_request
19+
from htk.utils.urls import build_full_url
2320

2421

2522
# isort: off
@@ -141,7 +138,7 @@ def notification_message(self):
141138
return message
142139

143140
def send_notifications(self):
144-
slack_notify(self.notification_message)
141+
notify(self.notification_message, use_messages=False)
145142

146143
try:
147144
prelaunch_email(self)
@@ -162,7 +159,8 @@ def grant_early_access(self):
162159
notify(
163160
'Early access has been enabled for {} <{}>'.format(
164161
self.full_name, self.email
165-
)
162+
),
163+
use_messages=False,
166164
)
167165
try:
168166
early_access_email(self)
@@ -179,7 +177,7 @@ def revoke_early_access(self):
179177
def early_access_url(self):
180178
if self.early_access:
181179
early_access_url = '{}?early_access_code={}'.format(
182-
get_full_url('/'),
180+
build_full_url('/'),
183181
self.early_access_code,
184182
)
185183
else:

decorators/celery_.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
# Third Party (PyPI) Imports
66
import rollbar
7-
from celery import shared_task
87

98
# HTK Imports
109
from htk.cachekeys import TaskCooldown
1110
from htk.utils import htk_setting
12-
from htk.utils.notifications import slack_notify
11+
from htk.utils.notifications import notify
1312
from htk.utils.timer import HtkTimer
1413

14+
from celery import shared_task
15+
1516

1617
class safe_timed_task(object):
1718
def __init__(
@@ -69,7 +70,7 @@ def wrapped(*args, **kwargs):
6970
msg = 'Processing *{}*... (`{}`)'.format(
7071
self.task_name, gethostname()
7172
)
72-
slack_notify(msg, custom_channel=custom_channel)
73+
notify(msg, custom_channel=custom_channel)
7374

7475
timer = HtkTimer()
7576
timer.start()
@@ -98,7 +99,7 @@ def wrapped(*args, **kwargs):
9899
msg = '{}Finished processing *{}* in *{}* seconds (`{}`)'.format(
99100
skipped_msg, self.task_name, duration, gethostname()
100101
)
101-
slack_notify(msg, custom_channel=custom_channel)
102+
notify(msg, custom_channel=custom_channel)
102103
except Exception:
103104
result = None
104105
extra_data = {

lib/github/tasks.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
MORNING_HOURS_END,
66
)
77
from htk.tasks import BaseTask
8-
from htk.utils.notifications import slack_notify
8+
from htk.utils.notifications import notify
99
from htk.utils.text.transformers import get_symbols
1010

1111

@@ -15,55 +15,78 @@
1515
class GitHubReminderTask(BaseTask):
1616
def __init__(self):
1717
from htk.lib.github.cachekeys import GitHubReminderCooldown
18-
super(GitHubReminderTask, self).__init__(cooldown_class=GitHubReminderCooldown)
18+
19+
super(GitHubReminderTask, self).__init__(
20+
cooldown_class=GitHubReminderCooldown
21+
)
1922

2023
def has_cooldown(self, user):
2124
_has_cooldown = super(GitHubReminderTask, self).has_cooldown(user)
22-
#_has_cooldown = False
25+
# _has_cooldown = False
2326
return _has_cooldown
2427

2528
def get_users(self):
2629
import htk.apps.accounts.filters as _filters
27-
from htk.apps.accounts.utils.lookup import get_users_with_attribute_value
28-
users = get_users_with_attribute_value('github_reminders', True, as_bool=True)
29-
users = _filters.users_currently_at_local_time(users, BUSINESS_HOURS_START, MORNING_HOURS_END, isoweekdays=ISOWEEKDAY_WEEKDAYS)
30+
from htk.apps.accounts.utils.lookup import (
31+
get_users_with_attribute_value,
32+
)
33+
34+
users = get_users_with_attribute_value(
35+
'github_reminders', True, as_bool=True
36+
)
37+
users = _filters.users_currently_at_local_time(
38+
users,
39+
BUSINESS_HOURS_START,
40+
MORNING_HOURS_END,
41+
isoweekdays=ISOWEEKDAY_WEEKDAYS,
42+
)
3043

3144
return users
3245

3346
def execute(self, user):
34-
slack_notify('Processing GitHub Reminders for {}'.format(user.username))
47+
notify(
48+
'Processing GitHub Reminders for {}'.format(user.username),
49+
use_messages=False,
50+
)
3551

3652
now = user.profile.get_local_time()
3753

3854
valid_chars = 'A-Za-z0-9_\-/'
3955
github_organizations = get_symbols(
4056
user.profile.get_attribute('github_organizations') or '',
41-
valid_chars=valid_chars
57+
valid_chars=valid_chars,
4258
)
4359
github_repositories = get_symbols(
4460
user.profile.get_attribute('github_repositories') or '',
45-
valid_chars=valid_chars
61+
valid_chars=valid_chars,
4662
)
4763

4864
self.send_github_reminders(
4965
user,
5066
organizations=github_organizations,
51-
repositories=github_repositories
67+
repositories=github_repositories,
5268
)
5369

54-
def send_github_reminders(self, user, organizations=None, repositories=None):
70+
def send_github_reminders(
71+
self, user, organizations=None, repositories=None
72+
):
5573
github_access_token = user.profile.get_attribute('github_access_token')
5674
slack_webhook_url = user.profile.get_attribute('slack_webhook_url')
57-
slack_channel = user.profile.get_attribute('github_reminders_slack_channel')
58-
mention_here = user.profile.get_attribute('github_reminders_slack_mention_here')
75+
slack_channel = user.profile.get_attribute(
76+
'github_reminders_slack_channel'
77+
)
78+
mention_here = user.profile.get_attribute(
79+
'github_reminders_slack_mention_here'
80+
)
5981

6082
from htk.lib.github.bots import GitHubReminderSlackBot
83+
6184
bot = GitHubReminderSlackBot(
6285
slack_webhook_url,
6386
slack_channel,
6487
github_access_token,
6588
organizations=organizations,
6689
repositories=repositories,
67-
mention_here=mention_here
90+
mention_here=mention_here,
6891
)
6992
bot.remind_pull_requests()

lib/shopify_lib/archivers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# HTK Imports
1010
from htk.utils import htk_setting
1111
from htk.utils.cache_descriptors import CachedAttribute
12-
from htk.utils.notifications import slack_notify
12+
from htk.utils.notifications import notify
1313

1414

1515
# isort: off
@@ -133,7 +133,7 @@ def archive_item_type(self, item_type):
133133
msg = 'Archiving %ss...' % item_type
134134
print(msg)
135135

136-
slack_notify(msg)
136+
notify(msg, use_messages=False)
137137

138138
num_archived = 0
139139
iterator = self._get_iterator_for_item_type(item_type)
@@ -154,7 +154,7 @@ def archive_item_type(self, item_type):
154154
item_type,
155155
duration,
156156
)
157-
slack_notify(msg)
157+
notify(msg, use_messages=False)
158158

159159
def archive_item(self, item_type, item):
160160
"""Archives a single Shopify.Resource `item` into some database using `archiver`"""

utils/notifications.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def notify(
1818
use_messages=True,
1919
use_slack=None,
2020
use_google=None,
21+
custom_channel=None,
2122
):
2223
"""Wrapper for simultaneously sending a message via:
2324
@@ -52,13 +53,13 @@ def notify(
5253
use_slack = htk_setting('HTK_SLACK_NOTIFICATIONS_ENABLED')
5354

5455
if use_slack:
55-
slack_notify(message, level=level)
56+
slack_notify(message, level=level, custom_channel=custom_channel)
5657

5758
if use_google is None:
5859
use_google = htk_setting('HTK_GOOGLE_CHAT_NOTIFICATIONS_ENABLED')
5960

6061
if use_google:
61-
google_chat_notify(message, level=level)
62+
google_chat_notify(message, level=level, custom_channel=custom_channel)
6263

6364

6465
def slack_notify(message, level=None, custom_channel=None):

0 commit comments

Comments
 (0)