Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jamstah
Copy link
Contributor

@Jamstah Jamstah commented May 29, 2024

This allows different jobs to be selected for reporting in different ways, for example, allowing different changes to be emailed to different addresses.

Closes #790

@Jamstah Jamstah marked this pull request as draft May 29, 2024 22:44
@Jamstah Jamstah force-pushed the multiple-reporters branch 2 times, most recently from aafd0a6 to 7cf98cc Compare May 29, 2024 22:52
@Jamstah Jamstah marked this pull request as ready for review May 29, 2024 22:57
Copy link
Owner

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

lib/urlwatch/reporters.py Outdated Show resolved Hide resolved
Comment on lines 105 to 110
'reported {count} of {total} watched URLs in {duration} seconds'.format(
count=len(self.job_states),
total=self.job_count_total,
duration=self.duration.seconds),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "reported in X seconds" is kind of wrong, as most of the time will be spent watching (hopefully).

Maybe just leave this as-is, as I'm not sure how useful this is (apart from debugging, which is already in the logs?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have removed the count, it was hard to describe what the count meant. Instead, we can just say what the process did.

I think that's clearer, or, we could just remove the sentence altogether.

@Jamstah Jamstah force-pushed the multiple-reporters branch 4 times, most recently from a02231b to 4c82895 Compare August 5, 2024 10:13
This allows different jobs to be selected for reporting in different
ways, for example, allowing different changes to be emailed to different
addresses.

Closes thp#790

Signed-off-by: James Hewitt <james.hewitt@gmail.com>
Copy link
Owner

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

Comment on lines +383 to +386
reported = report.finish_one(name)

if not reported:
raise ValueError(f'Reporter not enabled: {name}')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reported = report.finish_one(name)
if not reported:
raise ValueError(f'Reporter not enabled: {name}')
if not report.finish_one(name):
raise ValueError(f'Reporter not enabled: {name}')

..but is that changing behaviour from before?

Comment on lines +112 to +115
reported = self.report.finish()

if not reported:
logger.warning('No reporters enabled.')
Copy link
Owner

Choose a reason for hiding this comment

The 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
reported = self.report.finish()
if not reported:
logger.warning('No reporters enabled.')
if not self.report.finish():
logger.warning('No reporters enabled.')

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", []))
Copy link
Owner

Choose a reason for hiding this comment

The 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 filter_by_tags():

Suggested change
matching_job_states = filter_by_tags(job_states, cfg.get("tags", []))
if tags := cfg.get("tags"):
job_states = filter_by_tags(job_states, tags)

Comment on lines +150 to +153
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()
Copy link
Owner

Choose a reason for hiding this comment

The 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 len(job_states), not len(matching_job_states), is that correct/intended or a bug?

subclass(report, cfg, job_states, duration).submit()
subclass(report, cfg, matching_job_states, len(job_states), duration).submit()
for job_state in matching_job_states:
job_state.reported_count = job_state.reported_count + 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
job_state.reported_count = job_state.reported_count + 1
job_state.reported_count += 1

@classmethod
def submit_all(cls, report, job_states, duration):
any_enabled = False
for name in cls.__subclasses__.keys():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also work:

Suggested change
for name in cls.__subclasses__.keys():
for name in cls.__subclasses__:

def submit_all(cls, report, job_states, duration):
any_enabled = False
for name in cls.__subclasses__.keys():
any_enabled = any_enabled | ReporterBase.submit_one(name, report, job_states, duration)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
any_enabled = any_enabled | ReporterBase.submit_one(name, report, job_states, duration)
any_enabled |= ReporterBase.submit_one(name, report, job_states, duration)

@@ -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(
Copy link
Owner

Choose a reason for hiding this comment

The 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. watched 5 or 9 URLs in 12.34 seconds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: Support multiple reporters with different options
2 participants