Skip to content

Commit

Permalink
Exit once the scan has completed
Browse files Browse the repository at this point in the history
  • Loading branch information
elyousfi5 committed Aug 15, 2024
1 parent b2e3d33 commit 4b98917
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ostorlab/runtimes/local/log_streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LogStream:
def __init__(self):
self._threads = []
self._color_map = {}
self.active_services = []
self.services = []

def stream(self, service: docker.models.services.Service) -> None:
"""Stream logs of a service without blocking.
Expand All @@ -52,7 +52,7 @@ def stream(self, service: docker.models.services.Service) -> None:
"""
color = self._select_color(service)
logs = service.logs(details=False, follow=True, stdout=True, stderr=True)
self.active_services.append(service.id)
self.services.append(service.id)

Check warning on line 55 in src/ostorlab/runtimes/local/log_streamer.py

View check run for this annotation

Codecov / codecov/patch

src/ostorlab/runtimes/local/log_streamer.py#L55

Added line #L55 was not covered by tests
t = threading.Thread(
target=_stream_log, args=(logs, service.name, color), daemon=True
)
Expand Down
12 changes: 6 additions & 6 deletions src/ostorlab/runtimes/local/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def scan(
console.info("Updating scan status")
self._update_scan_progress("IN_PROGRESS")
console.success("Scan created successfully")
scan_complete_check = threading.Thread(
scan_complete_thread = threading.Thread(
target=self._check_services_running, daemon=False
)
scan_complete_check.start()
scan_complete_thread.start()
return self._scan_db
except AgentNotHealthy:
message = "Agent not starting"
Expand Down Expand Up @@ -267,13 +267,13 @@ def _check_services_running(self) -> None:

stop_event = threading.Event()
while stop_event.is_set() is False:
for service_id in list(self._log_streamer.active_services):
for service_id in list(self._log_streamer.services):
try:
self._docker_client.services.get(service_id)
except docker_errors.NotFound:
self._log_streamer.active_services.remove(service_id)
if len(self._log_streamer.active_services) == 0:
console.success("Scan completed.")
self._log_streamer.services.remove(service_id)

Check warning on line 274 in src/ostorlab/runtimes/local/runtime.py

View check run for this annotation

Codecov / codecov/patch

src/ostorlab/runtimes/local/runtime.py#L271-L274

Added lines #L271 - L274 were not covered by tests
if len(self._log_streamer.services) == 0:
console.success("Scan done.")
stop_event.set()
sys.exit(0)

Expand Down

0 comments on commit 4b98917

Please sign in to comment.