Skip to content

Commit

Permalink
standardize helper methods name (vendor<>task)
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Feb 25, 2024
1 parent afe5d93 commit 72b9e80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/sc_crawler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def custom_serializer(x):
vendor.progress_tracker = VendorProgressTracker(
vendor=vendor, progress_panel=pbars
)
vendor.progress_tracker.vendor_start(n=len(update_table))
vendor.progress_tracker.start_vendor(n=len(update_table))
if Tables.compliance_frameworks in update_table:
vendor.inventory_compliance_frameworks()
if Tables.datacenters in update_table:
Expand All @@ -190,7 +190,7 @@ def custom_serializer(x):
if Tables.ipv4_prices in update_table:
vendor.inventory_ipv4_prices()
# reset current step name
vendor.progress_tracker.vendor_update(step="")
vendor.progress_tracker.update_vendor(step="")
session.merge(vendor)
session.commit()

Expand Down
29 changes: 22 additions & 7 deletions src/sc_crawler/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def wrap(*args, **kwargs):

# update Vendor's progress bar with the step name
try:
self.progress_tracker.vendor_update(
self.progress_tracker.update_vendor(
# drop `inventory_` prefix and prettify
step=func.__name__[10:].replace("_", " ")
)
Expand All @@ -51,7 +51,7 @@ def wrap(*args, **kwargs):
result = func(*args, **kwargs)

# increment Vendor's progress bar
self.progress_tracker.vendor_update(advance=1)
self.progress_tracker.advance_vendor()

# log end of the step and return
logger.debug("Finished %s", fname)
Expand Down Expand Up @@ -159,7 +159,7 @@ def __init__(self, vendor: Vendor, progress_panel: ProgressPanel):
self.tasks = progress_panel.tasks
self.metadata = progress_panel.metadata

def vendor_start(self, n: int) -> TaskID:
def start_vendor(self, n: int) -> TaskID:
"""Starts a progress bar for the Vendor's steps.
Args:
Expand All @@ -170,11 +170,15 @@ def vendor_start(self, n: int) -> TaskID:
"""
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."""
def advance_vendor(self, by: int = 1) -> None:
"""Increment the number of finished steps.
Args:
by: Number of steps to advance.
"""
self.vendors.update(self.vendors.task_ids[0], advance=by)

def vendor_update(self, **kwargs):
def update_vendor(self, **kwargs) -> None:
"""Update the vendor's progress bar.
Useful fields:
Expand All @@ -183,7 +187,7 @@ def vendor_update(self, **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.
"""Starts a progress bar in the list of current jobs.
Args:
name: Name to show in front of the progress bar. Will be prefixed by Vendor's name.
Expand All @@ -195,7 +199,18 @@ def start_task(self, name: str, n: int) -> TaskID:
return self.tasks.add_task(self.vendor.name + ": " + name, total=n)

def advance_task(self, task_id: TaskID, by: int = 1):
"""Increment the number of finished steps.
Args:
task_id: The progress bar's identifier returned by `start_task`.
by: Number of steps to advance.
"""
self.tasks.update(task_id, advance=by)

def hide_task(self, task_id: TaskID):
"""Hide a task from the list of progress bars.
Args:
task_id: The progress bar's identifier returned by `start_task`.
"""
self.tasks.update(task_id, visible=False)

0 comments on commit 72b9e80

Please sign in to comment.