feat(api): refactored weekly report
This commit is contained in:
parent
8f0524a2f6
commit
6b6f23f39d
3 changed files with 14 additions and 28 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
from chalicelib.utils import pg_client, helper
|
from chalicelib.utils import pg_client, helper, email_helper
|
||||||
from chalicelib.utils.TimeUTC import TimeUTC
|
from chalicelib.utils.TimeUTC import TimeUTC
|
||||||
from decouple import config
|
|
||||||
from chalicelib.utils.helper import get_issue_title
|
from chalicelib.utils.helper import get_issue_title
|
||||||
|
|
||||||
LOWEST_BAR_VALUE = 3
|
LOWEST_BAR_VALUE = 3
|
||||||
|
|
@ -30,7 +29,7 @@ def edit_config(user_id, weekly_report):
|
||||||
|
|
||||||
|
|
||||||
def cron():
|
def cron():
|
||||||
with pg_client.PostgresClient() as cur:
|
with pg_client.PostgresClient(long_query=True) as cur:
|
||||||
params = {"3_days_ago": TimeUTC.midnight(delta_days=-3),
|
params = {"3_days_ago": TimeUTC.midnight(delta_days=-3),
|
||||||
"1_week_ago": TimeUTC.midnight(delta_days=-7),
|
"1_week_ago": TimeUTC.midnight(delta_days=-7),
|
||||||
"2_week_ago": TimeUTC.midnight(delta_days=-14),
|
"2_week_ago": TimeUTC.midnight(delta_days=-14),
|
||||||
|
|
@ -83,6 +82,7 @@ def cron():
|
||||||
) AS month_1_issues ON (TRUE)
|
) AS month_1_issues ON (TRUE)
|
||||||
WHERE projects.deleted_at ISNULL;"""), params)
|
WHERE projects.deleted_at ISNULL;"""), params)
|
||||||
projects_data = cur.fetchall()
|
projects_data = cur.fetchall()
|
||||||
|
emails_to_send = []
|
||||||
for p in projects_data:
|
for p in projects_data:
|
||||||
params["project_id"] = p["project_id"]
|
params["project_id"] = p["project_id"]
|
||||||
print(f"checking {p['project_name']} : {p['project_id']}")
|
print(f"checking {p['project_name']} : {p['project_id']}")
|
||||||
|
|
@ -227,13 +227,14 @@ def cron():
|
||||||
if j["type"] in keep_types:
|
if j["type"] in keep_types:
|
||||||
keep.append(j)
|
keep.append(j)
|
||||||
i["partition"] = keep
|
i["partition"] = keep
|
||||||
helper.async_post(config('email_funnel') % "weekly_report2",
|
emails_to_send.append({"email": p.pop("emails"),
|
||||||
{"email": p.pop("emails"),
|
"data": {
|
||||||
"data": {
|
**p,
|
||||||
**p,
|
"days_partition": days_partition,
|
||||||
"days_partition": days_partition,
|
"issues_by_type": issues_by_type,
|
||||||
"issues_by_type": issues_by_type,
|
"issues_breakdown_by_day": issues_breakdown_by_day,
|
||||||
"issues_breakdown_by_day": issues_breakdown_by_day,
|
"issues_breakdown_list": issues_breakdown_list
|
||||||
"issues_breakdown_list": issues_breakdown_list
|
}})
|
||||||
}
|
print(f">>> Sending weekly report to {len(emails_to_send)} email-group")
|
||||||
})
|
for e in emails_to_send:
|
||||||
|
email_helper.weekly_report2(recipients=e["email"], data=e["data"])
|
||||||
|
|
|
||||||
|
|
@ -567,15 +567,6 @@ def async_send_signup_emails(data: schemas.EmailPayloadSchema = Body(...)):
|
||||||
email_helper.send_assign_session(recipient=data.email, link=data.link, message=data.message)
|
email_helper.send_assign_session(recipient=data.email, link=data.link, message=data.message)
|
||||||
|
|
||||||
|
|
||||||
# TODO: transform this to a background task when you find a way to run it without an attached request
|
|
||||||
@public_app.post('/async/funnel/weekly_report2', tags=["async mail"])
|
|
||||||
def async_weekly_report(data: schemas.WeeklyReportPayloadSchema = Body(...)):
|
|
||||||
print("=========================> Sending weekly report")
|
|
||||||
if data.auth != config("async_Token"):
|
|
||||||
return {}
|
|
||||||
email_helper.weekly_report2(recipients=data.email, data=data.data)
|
|
||||||
|
|
||||||
|
|
||||||
# @public_app.post('/async/basic/member_invitation', tags=["async mail"])
|
# @public_app.post('/async/basic/member_invitation', tags=["async mail"])
|
||||||
# def async_basic_emails(data: schemas.MemberInvitationPayloadSchema = Body(...)):
|
# def async_basic_emails(data: schemas.MemberInvitationPayloadSchema = Body(...)):
|
||||||
# if data.auth != config("async_Token"):
|
# if data.auth != config("async_Token"):
|
||||||
|
|
|
||||||
|
|
@ -256,12 +256,6 @@ class EmailPayloadSchema(BaseModel):
|
||||||
message: str = Field(...)
|
message: str = Field(...)
|
||||||
|
|
||||||
|
|
||||||
class WeeklyReportPayloadSchema(BaseModel):
|
|
||||||
auth: str = Field(...)
|
|
||||||
email: EmailStr = Field(...)
|
|
||||||
data: dict = Field(...)
|
|
||||||
|
|
||||||
|
|
||||||
class MemberInvitationPayloadSchema(BaseModel):
|
class MemberInvitationPayloadSchema(BaseModel):
|
||||||
auth: str = Field(...)
|
auth: str = Field(...)
|
||||||
email: EmailStr = Field(...)
|
email: EmailStr = Field(...)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue