Create /tasks/email-reviewers in notifier

This commit is contained in:
Kyle Ju 2023-02-01 17:08:04 -08:00
Родитель 6e5b622c82
Коммит dc48d2d29c
5 изменённых файлов: 46 добавлений и 8 удалений

Просмотреть файл

@ -10,5 +10,8 @@ dispatch:
- url: "*/tasks/email-subscribers"
service: notifier
- url: "*/tasks/email-reviewers"
service: notifier
- url: "*/*"
service: default

Просмотреть файл

@ -146,16 +146,12 @@ def apply_subscription_rules(
return results
def make_email_tasks(fe: FeatureEntry, is_update: bool=False,
changes: Optional[list]=None):
def make_email_tasks(fe: FeatureEntry, target_emails: list[str],
is_update: bool = False, changes: Optional[list] = None):
"""Return a list of task dicts to notify users of feature changes."""
if changes is None:
changes = []
watchers: list[FeatureOwner] = FeatureOwner.query(
FeatureOwner.watching_all_features == True).fetch(None)
watcher_emails: list[str] = [watcher.email for watcher in watchers]
fe_stages = stage_helpers.get_feature_stages(fe.key.integer_id())
email_html = format_email_body(is_update, fe, fe_stages, changes)
@ -181,7 +177,7 @@ def make_email_tasks(fe: FeatureEntry, is_update: bool=False,
'You are CC\'d on this feature'
)
accumulate_reasons(
addr_reasons, watcher_emails,
addr_reasons, target_emails,
'You are watching all feature changes')
# There will always be at least one component.
@ -369,7 +365,37 @@ class FeatureChangeHandler(basehandlers.FlaskHandler):
# Load feature directly from NDB so as to never get a stale cached copy.
fe = FeatureEntry.get_by_id(feature['id'])
if fe and (is_update and len(changes) or not is_update):
email_tasks = make_email_tasks(fe, is_update=is_update, changes=changes)
watchers: list[FeatureOwner] = FeatureOwner.query(
FeatureOwner.watching_all_features == True).fetch(None)
watcher_emails: list[str] = [watcher.email for watcher in watchers]
email_tasks = make_email_tasks(fe, target_emails=watcher_emails,
is_update=is_update, changes=changes)
send_emails(email_tasks)
return {'message': 'Done'}
class FeatureReviewHandler(basehandlers.FlaskHandler):
"""This task handles feature review requests by making email tasks."""
IS_INTERNAL_HANDLER = True
def process_post_data(self, **kwargs):
self.require_task_header()
feature = self.get_param('feature')
gate_type = self.get_param('gate_type')
changes = self.get_param('changes', required=False) or []
logging.info('Starting to notify reviewers for feature %s',
repr(feature)[:settings.MAX_LOG_LINE])
fe = FeatureEntry.get_by_id(feature['id'])
if fe:
approvers = approval_defs.get_approvers(gate_type)
email_tasks = make_email_tasks(fe, target_emails=approvers,
is_update=True, changes=changes)
send_emails(email_tasks)
return {'message': 'Done'}

Просмотреть файл

@ -236,6 +236,7 @@ internals_routes: list[Route] = [
Route('/tasks/email-subscribers', notifier.FeatureChangeHandler),
Route('/tasks/detect-intent', detect_intent.IntentEmailHandler),
Route('/tasks/email-reviewers', notifier.FeatureReviewHandler),
Route('/admin/schema_migration_delete_entities',
schema_migration.DeleteNewEntities),

Просмотреть файл

@ -10,6 +10,10 @@ handlers:
script: auto
# Header checks prevent raw access to this handler. Tasks have headers.
- url: /tasks/email-reviewers
script: auto
# Header checks prevent raw access to this handler. Tasks have headers.
app_engine_apis: true
# Set up VPC Access Connector for Redis.

Просмотреть файл

@ -10,6 +10,10 @@ handlers:
script: auto
# Header checks prevent raw access to this handler. Tasks have headers.
- url: /tasks/email-reviewers
script: auto
# Header checks prevent raw access to this handler. Tasks have headers.
app_engine_apis: true
# Set up VPC Access Connector for Redis in prod.