revert code changes from commit cf0c178b81, but clarify behaviors in the comments.

This commit is contained in:
Matthew Wall
2022-12-17 11:55:35 -05:00
parent b5f1c83d19
commit 8a57a6891a
2 changed files with 20 additions and 24 deletions

View File

@@ -48,30 +48,30 @@ should only have to implement a few functions. In particular,
- post_request(self, request, data). This function takes a urllib.request.Request object
and is responsible for performing the HTTP GET or POST. The default version
simply uses urllib.request.urlopen(request) and returns the result. If the post
could raise an unusual exception, override this function and catch the
simply uses urllib.request.urlopen(request) and returns the result. If the
post could raise an unusual exception, override this function and catch the
exception. See the WOWThread implementation for an example.
- check_response(self, response). After an HTTP request gets posted, the
webserver sends back a "response." This response may contain clues as to
whether the post worked. For example, a request might succeed, but the
actual posting of data might fail, with the reason indicated in the
response. The uploader can then take appropriate action, such as just
logging the response, or raising a FailedPost exception. By overriding
check_response() you can look for these clues.
response. The uploader can then take appropriate action, such as raising
a FailedPost exception, which results in logging the failure but not
retrying the post. See the StationRegistry uploader as an example.
In unusual cases, you might also have to implement the following:
In some cases, you might also have to implement the following:
- get_request(self, url). The default version of this function creates
an urllib.request.Request object from the url, adds a 'User-Agent' header,
then returns it. You may need to override this function if you need to add
other headers, such as "Authorization" header.
- get_post_body(self, record). Override this function if you want to do an HTTP
POST (instead of GET). It should return a tuple. First element is the body
of the POST, the second element is the type of the body. An example would
be (json.dumps({'city' : 'Sacramento'}), 'application/json').
- get_post_body(self, record). Override this function if you want to do an
HTTP POST (instead of GET). It should return a tuple. First element is the
body of the POST, the second element is the type of the body. An example
would be (json.dumps({'city' : 'Sacramento'}), 'application/json').
- process_record(self, record, dbmanager). The default version is designed
to handle HTTP GET and POST. However, if your uploader uses some other
@@ -1562,18 +1562,14 @@ class StationRegistryThread(RESTThread):
def check_response(self, response):
"""
Check the response from a Station Registry post. The server will
reply with OK or FAIL. If a post fails at this point, it is probably
due to a configuration problem, not communications, so retrying
probably not help. Just log the server response.
reply with a single line that starts with OK or FAIL. If a post fails
at this point, it is probably due to a configuration problem, not
communications, so retrying probably not help. So raise a FailedPost
exception, which will result in logging the failure without retrying.
"""
# server responds with a single line, but check for multiple in case
# the protocol changes
ok = True
for line in response:
if line.startswith(b'FAIL') or line.startswith(b'FLOP'):
ok = False
if (not ok and self.log_failure) or (ok and self.log_success):
log.info("StationRegistry: %s" % line)
if line.startswith(b'FAIL'):
raise FailedPost(line)
# ==============================================================================

View File

@@ -11,10 +11,10 @@ Different wake-up strategy for the Vantage console.
Do not write config_path and entry_path to updated configuration dictionary.
Fixes issue #806.
Log response from registry server, respecting the log_success and log_failure
directives. Do not attempt retries when a registration update contacts the
server but gets a FAIL response, since a FAIL at that point is due to a
configuration problem, not comms, and retries will not help.
Document the behavior of the registry server responses. Do not attempt retries
when a registration update contacts the server but gets a FAIL response, since
a FAIL at that point is due to a configuration problem, not comms, and retries
will not help.
4.9.1 10/25/2022