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

Log and cache OSJobsRepository #27

Merged
merged 3 commits into from
Jan 9, 2025
Merged

Conversation

iaindillingham
Copy link
Member

For convenience, we add structlog as a requirement and then use it to log calls within app/measures.py that cross system boundaries. We then cache the repository, making it globally available.

It's worth checking out d627c23, switching between measures in the dashboard, and observing the logs. Then checkout 8153638 (HEAD), and observe the logs again.

I wouldn't say any of ☝🏻 is strictly necessary, but it helped me understand more about Streamlit's execution model. It might help you too 🙂

[structlog][] is simple. Much simpler than the standard library's
`logging` module.

[structlog]: https://www.structlog.org/
We focus on logging calls that cross system boundaries.
We use [`cache_resource`][1] to cache the repository, making it globally
available: that is, across all users, sessions, and reruns. Notice that
with this commit, a `Measure` is initialised once, and the instance is
then reused when the dashboard changes. Previously, a `Measure` was
initialised each time the dashboard changed.

Notice that `get_repository` allows us to maintain the separation
between the presentation (application) layer and the repository. We
don't want to see `import streamlit` in `app/measures.py`!

[1]: https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource
@iaindillingham iaindillingham self-assigned this Jan 8, 2025
@iaindillingham iaindillingham merged commit ea000e1 into main Jan 9, 2025
1 check passed
@iaindillingham iaindillingham deleted the iaindillingham/log-and-cache branch January 9, 2025 12:19
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.

2 participants