Skip to content

Commit

Permalink
simplify with reexports and drop custom id tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Feb 25, 2024
1 parent 40c47ee commit bf622ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/sc_crawler/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,17 @@ class VendorProgressTracker:

vendor: Vendor
progress_panel: ProgressPanel
# no need to track, stored in Progress.task_ids
vendor_progress: Optional[TaskID] = None
tasks: List[TaskID] = []
# reexport Progress attrubutes of the ProgressPanel
vendors: Progress
tasks: Progress
metadata: Progress

def __init__(self, vendor: Vendor, progress_panel: ProgressPanel):
self.vendor = vendor
self.progress_panel = progress_panel
self.vendors = progress_panel.vendors
self.tasks = progress_panel.tasks
self.metadata = progress_panel.metadata

def vendor_start(self, n: int) -> TaskID:
"""Starts a progress bar for the Vendor's steps.
Expand All @@ -164,22 +168,19 @@ def vendor_start(self, n: int) -> TaskID:
Returns:
TaskId: The progress bar's identifier to be referenced in future updates.
"""
self.vendor_progress = self.progress_panel.vendors.add_task(
self.vendor.name, total=n, step=""
)
return self.vendor_progress
return self.vendors.add_task(self.vendor.name, total=n, step="")

def vendor_steps_advance(self, by: int = 1):
"""Increment the number of finished steps."""
self.progress_panel.vendors.update(self.vendor_progress, advance=by)
self.vendors.update(self.vendors.task_ids[0], advance=by)

def vendor_update(self, **kwargs):
"""Update the vendor's progress bar.
Useful fields:
- `step`: Name of the currently running step to be shown on the progress bar.
"""
self.progress_panel.vendors.update(self.vendor_progress, **kwargs)
self.vendors.update(self.vendors.task_ids[0], **kwargs)

def start_task(self, name: str, n: int) -> TaskID:
"""Starts a progress bar for the Vendor's steps.
Expand All @@ -191,7 +192,4 @@ def start_task(self, name: str, n: int) -> TaskID:
Returns:
TaskId: The progress bar's identifier to be referenced in future updates.
"""
self.tasks.append(
self.progress_panel.tasks.add_task(self.vendor.name + ": " + name, total=n)
)
return self.tasks[-1]
return self.tasks.add_task(self.vendor.name + ": " + name, total=n)
4 changes: 2 additions & 2 deletions src/sc_crawler/vendors/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ def inventory_servers(vendor):
logger.info(
f"{vendor.name}: {len(instance_types)} servers synced from {datacenter.id}"
)
vendor.progress_tracker.progress_panel.tasks.update(progress, advance=1)
vendor.progress_tracker.progress_panel.tasks.update(progress, visible=False)
vendor.progress_tracker.tasks.update(progress, advance=1)
vendor.progress_tracker.tasks.update(progress, visible=False)


def inventory_server_prices(vendor):
Expand Down

0 comments on commit bf622ed

Please sign in to comment.