-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sending messages async and more robust
Signed-off-by: Aurélien Bompard <[email protected]>
- Loading branch information
Showing
6 changed files
with
87 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import asyncio | ||
import logging | ||
import sys | ||
import traceback | ||
|
||
import backoff | ||
from fedora_messaging import api | ||
from fedora_messaging import exceptions as fm_exceptions | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def backoff_hdlr(details): | ||
log.warning("Publishing message failed. Retrying. %s", traceback.format_tb(sys.exc_info()[2])) | ||
|
||
|
||
def giveup_hdlr(details): | ||
log.error("Publishing message failed. Giving up. %s", traceback.format_tb(sys.exc_info()[2])) | ||
|
||
|
||
@backoff.on_exception( | ||
backoff.expo, | ||
(fm_exceptions.ConnectionException, fm_exceptions.PublishException), | ||
max_tries=3, | ||
on_backoff=backoff_hdlr, | ||
on_giveup=giveup_hdlr, | ||
) | ||
async def publish(message): | ||
deferred = api.twisted_publish(message) | ||
loop = asyncio.get_running_loop() | ||
await deferred.asFuture(loop) |