change max duration to 10 years
This commit is contained in:
parent
5ed5a4aa08
commit
a1f701d2ba
2 changed files with 9 additions and 9 deletions
|
@ -16,6 +16,8 @@ from matrix_alertbot.errors import (
|
||||||
SilenceNotFoundError,
|
SilenceNotFoundError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
MAX_DURATION_DAYS = 3652
|
||||||
|
|
||||||
|
|
||||||
class AlertmanagerClient:
|
class AlertmanagerClient:
|
||||||
def __init__(self, url: str, cache: Cache) -> None:
|
def __init__(self, url: str, cache: Cache) -> None:
|
||||||
|
@ -69,14 +71,12 @@ class AlertmanagerClient:
|
||||||
]
|
]
|
||||||
|
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
if duration_seconds is None:
|
max_duration = timedelta(days=MAX_DURATION_DAYS)
|
||||||
end_time = datetime.max
|
if duration_seconds is None or duration_seconds > max_duration.total_seconds():
|
||||||
|
end_time = start_time + max_duration
|
||||||
elif duration_seconds > 0:
|
elif duration_seconds > 0:
|
||||||
try:
|
|
||||||
duration_delta = timedelta(seconds=duration_seconds)
|
duration_delta = timedelta(seconds=duration_seconds)
|
||||||
end_time = start_time + duration_delta
|
end_time = start_time + duration_delta
|
||||||
except OverflowError:
|
|
||||||
end_time = datetime.max
|
|
||||||
else:
|
else:
|
||||||
raise InvalidDurationError(f"Duration must be positive: {duration_seconds}")
|
raise InvalidDurationError(f"Duration must be positive: {duration_seconds}")
|
||||||
|
|
||||||
|
|
|
@ -427,7 +427,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
|
||||||
],
|
],
|
||||||
"createdBy": "user",
|
"createdBy": "user",
|
||||||
"startsAt": "1970-01-01T00:00:00",
|
"startsAt": "1970-01-01T00:00:00",
|
||||||
"endsAt": "9999-12-31T23:59:59.999999",
|
"endsAt": "1980-01-01T00:00:00",
|
||||||
"comment": "Acknowledge alert from Matrix",
|
"comment": "Acknowledge alert from Matrix",
|
||||||
},
|
},
|
||||||
silence,
|
silence,
|
||||||
|
@ -461,7 +461,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
|
||||||
],
|
],
|
||||||
"createdBy": "user",
|
"createdBy": "user",
|
||||||
"startsAt": "1970-01-01T00:00:00",
|
"startsAt": "1970-01-01T00:00:00",
|
||||||
"endsAt": "9999-12-31T23:59:59.999999",
|
"endsAt": "1980-01-01T00:00:00",
|
||||||
"comment": "Acknowledge alert from Matrix",
|
"comment": "Acknowledge alert from Matrix",
|
||||||
},
|
},
|
||||||
silence,
|
silence,
|
||||||
|
|
Loading…
Reference in a new issue