Skip to content

Commit

Permalink
Tidy up serialization-related code
Browse files Browse the repository at this point in the history
* Remove an unused instance of `ComputeSerializer`
* Remove the `check` method from `SerializeBase`
* Reorder the `DeserializationError` class so that it's next to
  `SerializationError`
* Remove redundant `__repr__` methods in serialization error classes
* Sync `SerializationError`'s `__repr__` with `DeserializationError`'s
* Fix a typo
  • Loading branch information
chris-janidlo committed May 8, 2023
1 parent e700ac9 commit 151ebe0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
)
from globus_compute_endpoint.executors.high_throughput.worker_map import WorkerMap
from globus_compute_endpoint.logging_config import ComputeLogger, setup_logging
from globus_compute_sdk.serialize import ComputeSerializer
from parsl.version import VERSION as PARSL_VERSION

RESULT_TAG = 10
Expand Down Expand Up @@ -241,7 +240,6 @@ def __init__(
self.heartbeat_period = heartbeat_period
self.heartbeat_threshold = heartbeat_threshold
self.poll_period = poll_period
self.serializer = ComputeSerializer()
self.next_worker_q: list[str] = [] # FIFO queue for spinning up workers.
self.worker_procs: dict[str, subprocess.Popen] = {}

Expand Down
34 changes: 10 additions & 24 deletions compute_sdk/globus_compute_sdk/serialize/base.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
from abc import ABCMeta, abstractmethod


class DeserializationError(Exception):
"""Base class for all deserialization errors"""

def __init__(self, reason):
self.reason = reason

def __repr__(self):
return f"Deserialization failed due to {self.reason}"

def __str__(self):
return self.__repr__()


class SerializeBase(metaclass=ABCMeta):
"""Shared functionality for all serializer implementations"""

Expand All @@ -37,14 +24,6 @@ def chomp(self, payload: str) -> str:
)
return payload

def check(self, payload):
try:
x = self.serialize(payload)
self.deserialize(x)

except Exception as e:
raise SerializerError(f"Serialize-Deserialize combo failed due to {e}")

@abstractmethod
def serialize(self, data):
raise NotImplementedError("Concrete class did not implement serialize")
Expand All @@ -58,8 +37,15 @@ class SerializerError:
def __init__(self, reason):
self.reason = reason

def __str__(self):
return self.reason
def __repr__(self):
return f"Serialization failed due to {self.reason}"


class DeserializationError(Exception):
"""Base class for all deserialization errors"""

def __init__(self, reason):
self.reason = reason

def __repr__(self):
return self.__str__()
return f"Deserialization failed due to {self.reason}"
2 changes: 1 addition & 1 deletion compute_sdk/globus_compute_sdk/serialize/concretes.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def deserialize(self, payload: str, variation: int = 0):
"""
Functions are serialized using the follow methods and
the resulting encoded versions are stored. Redundancy if
one of the methods fail on deserlization, undetectable during
one of the methods fail on deserialization, undetectable during
serialization attempts previously.
Note that of the 3 categories of failures:
Expand Down

0 comments on commit 151ebe0

Please sign in to comment.