-
Notifications
You must be signed in to change notification settings - Fork 140
Moves API heartbeat to it's own thread. #7331
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixed bug where API process would miss heartbeats during long uploads. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |||||
| from logging import getLogger | ||||||
| import os | ||||||
| import sys | ||||||
| import threading | ||||||
| import time | ||||||
|
|
||||||
| import click | ||||||
| import django | ||||||
|
|
@@ -22,9 +24,18 @@ | |||||
|
|
||||||
|
|
||||||
| class PulpApiWorker(SyncWorker): | ||||||
|
|
||||||
| def __init__(self, *args, **kwargs): | ||||||
| super().__init__(*args, **kwargs) | ||||||
| self.heartbeat_thread = None | ||||||
|
|
||||||
| def notify(self): | ||||||
| super().notify() | ||||||
| self.heartbeat() | ||||||
|
|
||||||
| def _heartbeat_loop(self): | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the thread dies? |
||||||
| while self.alive: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this for? |
||||||
| self.heartbeat() | ||||||
| time.sleep(self.heartbeat_interval) | ||||||
|
|
||||||
| def heartbeat(self): | ||||||
| try: | ||||||
|
|
@@ -76,6 +87,13 @@ def init_process(self): | |||||
| logger.error(f"An API app with name {self.name} already exists in the database.") | ||||||
| exit(Arbiter.WORKER_BOOT_ERROR) | ||||||
|
|
||||||
| # Store heartbeat interval for the heartbeat thread | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
:mild sarcasm: |
||||||
| self.heartbeat_interval = settings.API_APP_TTL // 3 | ||||||
|
|
||||||
| # Start heartbeat thread before entering the main loop | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now why don't we then put all of that stuff right before entering the main loop? |
||||||
| self.heartbeat_thread = threading.Thread(target=self._heartbeat_loop, daemon=True) | ||||||
| self.heartbeat_thread.start() | ||||||
|
|
||||||
| super().init_process() | ||||||
|
|
||||||
| def run(self): | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First i thought, this is dead code. Now i think we have the opportunity to check in on the thread here.