-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from flyingcircusio/PL-129777-agent-maintenan…
…ce-scheduling fc-agent: improve maintenance scheduling
- Loading branch information
Showing
45 changed files
with
2,612 additions
and
1,320 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""Scheduled machine reboot. | ||
This activity does nothing if the machine has been booted for another reason in | ||
the time between creation and execution. | ||
""" | ||
|
||
from typing import Union | ||
|
||
import structlog | ||
|
||
from ..estimate import Estimate | ||
from . import Activity, ActivityMergeResult, RebootType | ||
|
||
_log = structlog.get_logger() | ||
|
||
|
||
class RebootActivity(Activity): | ||
estimate = Estimate("5m") | ||
|
||
def __init__( | ||
self, action: Union[str, RebootType] = RebootType.WARM, log=_log | ||
): | ||
super().__init__() | ||
self.set_up_logging(log) | ||
self.reboot_needed = RebootType(action) | ||
|
||
@property | ||
def comment(self): | ||
return "Scheduled {}".format( | ||
"cold boot" if self.reboot_needed == RebootType.COLD else "reboot" | ||
) | ||
|
||
def merge(self, other): | ||
if not isinstance(other, RebootActivity): | ||
self.log.debug( | ||
"merge-incompatible-skip", | ||
self_type=type(self), | ||
other_type=type(other), | ||
) | ||
return ActivityMergeResult() | ||
|
||
if self.reboot_needed == other.reboot_needed: | ||
self.log.debug("merge-reboot-identical") | ||
return ActivityMergeResult(self, is_effective=True) | ||
|
||
if ( | ||
self.reboot_needed == RebootType.COLD | ||
and other.reboot_needed == RebootType.WARM | ||
): | ||
self.log.debug( | ||
"merge-reboot-cold-warm", | ||
help=( | ||
"merging a warm reboot into a cold reboot results in a " | ||
"cold reboot." | ||
), | ||
) | ||
return ActivityMergeResult(self, is_effective=True) | ||
|
||
if ( | ||
self.reboot_needed == RebootType.WARM | ||
and other.reboot_needed == RebootType.COLD | ||
): | ||
self.log.debug( | ||
"merge-reboot-warm-to-cold", | ||
help=( | ||
"merging a cold reboot into a warm reboot results in a " | ||
"cold reboot. This is a significant change." | ||
), | ||
) | ||
return ActivityMergeResult( | ||
self, | ||
is_effective=True, | ||
is_significant=True, | ||
changes={"before": RebootType.WARM, "after": RebootType.COLD}, | ||
) |
Oops, something went wrong.