Skip to main content

sc_crawler.logger

Logging and progress bar helpers.

Classes:

  • ScRichHandler – Extend RichHandler with function name logged in the right column.
  • ProgressPanel – Progress bars of the vendors and their inventory steps, with the metadata of the run.
  • VendorProgressTracker – Tracking the progress of the vendor's inventory updates.
  • VoidProgressTracker – Progress tracker reference not doing antyhing.

Functions:

  • log_start_end – Log the start and end of the decorated function.

func log_start_end logger.py:31–62⁠ (opens in a new tab)​

log_start_end(func)

Log the start and end of the decorated function.

class ScRichHandler logger.py:66–91⁠ (opens in a new tab)​

Bases: RichHandler⁠ (opens in a new tab)

Extend RichHandler with function name logged in the right column.

class ProgressPanel logger.py:94–142⁠ (opens in a new tab)​

Progress bars of the vendors and their inventory steps, with the metadata of the run.

class VendorProgressTracker logger.py:149–303⁠ (opens in a new tab)​

Tracking the progress of the vendor's inventory updates.

Functions:

  • start_vendor – Starts a progress bar for the Vendor's steps.
  • advance_vendor – Increment the number of finished steps.
  • update_vendor – Update the vendor's progress bar.
  • start_task – Starts a progress bar in the list of current jobs.
  • last_task – Returh the last registered TaskID.
  • advance_task – Increment the number of finished steps.
  • update_task – Update the task's progress bar.
  • hide_task – Hide a task from the list of progress bars.
  • fail_vendor – Clean up the progress bars of a vendor failed mid-way.

Attributes:

attr VendorProgressTracker.vendor logger.py:172⁠ (opens in a new tab)​

vendor: Vendor = vendor

A sc_crawler.tables.Vendor instance for which tracking progress.

attr VendorProgressTracker.progress_panel logger.py:173⁠ (opens in a new tab)​

progress_panel: ProgressPanel = progress_panel

A rich panel including progress bars. Should not be used directly, see the vendors, tasks and metadata attributes.

attr VendorProgressTracker.vendors logger.py:174⁠ (opens in a new tab)​

vendors: Progress = progress_panel.vendors

rich.progress.Progress⁠ (opens in a new tab) for tracking the inventory steps of the vendor.

attr VendorProgressTracker.tasks logger.py:175⁠ (opens in a new tab)​

tasks: Progress = progress_panel.tasks

rich.progress.Progress⁠ (opens in a new tab) for tracking the lower-level tasks within each step.

attr VendorProgressTracker.metadata logger.py:176⁠ (opens in a new tab)​

metadata: Text = progress_panel.metadata

rich.text.Text⁠ (opens in a new tab) metadata, e.g. data sources and records to be udpated.

attr VendorProgressTracker.task_ids logger.py:179⁠ (opens in a new tab)​

task_ids: List[TaskID] = []

List of active task ids for the current vendor.

attr VendorProgressTracker.vendor_task_id logger.py:180⁠ (opens in a new tab)​

vendor_task_id: Optional[TaskID] = None

The TaskID of the vendor's progress bar, set by start_vendor.

meth VendorProgressTracker.start_vendor logger.py:182–194⁠ (opens in a new tab)​

start_vendor(total)

Starts a progress bar for the Vendor's steps.

Parameters:

Returns:

  • TaskId (TaskID) – The progress bar's identifier to be referenced in future updates.

meth VendorProgressTracker.advance_vendor logger.py:201–207⁠ (opens in a new tab)​

advance_vendor(advance=1)

Increment the number of finished steps.

Parameters:

meth VendorProgressTracker.update_vendor logger.py:209–215⁠ (opens in a new tab)​

update_vendor(**kwargs)

Update the vendor's progress bar.

Useful fields:

  • step: Name of the currently running step to be shown on the progress bar.

meth VendorProgressTracker.start_task logger.py:217–234⁠ (opens in a new tab)​

start_task(name, total)

Starts a progress bar in the list of current jobs.

Besides returning the TaskID, it will also register in self.tasks.task_ids as the last task, which will be the default value for future advance_task, hide_task etc calls. The latter will remove the TaskID from the task_ids.

Parameters:

Returns:

  • TaskId (TaskID) – The progress bar's identifier to be referenced in future updates.

meth VendorProgressTracker.last_task logger.py:236–238⁠ (opens in a new tab)​

last_task()

Returh the last registered TaskID.

meth VendorProgressTracker.advance_task logger.py:240–251⁠ (opens in a new tab)​

advance_task(task_id=None, advance=1)

Increment the number of finished steps.

Parameters:

meth VendorProgressTracker.update_task logger.py:253–267⁠ (opens in a new tab)​

update_task(task_id=None, **kwargs)

Update the task's progress bar.

Parameters:

Other Parameters:

See rich.progress.Progress.update⁠ (opens in a new tab) for further keyword arguments.

meth VendorProgressTracker.hide_task logger.py:269–282⁠ (opens in a new tab)​

hide_task(task_id=None)

Hide a task from the list of progress bars.

Parameters:

meth VendorProgressTracker.fail_vendor logger.py:284–303⁠ (opens in a new tab)​

fail_vendor(step='✘')

Clean up the progress bars of a vendor failed mid-way.

Removes the progress bars of the vendor's interrupted steps from the display (e.g. when an exception interrupted an inventory step before its hide_task call), and stops the vendor's progress bar so its elapsed time no longer increases while the next vendors are being processed. These are display entries only, the interrupted work is not running anymore.

Parameters:

class VoidProgressTracker logger.py:306–337⁠ (opens in a new tab)​

Bases: VendorProgressTracker

Progress tracker reference not doing antyhing.

Functions:

  • start_vendor – Starts a progress bar for the Vendor's steps.
  • advance_vendor – Increment the number of finished steps.
  • update_vendor – Update the vendor's progress bar.
  • start_task – Starts a progress bar in the list of current jobs.
  • last_task – Returh the last registered TaskID.
  • advance_task – Increment the number of finished steps.
  • update_task – Update the task's progress bar.
  • hide_task – Hide a task from the list of progress bars.
  • fail_vendor – Clean up the progress bars of a vendor failed mid-way.

meth VoidProgressTracker.start_vendor logger.py:312–313⁠ (opens in a new tab)​

start_vendor(*args, **kwargs)

Starts a progress bar for the Vendor's steps.

Parameters:

Returns:

  • TaskId (TaskID) – The progress bar's identifier to be referenced in future updates.

meth VoidProgressTracker.advance_vendor logger.py:315–316⁠ (opens in a new tab)​

advance_vendor(*args, **kwargs)

Increment the number of finished steps.

Parameters:

meth VoidProgressTracker.update_vendor logger.py:318–319⁠ (opens in a new tab)​

update_vendor(*args, **kwargs)

Update the vendor's progress bar.

Useful fields:

  • step: Name of the currently running step to be shown on the progress bar.

meth VoidProgressTracker.start_task logger.py:321–322⁠ (opens in a new tab)​

start_task(*args, **kwargs)

Starts a progress bar in the list of current jobs.

Besides returning the TaskID, it will also register in self.tasks.task_ids as the last task, which will be the default value for future advance_task, hide_task etc calls. The latter will remove the TaskID from the task_ids.

Parameters:

Returns:

  • TaskId (TaskID) – The progress bar's identifier to be referenced in future updates.

meth VoidProgressTracker.last_task logger.py:324–325⁠ (opens in a new tab)​

last_task(*args, **kwargs)

Returh the last registered TaskID.

meth VoidProgressTracker.advance_task logger.py:327–328⁠ (opens in a new tab)​

advance_task(*args, **kwargs)

Increment the number of finished steps.

Parameters:

meth VoidProgressTracker.update_task logger.py:330–331⁠ (opens in a new tab)​

update_task(*args, **kwargs)

Update the task's progress bar.

Parameters:

Other Parameters:

See rich.progress.Progress.update⁠ (opens in a new tab) for further keyword arguments.

meth VoidProgressTracker.hide_task logger.py:333–334⁠ (opens in a new tab)​

hide_task(*args, **kwargs)

Hide a task from the list of progress bars.

Parameters:

meth VoidProgressTracker.fail_vendor logger.py:336–337⁠ (opens in a new tab)​

fail_vendor(*args, **kwargs)

Clean up the progress bars of a vendor failed mid-way.

Removes the progress bars of the vendor's interrupted steps from the display (e.g. when an exception interrupted an inventory step before its hide_task call), and stops the vendor's progress bar so its elapsed time no longer increases while the next vendors are being processed. These are display entries only, the interrupted work is not running anymore.

Parameters: