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
log_start_end(func)
Log the start and end of the decorated function.
class ScRichHandler logger.py:66–91
Bases: RichHandler
Extend RichHandler with function name logged in the right column.
class ProgressPanel logger.py:94–142
Progress bars of the vendors and their inventory steps, with the metadata of the run.
class VendorProgressTracker logger.py:149–303
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:
- vendor (
Vendor) – A sc_crawler.tables.Vendor instance for which tracking progress. - progress_panel (
ProgressPanel) – Arichpanel including progress bars. - vendors (
Progress) – rich.progress.Progress for tracking the inventory steps of the vendor. - tasks (
Progress) – rich.progress.Progress for tracking the lower-level tasks within each step. - metadata (
Text) – rich.text.Text metadata, e.g. data sources and records to be udpated. - task_ids (
List[TaskID]) – List of active task ids for the currentvendor. - vendor_task_id (
Optional[TaskID]) – TheTaskIDof the vendor's progress bar, set bystart_vendor.
attr VendorProgressTracker.vendor logger.py:172
vendor: Vendor = vendor
A sc_crawler.tables.Vendor instance for which tracking progress.
attr VendorProgressTracker.progress_panel logger.py:173
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
vendors: Progress = progress_panel.vendors
rich.progress.Progress for tracking the inventory steps of the vendor.
attr VendorProgressTracker.tasks logger.py:175
tasks: Progress = progress_panel.tasks
rich.progress.Progress for tracking the lower-level tasks within each step.
attr VendorProgressTracker.metadata logger.py:176
metadata: Text = progress_panel.metadata
rich.text.Text metadata, e.g. data sources and records to be udpated.
attr VendorProgressTracker.task_ids logger.py:179
task_ids: List[TaskID] = []
List of active task ids for the current vendor.
attr VendorProgressTracker.vendor_task_id logger.py:180
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
start_vendor(total)
Starts a progress bar for the Vendor's steps.
Parameters:
- total (
int) – Overall number of steps to show in the progress bar.
Returns:
- TaskId (
TaskID) – The progress bar's identifier to be referenced in future updates.
meth VendorProgressTracker.advance_vendor logger.py:201–207
advance_vendor(advance=1)
Increment the number of finished steps.
Parameters:
- advance (
int) – Number of steps to advance.
meth VendorProgressTracker.update_vendor logger.py:209–215
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
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:
- name (
str) – Name to show in front of the progress bar. Will be prefixed by Vendor's name. - total (
int) – Overall number of steps to show in the progress bar.
Returns:
- TaskId (
TaskID) – The progress bar's identifier to be referenced in future updates.
meth VendorProgressTracker.last_task logger.py:236–238
last_task()
Returh the last registered TaskID.
meth VendorProgressTracker.advance_task logger.py:240–251
advance_task(task_id=None, advance=1)
Increment the number of finished steps.
Parameters:
- task_id (
Optional[TaskID]) – The progress bar's identifier returned bystart_task. Defaults to the most recently created task. - advance (
int) – Number of steps to advance.
meth VendorProgressTracker.update_task logger.py:253–267
update_task(task_id=None, **kwargs)
Update the task's progress bar.
Parameters:
- task_id (
Optional[TaskID]) – The progress bar's identifier returned bystart_task. Defaults to the most recently created task.
Other Parameters:
- step (
str) – Name of the currently running step to be shown on the progress bar.
See rich.progress.Progress.update for further keyword arguments.
meth VendorProgressTracker.hide_task logger.py:269–282
hide_task(task_id=None)
Hide a task from the list of progress bars.
Parameters:
- task_id (
Optional[TaskID]) – The progress bar's identifier returned bystart_task. Defaults to the most recently created task.
meth VendorProgressTracker.fail_vendor logger.py:284–303
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:
- step (
str) – Text to show as the current step on the vendor's progress bar.
class VoidProgressTracker logger.py:306–337
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
start_vendor(*args, **kwargs)
Starts a progress bar for the Vendor's steps.
Parameters:
- total (
int) – Overall number of steps to show in the progress bar.
Returns:
- TaskId (
TaskID) – The progress bar's identifier to be referenced in future updates.
meth VoidProgressTracker.advance_vendor logger.py:315–316
advance_vendor(*args, **kwargs)
Increment the number of finished steps.
Parameters:
- advance (
int) – Number of steps to advance.
meth VoidProgressTracker.update_vendor logger.py:318–319
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
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:
- name (
str) – Name to show in front of the progress bar. Will be prefixed by Vendor's name. - total (
int) – Overall number of steps to show in the progress bar.
Returns:
- TaskId (
TaskID) – The progress bar's identifier to be referenced in future updates.
meth VoidProgressTracker.last_task logger.py:324–325
last_task(*args, **kwargs)
Returh the last registered TaskID.
meth VoidProgressTracker.advance_task logger.py:327–328
advance_task(*args, **kwargs)
Increment the number of finished steps.
Parameters:
- task_id (
Optional[TaskID]) – The progress bar's identifier returned bystart_task. Defaults to the most recently created task. - advance (
int) – Number of steps to advance.
meth VoidProgressTracker.update_task logger.py:330–331
update_task(*args, **kwargs)
Update the task's progress bar.
Parameters:
- task_id (
Optional[TaskID]) – The progress bar's identifier returned bystart_task. Defaults to the most recently created task.
Other Parameters:
- step (
str) – Name of the currently running step to be shown on the progress bar.
See rich.progress.Progress.update for further keyword arguments.
meth VoidProgressTracker.hide_task logger.py:333–334
hide_task(*args, **kwargs)
Hide a task from the list of progress bars.
Parameters:
- task_id (
Optional[TaskID]) – The progress bar's identifier returned bystart_task. Defaults to the most recently created task.
meth VoidProgressTracker.fail_vendor logger.py:336–337
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:
- step (
str) – Text to show as the current step on the vendor's progress bar.