Skip to content

Commit 5ce585d

Browse files
authored
Merge pull request #123 from 2ndWatch/add/has_lag
Added lag check; Refactored time audit code to prevent repeated code
2 parents 134a42e + 8e4b04d commit 5ce585d

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SHA1 := $$(git log -1 --pretty=%h)
88
CURRENT_BRANCH := $$(git symbolic-ref -q --short HEAD)
99
LATEST_TAG := ${REPO_NAME}:latest
1010
GIT_TAG := ${REPO_NAME}:${SHA1}
11-
VERSION := v0.3.2
11+
VERSION := v0.3.3
1212

1313
info: ## Show information about the current git state.
1414
@echo "Github Project: https://github.com/${REPO_NAME}\nCurrent Branch: ${CURRENT_BRANCH}\nSHA1: ${SHA1}\n"

cloudendure/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.2"
1+
__version__ = "0.3.3"

cloudendure/cloudendure.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,16 @@ def get_machine_sync_details(self) -> Dict[Any]:
471471
}
472472
if replication_info.get("lastSeenDateTime"):
473473
response_dict[machine_id]["last_seen_utc"] = replication_info.get("lastSeenDateTime")
474+
if replication_info.get("lastConsistencyDateTime"):
475+
response_dict[machine_id]["last_consistency_utc"] = replication_info.get("lastConsistencyDateTime")
474476
# Project is still printing to console as a convention; Emitting an
475477
# output to stdout for interactive usage
476478
return response_dict
477479

478480
def inspect_ce_project(self, check_type: str) -> Dict[str, Any]:
479-
valid_check_types: List[str] = ["not_synced", "not_started", "not_current"]
481+
state_check_types: List[str] = ["not_synced", "not_started"]
482+
time_check_types: List[str] = ["not_current", "is_lagged"]
483+
valid_check_types: List[str] = state_check_types + time_check_types
480484
if check_type not in valid_check_types:
481485
print(
482486
f'ERROR: Unknown check_type of "{check_type}"; Please use a valid check_type: [ {", ".join(valid_check_types)} ] ...'
@@ -485,9 +489,15 @@ def inspect_ce_project(self, check_type: str) -> Dict[str, Any]:
485489
result: Dict[str, Any] = {}
486490
sync_report: Dict[str, Any] = self.get_machine_sync_details()
487491
print(f"INFO: Using check '{check_type}' on Project: ({self.project_name})")
488-
inspector = getattr(self, check_type)
492+
if check_type in state_check_types:
493+
inspector1 = getattr(self, check_type)
494+
else:
495+
inspector2 = getattr(self, "time_delta_context")
489496
for item in sync_report.keys():
490-
mcheck = inspector(machine=sync_report[item])
497+
if inspector2:
498+
mcheck = inspector2(machine=sync_report[item], check_type=check_type)
499+
else:
500+
mcheck = inspector1(machine=sync_report[item])
491501
if mcheck:
492502
result[item] = sync_report[item]
493503
print(f"INFO: Check '{check_type}' completed; {len(result)} machines matched in Project: ({self.project_name})")
@@ -505,15 +515,18 @@ def not_started(self, machine) -> bool:
505515
else:
506516
return True
507517

508-
def not_current(self, machine, delta_seconds: int = 86400) -> bool:
509-
if machine.get("last_seen_utc"):
518+
def time_delta_context(self, machine: Dict[str, Any], check_type: str) -> bool:
519+
time_contexts: Dict[str, dict] = {
520+
"not_current": {"delta_seconds": 86400, "property": "last_seen_utc"},
521+
"is_lagged": {"delta_seconds": 120, "property": "last_consistency_utc"},
522+
}
523+
if machine.get(time_contexts[check_type].get("property")):
510524
now: datetime = datetime.datetime.now(datetime.timezone.utc)
511-
machine_last_seen: datetime = datetime.datetime.fromisoformat(machine["last_seen_utc"])
512-
last_seen_delta: datetime = now - machine_last_seen
513-
if int(last_seen_delta.total_seconds()) >= delta_seconds:
525+
last_seen: datetime = datetime.datetime.fromisoformat(machine[time_contexts[check_type].get("property")])
526+
last_seen_delta: datetime = now - last_seen
527+
if int(last_seen_delta.total_seconds()) >= time_contexts[check_type].get("delta_seconds"):
514528
return True
515-
else:
516-
return False
529+
return False
517530

518531
def update_blueprint(self) -> bool:
519532
"""Update the blueprint associated with the specified machines."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cloudendure"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
description = "Python wrapper and CLI for CloudEndure"
55
authors = ["Mark Beacom <[email protected]>", "Tom Warnock <[email protected]>"]
66
maintainers = ["Evan Lucchesi <[email protected]>", "Nick Selpa <[email protected]>"]

0 commit comments

Comments
 (0)