-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Polished and modernised agent service ⚠️ (#6452)
Co-authored-by: Andrei Neagu <[email protected]>
- Loading branch information
Showing
79 changed files
with
1,846 additions
and
2,207 deletions.
There are no files selected for viewing
File renamed without changes.
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
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/agent/errors.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from pydantic.errors import PydanticErrorMixin | ||
|
||
|
||
class BaseAgentRPCError(PydanticErrorMixin, Exception): | ||
... | ||
|
||
|
||
class NoServiceVolumesFoundRPCError(BaseAgentRPCError): | ||
msg_template: str = ( | ||
"Could not detect any unused volumes after waiting '{period}' seconds for " | ||
"volumes to be released after closing all container for service='{node_id}'" | ||
) |
57 changes: 57 additions & 0 deletions
57
packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/agent/volumes.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
from datetime import timedelta | ||
from typing import Final | ||
|
||
from models_library.projects_nodes_io import NodeID | ||
from models_library.rabbitmq_basic_types import RPCMethodName, RPCNamespace | ||
from pydantic import NonNegativeInt, parse_obj_as | ||
from servicelib.logging_utils import log_decorator | ||
from servicelib.rabbitmq import RabbitMQRPCClient | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
_REQUEST_TIMEOUT: Final[NonNegativeInt] = int(timedelta(minutes=60).total_seconds()) | ||
|
||
|
||
@log_decorator(_logger, level=logging.DEBUG) | ||
async def remove_volumes_without_backup_for_service( | ||
rabbitmq_rpc_client: RabbitMQRPCClient, | ||
*, | ||
docker_node_id: str, | ||
swarm_stack_name: str, | ||
node_id: NodeID, | ||
) -> None: | ||
result = await rabbitmq_rpc_client.request( | ||
RPCNamespace.from_entries( | ||
{ | ||
"service": "agent", | ||
"docker_node_id": docker_node_id, | ||
"swarm_stack_name": swarm_stack_name, | ||
} | ||
), | ||
parse_obj_as(RPCMethodName, "remove_volumes_without_backup_for_service"), | ||
node_id=node_id, | ||
timeout_s=_REQUEST_TIMEOUT, | ||
) | ||
assert result is None # nosec | ||
|
||
|
||
@log_decorator(_logger, level=logging.DEBUG) | ||
async def backup_and_remove_volumes_for_all_services( | ||
rabbitmq_rpc_client: RabbitMQRPCClient, | ||
*, | ||
docker_node_id: str, | ||
swarm_stack_name: str, | ||
) -> None: | ||
result = await rabbitmq_rpc_client.request( | ||
RPCNamespace.from_entries( | ||
{ | ||
"service": "agent", | ||
"docker_node_id": docker_node_id, | ||
"swarm_stack_name": swarm_stack_name, | ||
} | ||
), | ||
parse_obj_as(RPCMethodName, "backup_and_remove_volumes_for_all_services"), | ||
timeout_s=_REQUEST_TIMEOUT, | ||
) | ||
assert result is None # nosec |
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 @@ | ||
0.0.1 | ||
1.0.0 |
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
Oops, something went wrong.