Commit 91385fb7 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

move retry to utils

parent 5f412905
Pipeline #2595 running with stage
...@@ -10,11 +10,13 @@ Modified-History: ...@@ -10,11 +10,13 @@ Modified-History:
2023-12-15, Bo Zhang, add module header 2023-12-15, Bo Zhang, add module header
""" """
from .decorator import parameterized_module_decorator
from .file import File from .file import File
from .pipeline import Pipeline from .pipeline import Pipeline
from .status import CsstResult, CsstStatus from .status import CsstResult, CsstStatus
from .time import now from .time import now
from .dfs import DFS
from .ccds import CCDS
from .utils import retry
__version__ = "0.0.2" __version__ = "0.0.2"
...@@ -22,5 +24,4 @@ __all__ = [ ...@@ -22,5 +24,4 @@ __all__ = [
"Pipeline", "Pipeline",
"File", "File",
"CsstResult", "CsstResult",
"parameterized_module_decorator",
] ]
...@@ -97,29 +97,6 @@ class CCDS: ...@@ -97,29 +97,6 @@ class CCDS:
# 'ledflat': '/ccds_root/references/msc/csst_msc_ms_ledflat_10_000001.fits'} # 'ledflat': '/ccds_root/references/msc/csst_msc_ms_ledflat_10_000001.fits'}
return refs_fp return refs_fp
@staticmethod
def retry(func, n, *args, **kwargs):
for attempt in range(1, n + 1):
try:
res = func(*args, **kwargs)
# assert res["code"] == 0, res
return res
except BaseException as e:
print(f"Error occurs: {e.__repr__()}")
raise RuntimeError(f"All {n} attempts failed.")
def retry(func, n=3):
@functools.wraps(func)
def wrapper(*args, **kwargs):
for attempt in range(1, n + 1):
try:
result = func(*args, **kwargs)
return result
except Exception as e:
print(f"尝试 {attempt}/{n} 失败: {e}")
raise RuntimeError("All attempts failed.")
""" """
file_path="/dfsroot/L0/MSC/SCIE/62030/10160000105/MS/CSST_MSC_MS_SCIE_20280916072059_20280916072329_10160000105_10_L0_V01.fits" file_path="/dfsroot/L0/MSC/SCIE/62030/10160000105/MS/CSST_MSC_MS_SCIE_20280916072059_20280916072329_10160000105_10_L0_V01.fits"
......
...@@ -25,16 +25,6 @@ class DFS: ...@@ -25,16 +25,6 @@ class DFS:
def __init__(self, n_try=5): def __init__(self, n_try=5):
self.n_try = n_try self.n_try = n_try
def retry(self, func, *args, **kwargs):
for attempt in range(self.n_try):
try:
res = func(*args, **kwargs)
assert res["code"] == 0, res
return res
except BaseException as e:
print(f"Error occurs: {e.__repr__()}")
raise RuntimeError("All attempts failed.")
# DFS APIs # DFS APIs
@property @property
def L0DataApi(self): def L0DataApi(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment