From 9f982e175c9b101b960761235d6c94ec6474be88 Mon Sep 17 00:00:00 2001 From: Roland DENIS Date: Mon, 14 Mar 2022 11:23:56 +0100 Subject: [PATCH] Avoiding multiple job offer notification when rebuilding website --- utils/notify_job_offer_openshift.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/utils/notify_job_offer_openshift.py b/utils/notify_job_offer_openshift.py index e7870b63..c8d750bc 100644 --- a/utils/notify_job_offer_openshift.py +++ b/utils/notify_job_offer_openshift.py @@ -127,8 +127,10 @@ def send_email(job_id=None, notifier=None, recipient_email=None, publisher=None) smtpObj = smtplib.SMTP(SMTP_SERVER) smtpObj.sendmail(SENDER_MAIL, msg['To'], msg.as_string()) print("Successfully sent email") + return True except SMTPException: print("Error: unable to send email") + return False def main(): repo = git.Repo(GIT_REPO) @@ -139,7 +141,18 @@ def main(): job_id = m.group(1) publisher = commit.author.name - send_email(job_id=job_id, notifier=AuthorMessage, publisher=publisher) + # Sending notification only once + website_path = os.environ['WEBSITE'] + notified_path = os.path.join(website_path, "content", "job_offers", "notified") + notified_file = os.path.join(notified_path, f"job_{job_id}.md") + os.makedirs(notified_path, exist_ok=True) + if os.path.exists(notified_file): + print("Notification already sent!") + else: + success = send_email(job_id=job_id, notifier=AuthorMessage, publisher=publisher) + if success: + from pathlib import Path + Path(notified_file).touch() if __name__ == '__main__': -- GitLab