Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email notification when lease starts or ends soon #150

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

DanNiESh
Copy link
Contributor

@DanNiESh DanNiESh commented Dec 11, 2023

Closes: #149

@larsks
Copy link
Member

larsks commented Dec 12, 2023

You should update your commit message and the PR description to include a link to the issue with which it is associated. This will update the issue to include a link to the commit (for mention in the commit message) and to this PR (for the mention in the PR description).

It's generally good practice for your commit message to provide some context for the changes.

If you write something like:

Closes: https://github.com/CCI-MOC/esi-leap/issues/149

Then the referenced issue will be closed automatically when this PR merges. If the PR and the issue are in the same repository, you can write:

Closes: #149

@DanNiESh
Copy link
Contributor Author

You should update your commit message and the PR description to include a link to the issue with which it is associated. This will update the issue to include a link to the commit (for mention in the commit message) and to this PR (for the mention in the PR description).

It's generally good practice for your commit message to provide some context for the changes.

If you write something like:

Closes: https://github.com/CCI-MOC/esi-leap/issues/149

Then the referenced issue will be closed automatically when this PR merges. If the PR and the issue are in the same repository, you can write:

Closes: #149

Thank you for your advice! I've updated PR description as well as commit message with a link to the issue.

@tzumainn
Copy link
Contributor

@DanNiESh this looks pretty good - I think optimally we don't run openstack commands on the command line, but I think that can be updated later once the ESI commands get an SDK.

Can you add some comments to the top of the file explaining how to run the script?

@DanNiESh
Copy link
Contributor Author

@DanNiESh this looks pretty good - I think optimally we don't run openstack commands on the command line, but I think that can be updated later once the ESI commands get an SDK.

Can you add some comments to the top of the file explaining how to run the script?

Done!

Copy link
Contributor

@tzumainn tzumainn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor text changes!

bin/query_events.py Outdated Show resolved Hide resolved
email_body_lease_expire = f"Hi {lease['Project']}," \
f"\n\n" \
f"We would like to inform you that" \
f" your lease: {lease['UUID']} " \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the node UUID and name as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esi lease lease command doesn't have an output of node uuid. Do we want to make another call to retrieve node uuid?

bin/query_events.py Outdated Show resolved Hide resolved
@DanNiESh
Copy link
Contributor Author

I've updated the content of email body and provided external email templates for the script.

@larsks
Copy link
Member

larsks commented Dec 14, 2023

I would expect this script to live in the esi_leap package directory, and to have it installed via an entry in the [entry_points] section of setup.cfg.

The default template files should live in the package directory as well (e.g., in esi_leap/templates), and you would load them from there using the importlib.resources module:

import importlib.resources

lease_expire_template = importlib.resources.files("esi_leap") / "templates" / "lease_expire_email.txt"
template_text = lease_expire_template.read_text()

You could also generate the path like this:

lease_expire_template = importlib.resources.files("esi_leap").joinpath("templates/lease_expire_email.txt")

Rather than hardcoding the package name, you could ask for __name__.split('.')[0]

(You will still want to support using alternate templates using the LEASE_CREATE_TEMPLATE and LEASE_EXPIRE_TEMPLATE environment variables.)

@DanNiESh DanNiESh force-pushed the email_notification branch 2 times, most recently from 053442c to b1b5668 Compare December 14, 2023 20:20
@DanNiESh
Copy link
Contributor Author

updated the endpoint name to esi-leap-email-notification

- LEASE_EXPIRE_TEMPLATE: Path to the email template for lease expiration
warnings. Default is esi_leap/templates/lease_expire_email.txt

After esi-leap package is installed, run `esi_leap_query_events`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you run esi-leap-email-notification instead? I might mention that the script would be run periodically as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script itself doesn't have scheduling mechanism. But we can make it a cronjob to run periodically. Just add the command esi-leap-email-notification in a crontab file and specify a frequency would work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sorry, I was unclear - the documentation should be updated to say "run esi-leap-email-notification" instead of "esi_leap_query_events", right? And I think the documentation should tell the operator to set up a periodic cron job rather than just running it once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! I just added this instruction in the documentation.

@tzumainn
Copy link
Contributor

Looks good - thanks!

@tzumainn tzumainn merged commit bb1fbad into CCI-MOC:master Feb 14, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create email notifications when a lease is close to expiration
3 participants