-
Notifications
You must be signed in to change notification settings - Fork 943
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-changelog
- Loading branch information
Showing
5 changed files
with
174 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 Flower Labs GmbH. All Rights Reserved. | ||
# | ||
# 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. | ||
# ============================================================================== | ||
"""Utility functions for State.""" | ||
|
||
|
||
import time | ||
from logging import ERROR | ||
from uuid import uuid4 | ||
|
||
from flwr.common import log | ||
from flwr.common.constant import ErrorCode | ||
from flwr.proto.error_pb2 import Error # pylint: disable=E0611 | ||
from flwr.proto.node_pb2 import Node # pylint: disable=E0611 | ||
from flwr.proto.task_pb2 import Task, TaskIns, TaskRes # pylint: disable=E0611 | ||
|
||
NODE_UNAVAILABLE_ERROR_REASON = ( | ||
"Error: Node Unavailable - The destination node is currently unavailable. " | ||
"It exceeds the time limit specified in its last ping." | ||
) | ||
|
||
|
||
def make_node_unavailable_taskres(ref_taskins: TaskIns) -> TaskRes: | ||
"""Generate a TaskRes with a node unavailable error from a TaskIns.""" | ||
current_time = time.time() | ||
ttl = ref_taskins.task.ttl - (current_time - ref_taskins.task.created_at) | ||
if ttl < 0: | ||
log(ERROR, "Creating TaskRes for TaskIns that exceeds its TTL.") | ||
ttl = 0 | ||
return TaskRes( | ||
task_id=str(uuid4()), | ||
group_id=ref_taskins.group_id, | ||
run_id=ref_taskins.run_id, | ||
task=Task( | ||
producer=Node(node_id=ref_taskins.task.consumer.node_id, anonymous=False), | ||
consumer=Node(node_id=ref_taskins.task.producer.node_id, anonymous=False), | ||
created_at=current_time, | ||
ttl=ttl, | ||
ancestry=[ref_taskins.task_id], | ||
task_type=ref_taskins.task.task_type, | ||
error=Error( | ||
code=ErrorCode.NODE_UNAVAILABLE, reason=NODE_UNAVAILABLE_ERROR_REASON | ||
), | ||
), | ||
) |