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

Add stop callback on shutdown #337

Merged
merged 6 commits into from Nov 28, 2020
Merged

Add stop callback on shutdown #337

merged 6 commits into from Nov 28, 2020

Conversation

qinghuangchan
Copy link
Contributor

In this PR, I propose to add some additional handling when exiting.

Background for needing this feature:

I've opted to store my data in pgsql. The current pgsql insertion implementation doesn't do any caching, so i've monkey patched my own caching methods in.

However, when restarting the collector, the data in cache is lost, since there is no opportunity to do clean up.

I've added a stop method to the Callback class, as well as created a new BackendCallback base class which all other backend callbacks inherit.

The purpose of adding such handling is to allow the many types of callbacks to do some clean up where necessary.

In the run method of FeedHandler, I've added a finally clause to the try-except statement. This is where the code will try to call stop for all its feeds.

Im not too sure if you'd like my implementation - please let me know if there's something I can change to make it better.

  • - Tested
  • - Changelog updated
  • - Contributors file updated (optional)

Copy link
Owner

@bmoscon bmoscon left a comment

Choose a reason for hiding this comment

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

rather than put in an un-used stub, why not just check if stop is a defined method on callback before calling it? This would remove the need for all the added inheritance

CHANGES.md Outdated
@@ -1,4 +1,5 @@
## Changelog
* Feature: Add stop callback when exiting loop, add stop method placeholder for base callbacks
Copy link
Owner

Choose a reason for hiding this comment

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

move this under the current dev version, 1.6.2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@qinghuangchan
Copy link
Contributor Author

That's looks nicer indeed. changes committed.

@bmoscon bmoscon merged commit 9399397 into bmoscon:master Nov 28, 2020
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.

None yet

2 participants