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
Create base Daemon class and refactor Undertaker, Reaper, Abacus Account and Judge Repairer daemons to inherit from base class #6489
Open
rdimaio
wants to merge
5
commits into
rucio:master
Choose a base branch
from
rdimaio:patch-6478-daemon-refactor-undertaker
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
90e3fb8
Daemons: Create base Daemon class and refactor Undertaker to inherit …
rdimaio e404635
Daemons: Refactor Reaper to inherit from base Daemon class; #6478
rdimaio fa57fcf
Daemons: Refactor Judge Repairer to inherit from Daemon base class; #…
rdimaio fe86b52
Daemons: Refactor Abacus Account to inherit from base Daemon class; r…
rdimaio 91599a5
Daemons: Fix graceful stop logic
rdimaio File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright European Organization for Nuclear Research (CERN) since 2012 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from rucio.daemons.common import Daemon, HeartbeatHandler | ||
from rucio.common.utils import get_thread_with_periodic_running_function | ||
from rucio.core.account_counter import fill_account_counter_history_table | ||
import logging | ||
import threading | ||
from typing import Any | ||
from abc import abstractmethod | ||
|
||
ABACUS_HISTORY_TABLE_INTERVAL = 3600 | ||
|
||
|
||
class AbacusDaemon(Daemon): | ||
""" | ||
Common daemon logic for multiple Abacus daemons. | ||
""" | ||
def __init__(self, fill_history_table: bool = False, **_kwargs) -> None: | ||
f""" | ||
:param fill_history_table: Set to True to record account usage into history table every {ABACUS_HISTORY_TABLE_INTERVAL} seconds. | ||
""" | ||
super().__init__(**_kwargs) | ||
self.fill_history_table = fill_history_table | ||
self.paused_dids = {} | ||
|
||
@abstractmethod | ||
def _run_once( | ||
self, heartbeat_handler: "HeartbeatHandler", **_kwargs | ||
) -> tuple[bool, Any]: | ||
pass | ||
|
||
def run(self) -> None: | ||
self._pre_run_checks() | ||
|
||
if self.once: | ||
logging.info("%s: executing one iteration only", self.daemon_name) | ||
self._call_daemon() | ||
else: | ||
logging.info("%s: starting threads", self.daemon_name) | ||
thread_list = [threading.Thread(target=self._call_daemon) for _ in | ||
range(0, self.total_workers)] | ||
if self.fill_history_table: | ||
thread_list.append(get_thread_with_periodic_running_function(ABACUS_HISTORY_TABLE_INTERVAL, fill_account_counter_history_table, self.graceful_stop)) | ||
[t.start() for t in thread_list] | ||
logging.info("%s: waiting for interrupts", self.daemon_name) | ||
# Interruptible joins require a timeout. | ||
while thread_list: | ||
thread_list = [ | ||
thread.join(timeout=3.14) | ||
for thread in thread_list | ||
if thread and thread.is_alive() | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this try except is not needed