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

Add retry logic for database and broker connections #12

Merged
merged 7 commits into from
Aug 30, 2024

Conversation

jmborr
Copy link
Member

@jmborr jmborr commented Aug 28, 2024

Description of the changes

When testfixture01 is deployed in the test environment of webmonchow, there's no guarantee that neither the AMQ broker or the Webmon database servers have deployed. Because of this reason, webmonchow will retry (every 5 seconds by default) to connect to these services, in the hope that they will eventually run.

Check all that apply:

  • added release notes (if not, provide an explanation in the work description)
  • updated documentation
  • Source added/refactored
  • Added unit tests
  • Added integration tests

References:

Manual test for the reviewer

Deploy WebMon locally in your machine, but edit Dockerfile.webmonchow so that instead of using the webmonchow conda package, it will use the webmonchow feature branch relentless_attempt_db_connection. The edited Dockerfile:

# Miniconda with native Python 3.10
FROM continuumio/miniconda3:23.3.1-0
RUN conda install --yes -n base conda-libmamba-solver

# Install webmonchow
#RUN conda install --yes --solver=libmamba -n base -c conda-forge -c neutrons postgresql=14 webmonchow=1.0.0

# Install webmonchow from a feature branch (only to test the latest changes in webmonchow)
RUN conda install --yes --solver=libmamba -n base -c conda-forge postgresql=14
RUN python -m pip install git+https://github.com/neutrons/webmonchow.git@relentless_attempt_db_connection#egg=webmonchow

# Start the AMQ and PV generators when starting the container
CMD ["sh", "-c", "broadcast_pv & broadcast_amq --broker \"activemq:61613\" & wait"]

Check list for the reviewer

  • release notes updated, or an explanation is provided as to why release notes are unnecessary
  • best software practices
    • clearly named variables (better to be verbose in variable names)
    • code comments explaining the intent of code blocks
  • All the tests are passing
  • The documentation is up to date
  • code comments added when explaining intent

Enhanced `connect_to_database` and `connect_to_broker` functions to include retry logic with specified attempts and intervals. Updated corresponding unit tests to verify the new functionality and handle connection failures gracefully.

Signed-off-by: Jose Borreguero <[email protected]>
@jmborr jmborr self-assigned this Aug 28, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.95%. Comparing base (f6940da) to head (2a357c9).

Additional details and impacted files
@@            Coverage Diff             @@
##             next      #12      +/-   ##
==========================================
+ Coverage   89.51%   92.95%   +3.44%     
==========================================
  Files           3        3              
  Lines         124      142      +18     
==========================================
+ Hits          111      132      +21     
+ Misses         13       10       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmborr jmborr requested a review from backmari August 28, 2024 19:52
Added print statements to log successful connections in both PostgreSQL and broker connection attempts. This will aid in debugging and confirming when connections are successfully established.

Signed-off-by: Jose Borreguero <[email protected]>
Introduce deployment workflow section in the docs with an accompanying image. This includes details on deploying Webmonchow as a service in a Docker container environment.

Signed-off-by: Jose Borreguero <[email protected]>
Update the documentation to include specific URLs for the local and test environments of the Web Monitor application. This provides clearer guidance on accessing the Webmonchow service in different deployment contexts.

Signed-off-by: Jose Borreguero <[email protected]>
Removed unnecessary reassignment of 'conn' in the connection attempt loop. This change cleans up the code by ensuring 'conn' is only connected without reassigning it unnecessarily.

Signed-off-by: Jose Borreguero <[email protected]>
@backmari
Copy link

Local deployment of WebMon pointing to webmonchow in this branch works as expected. The instruments PV:s are being updated and DASMON status is green.
image
image

Copy link

@backmari backmari left a comment

Choose a reason for hiding this comment

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

Good addition with retry logic 🙌

@jmborr jmborr merged commit 6d92150 into next Aug 30, 2024
1 check passed
@jmborr
Copy link
Member Author

jmborr commented Aug 30, 2024

@backmari thanks for the review!

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.

3 participants