-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move event emit code to common module. (#220)
* Move event emit code to common module. This moves the event emit code to a central module so it can be used elsewhere in the code. Signed-off-by: David Brown <dmlb2000@gmail.com> * Add orm eventing Signed-off-by: David Brown <dmlb2000@gmail.com> * try to fix python 2 unicode issues Signed-off-by: David Brown <dmlb2000@gmail.com> * Add doi update events Signed-off-by: David Brown <dmlb2000@gmail.com>
- Loading branch information
Showing
7 changed files
with
173 additions
and
50 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
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 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
"""Emit events for different things.""" | ||
from datetime import datetime | ||
import logging | ||
from json import dumps | ||
import requests | ||
from requests import RequestException | ||
from ..config import get_config | ||
|
||
|
||
def emit_event(**kwargs): | ||
"""Emit a cloud event that the data is now accepted.""" | ||
try: | ||
resp = requests.post( | ||
get_config().get('notifications', 'url'), | ||
data=dumps({ | ||
'cloudEventsVersion': '0.1', | ||
'eventType': kwargs.get('eventType'), | ||
'source': kwargs.get('source'), | ||
'eventID': kwargs.get('eventID'), | ||
'eventTime': datetime.now().replace(microsecond=0).isoformat(), | ||
'extensions': kwargs.get('extensions', {}), | ||
'contentType': 'application/json', | ||
'data': kwargs.get('data', {}) | ||
}), | ||
headers={'Content-Type': 'application/json'} | ||
) | ||
resp_major = int(int(resp.status_code)/100) | ||
assert resp_major == 2 | ||
except (RequestException, AssertionError) as ex: | ||
logging.warning('Unable to send notification: %s', ex) |
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