Jarvis Stubblefield
12/15/2022, 11:42 PMJarvis Stubblefield
12/15/2022, 11:42 PM$ python -m performance.flows.deployments.one_offs
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/flows.py:205: UserWarning: A flow named 'alert-upcoming-hire-date-reviews' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_hire_date_reviews.py:22' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:
`@flow(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/tasks.py:206: UserWarning: A task named 'get_potential_users_from_logs' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:29' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:
`@task(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/tasks.py:206: UserWarning: A task named 'get_tasks_for_org_ids' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:37' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:
`@task(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/tasks.py:206: UserWarning: A task named 'get_logs_from_tasks' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:42' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:
`@task(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/tasks.py:206: UserWarning: A task named 'get_view_logs_url' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:47' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:
`@task(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/tasks.py:206: UserWarning: A task named 'get_email_context' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:55' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:
`@task(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/tasks.py:206: UserWarning: A task named 'get_merge_data_for_leaders' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:66' conflicts with another task. Consider specifying a unique `name` parameter in the task definition:
`@task(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/flows.py:205: UserWarning: A flow named 'alert-ky-early-intervention' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_ky_early_intervention.py:75' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:
`@flow(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/flows.py:205: UserWarning: A flow named 'update-and-alert-about-users-who-need-logs' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/alert_logs_needed.py:14' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:
`@flow(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/flows.py:205: UserWarning: A flow named 'reset-annual-report-dates-for' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/one_offs.py:14' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:
`@flow(name='my_unique_name', ...)`
warnings.warn(
/home/ec2-user/.local/share/virtualenvs/ppower-spzYstDT/lib/python3.10/site-packages/prefect/flows.py:205: UserWarning: A flow named 'remove-all-alerts-for' and defined at '/home/ec2-user/tenzinga/ppower/performance/flows/one_offs.py:36' conflicts with another flow. Consider specifying a unique `name` parameter in the flow definition:
`@flow(name='my_unique_name', ...)`
warnings.warn(
Anna Geller
Jarvis Stubblefield
12/16/2022, 3:54 PMJarvis Stubblefield
12/16/2022, 3:54 PMJarvis Stubblefield
12/16/2022, 3:54 PMKhuyen Tran
12/16/2022, 4:52 PMJarvis Stubblefield
12/16/2022, 4:53 PMJarvis Stubblefield
12/16/2022, 4:53 PM# -*- coding: utf-8
from __future__ import unicode_literals
from prefect.deployments import Deployment
from tenzinga_django_setup import prepare_django_and_paths
prepare_django_and_paths()
from ppower.performance.flows import (
remove_all_alerts_for,
reset_annual_report_dates_for
)
flow_defs = [{
"flow": reset_annual_report_dates_for,
"name": "reset_annual_report_dates",
"description": "Reset annual report dates for an organization.",
"tags": ["annual_report", "reset_date"],
}, {
"flow": remove_all_alerts_for,
"name": "remove_all_alerts",
"description": "Remove all alerts for all users in an organization.",
"tags": ["alerts", "reset_alerts"],
}]
for flow_def in flow_defs:
deployment = Deployment.build_from_flow(
flow=flow_def["flow"],
name=flow_def["name"],
description=flow_def["description"],
tags=flow_def["tags"],
work_queue_name="tenzinga_django_prod",
)
deployment.apply()
Jarvis Stubblefield
12/16/2022, 4:54 PM# -*- coding: utf-8
from __future__ import unicode_literals
import datetime
from prefect import flow, task, get_run_logger
from tenzinga_django_setup import prepare_django_and_paths
prepare_django_and_paths()
from ppower.base.models import Organization
from ppower.notification.models import Notice
@flow
def reset_annual_report_dates_for(org_id, *, year: int, month: int = None, day: int = None):
today = datetime.date.today()
if year is None:
year = today.year
org = Organization.objects.get(pk=org_id)
users = org.hreuser_set.all()
for user in users:
initial_date = user.next_annual_report
if month is None:
month = initial_date.month
if day is None:
day = initial_date.day
user.next_annual_report = datetime.date(year=year, month=month, day=day)
user.save()
logger = get_run_logger()
<http://logger.info|logger.info>(f"Reset annual report dates for {len(users)} users.")
@flow
def remove_all_alerts_for(org_id: int):
org = Organization.objects.get(pk=org_id)
users = org.hreuser_set.all()
for user in users:
# Set the last_log_alert to today so they don't receive any alerts
user.last_log_alert_time = datetime.date.today()
user.save()
notices = Notice.objects.filter(user__in=users)
notices.delete()
logger = get_run_logger()
<http://logger.info|logger.info>(f"Removed {len(notices)} alerts for {len(users)} users.")
Khuyen Tran
12/16/2022, 4:59 PMJarvis Stubblefield
12/16/2022, 5:00 PMJarvis Stubblefield
12/16/2022, 5:01 PMJarvis Stubblefield
12/16/2022, 5:01 PMJarvis Stubblefield
12/16/2022, 5:01 PMJarvis Stubblefield
12/16/2022, 5:02 PMJarvis Stubblefield
12/16/2022, 5:02 PMJarvis Stubblefield
12/16/2022, 5:02 PMKhuyen Tran
12/16/2022, 5:16 PMJarvis Stubblefield
12/16/2022, 5:24 PMJarvis Stubblefield
03/27/2023, 9:26 PM