-
-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reporters to be specified multiple times #822
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -109,5 +109,13 @@ def run_jobs(self): | |||||||||||||
run_jobs(self) | ||||||||||||||
|
||||||||||||||
def close(self): | ||||||||||||||
self.report.finish() | ||||||||||||||
reported = self.report.finish() | ||||||||||||||
|
||||||||||||||
if not reported: | ||||||||||||||
logger.warning('No reporters enabled.') | ||||||||||||||
Comment on lines
+112
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like to do it like this mostly so that the "reported" local variable doesn't leak into the scope (this way, we can be sure that it isn't used below, since we don't give the expression result a name to begin with):
Suggested change
|
||||||||||||||
|
||||||||||||||
for job_state in self.report.job_states: | ||||||||||||||
if not job_state.reported_count: | ||||||||||||||
logger.warning(f'Job {job_state.job.pretty_name()} was not reported on') | ||||||||||||||
|
||||||||||||||
self.cache_storage.close() |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -28,6 +28,7 @@ | |||||||
|
||||||||
|
||||||||
import asyncio | ||||||||
from collections.abc import Mapping | ||||||||
import difflib | ||||||||
import re | ||||||||
import email.utils | ||||||||
|
@@ -80,13 +81,20 @@ | |||||||
WDIFF_REMOVED_RE = r'[\[][-].*?[-][]]' | ||||||||
|
||||||||
|
||||||||
def filter_by_tags(job_states, tags): | ||||||||
if tags: | ||||||||
return [job_state for job_state in job_states if job_state.job.matching_tags(tags)] | ||||||||
return job_states | ||||||||
|
||||||||
|
||||||||
class ReporterBase(object, metaclass=TrackSubClasses): | ||||||||
__subclasses__ = {} | ||||||||
|
||||||||
def __init__(self, report, config, job_states, duration): | ||||||||
def __init__(self, report, config, job_states, job_count_total, duration): | ||||||||
self.report = report | ||||||||
self.config = config | ||||||||
self.job_states = job_states | ||||||||
self.job_count_total = job_count_total | ||||||||
self.duration = duration | ||||||||
|
||||||||
def get_signature(self): | ||||||||
|
@@ -96,8 +104,10 @@ def get_signature(self): | |||||||
copyright=urlwatch.__copyright__), | ||||||||
'Website: {url}'.format(url=urlwatch.__url__), | ||||||||
'Support urlwatch development: https://github.com/sponsors/thp', | ||||||||
'watched {count} URLs in {duration} seconds'.format(count=len(self.job_states), | ||||||||
duration=self.duration.seconds), | ||||||||
'watched {total} URLs in {duration} seconds'.format( | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to show here that something is filtered down? e.g. |
||||||||
count=len(self.job_states), | ||||||||
total=self.job_count_total, | ||||||||
duration=self.duration.seconds), | ||||||||
) | ||||||||
|
||||||||
def convert(self, othercls): | ||||||||
|
@@ -106,7 +116,7 @@ def convert(self, othercls): | |||||||
else: | ||||||||
config = {} | ||||||||
|
||||||||
return othercls(self.report, config, self.job_states, self.duration) | ||||||||
return othercls(self.report, config, self.job_states, self.job_count_total, self.duration) | ||||||||
|
||||||||
@classmethod | ||||||||
def get_base_config(cls, report): | ||||||||
|
@@ -123,35 +133,36 @@ def reporter_documentation(cls): | |||||||
|
||||||||
@classmethod | ||||||||
def submit_one(cls, name, report, job_states, duration): | ||||||||
any_enabled = False | ||||||||
subclass = cls.__subclasses__[name] | ||||||||
cfg = report.config['report'].get(name, {'enabled': False}) | ||||||||
if cfg['enabled']: | ||||||||
base_config = subclass.get_base_config(report) | ||||||||
if base_config.get('separate', False): | ||||||||
for job_state in job_states: | ||||||||
subclass(report, cfg, [job_state], duration).submit() | ||||||||
else: | ||||||||
subclass(report, cfg, job_states, duration).submit() | ||||||||
else: | ||||||||
raise ValueError('Reporter not enabled: {name}'.format(name=name)) | ||||||||
cfgs = report.config['report'].get(name, {'enabled': False}) | ||||||||
if isinstance(cfgs, Mapping): | ||||||||
cfgs = [cfgs] | ||||||||
|
||||||||
@classmethod | ||||||||
def submit_all(cls, report, job_states, duration): | ||||||||
any_enabled = False | ||||||||
for name, subclass in cls.__subclasses__.items(): | ||||||||
cfg = report.config['report'].get(name, {}) | ||||||||
for cfg in cfgs: | ||||||||
if cfg.get('enabled', False): | ||||||||
any_enabled = True | ||||||||
logger.info('Submitting with %s (%r)', name, subclass) | ||||||||
base_config = subclass.get_base_config(report) | ||||||||
matching_job_states = filter_by_tags(job_states, cfg.get("tags", [])) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can get away with this, and then not having to check for the empty tags in
Suggested change
|
||||||||
if base_config.get('separate', False): | ||||||||
for job_state in job_states: | ||||||||
subclass(report, cfg, [job_state], duration).submit() | ||||||||
for job_state in matching_job_states: | ||||||||
subclass(report, cfg, [job_state], len(job_states), duration).submit() | ||||||||
job_state.reported_count = job_state.reported_count + 1 | ||||||||
else: | ||||||||
subclass(report, cfg, job_states, duration).submit() | ||||||||
subclass(report, cfg, matching_job_states, len(job_states), duration).submit() | ||||||||
Comment on lines
+150
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't checked what's the right way, but curiously it's always |
||||||||
for job_state in matching_job_states: | ||||||||
job_state.reported_count = job_state.reported_count + 1 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
return any_enabled | ||||||||
|
||||||||
@classmethod | ||||||||
def submit_all(cls, report, job_states, duration): | ||||||||
any_enabled = False | ||||||||
for name in cls.__subclasses__.keys(): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might also work:
Suggested change
|
||||||||
any_enabled = any_enabled | ReporterBase.submit_one(name, report, job_states, duration) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
if not any_enabled: | ||||||||
logger.warning('No reporters enabled.') | ||||||||
return any_enabled | ||||||||
|
||||||||
def submit(self): | ||||||||
raise NotImplementedError() | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..but is that changing behaviour from before?