-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hive-service: Add hive.service.HiveService
- Loading branch information
Showing
21 changed files
with
106 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .restart_monitor import RestartMonitor | ||
from .service import Service as HiveService | ||
from .status import ServiceCondition, ServiceStatus |
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,60 @@ | ||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
from typing import Callable, Optional | ||
|
||
from hive.common import ArgumentParser | ||
from hive.common.functools import once | ||
from hive.messaging import ( | ||
Channel, | ||
Connection, | ||
blocking_connection, | ||
publisher_connection, | ||
) | ||
|
||
from .restart_monitor import RestartMonitor | ||
|
||
|
||
@dataclass | ||
class Service(ABC): | ||
argument_parser: Optional[ArgumentParser] = None | ||
on_channel_open: Optional[Callable[[Channel], None]] = None | ||
|
||
def make_argument_parser(self) -> ArgumentParser: | ||
parser = ArgumentParser() | ||
parser.add_argument( | ||
"--no-monitor", | ||
dest="with_restart_monitor", | ||
action="store_false", | ||
help="run without restart monitoring", | ||
) | ||
return parser | ||
|
||
def __post_init__(self): | ||
if not self.argument_parser: | ||
self.argument_parser = self.make_argument_parser() | ||
self.args = self.argument_parser.parse_args() | ||
|
||
if getattr(self.args, "with_restart_monitor", True): | ||
rsm = RestartMonitor() | ||
if self.on_channel_open: | ||
raise NotImplementedError | ||
self.on_channel_open = once(rsm.report_via_channel) | ||
|
||
@classmethod | ||
def main(cls, **kwargs): | ||
service = cls(**kwargs) | ||
return service.run() | ||
|
||
@abstractmethod | ||
def run(self): | ||
raise NotImplementedError | ||
|
||
def blocking_connection(self, **kwargs) -> Connection: | ||
return self._connect(blocking_connection, kwargs) | ||
|
||
def publisher_connection(self, **kwargs) -> Connection: | ||
return self._connect(publisher_connection, kwargs) | ||
|
||
def _connect(self, connect, kwargs) -> Connection: | ||
on_channel_open = kwargs.get("on_channel_open", self.on_channel_open) | ||
return connect(on_channel_open=on_channel_open, **kwargs) |
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ classifiers = [ | |
] | ||
dependencies = [ | ||
"hive-common", | ||
"hive-messaging", | ||
] | ||
|
||
[project.urls] | ||
|
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
-r ../../requirements.txt | ||
-e ../common | ||
-e ../messaging |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .main import main | ||
from .service import Service | ||
|
||
main = Service.main |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .main import main | ||
from .service import Service | ||
|
||
main = Service.main |
This file was deleted.
Oops, something went wrong.
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
4 changes: 3 additions & 1 deletion
4
services/reading-list-updater/hive/reading_list_updater/__init__.py
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .main import main | ||
from .service import Service | ||
|
||
main = Service.main |
13 changes: 0 additions & 13 deletions
13
services/reading-list-updater/hive/reading_list_updater/main.py
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .main import main | ||
from .service import Service | ||
|
||
main = Service.main |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .main import main | ||
from .service import Service | ||
|
||
main = Service.main |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.