From: blizzard Date: Fri, 28 Nov 2008 02:46:38 +0000 (+0000) Subject: 2008-11-27 Christopher Blizzard X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1740d2f0ac594006fbe6b7fb0207d31999ad3f08;p=whoisi.git 2008-11-27 Christopher Blizzard * tests/twisted/network/test_feedrefresh.py (TestFeedRefresh.confirmEntityHit): Check to make sure we changed last_poll when we hit an etag or last_modified. * services/command/siterefresh.py (RefreshSiteError.handleError): Update the last_poll field in the site table with the date if we hit the etag or last_modified value. git-svn-id: svn://trac.whoisi.com/whoisi/trunk@14 ae879524-a8bd-4c4c-a5ea-74d2e5fc5a2c --- diff --git a/ChangeLog b/ChangeLog index 5a73b4a..7481a79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-11-27 Christopher Blizzard + + * tests/twisted/network/test_feedrefresh.py (TestFeedRefresh.confirmEntityHit): + Check to make sure we changed last_poll when we hit an etag or + last_modified. + + * services/command/siterefresh.py (RefreshSiteError.handleError): + Update the last_poll field in the site table with the date if we + hit the etag or last_modified value. + 2008-11-22 Christopher Blizzard * whoisi/test_controller.py (TestController.modified): Now returns diff --git a/services/command/siterefresh.py b/services/command/siterefresh.py index 9a6c512..47ad931 100644 --- a/services/command/siterefresh.py +++ b/services/command/siterefresh.py @@ -87,32 +87,48 @@ class RefreshSiteError: self.d = defer.Deferred() def handleError(self, state, failure): + self.state = state error = None id = state["site_refresh_id"] self.orig_failure = failure self.it_failed = True + # a NotModifiedError is actually a success so we update the + # site_refresh table with "done" and then update the last_poll + # on the site table if failure.check(NotModifiedError): + self.it_failed = False q = """ - UPDATE site_refresh set status = "done", error = %s where id = %s + UPDATE site_refresh set status = "done", error = "http_not_modified" where id = %s """ - error = "http_not_modified" - self.it_failed = False + d = self.dcm.runQuery(q, id) + d.addCallback(self.modifiedUpdateDone) + d.addErrback(self.updateFailed) + return self.d - else: + q = """ + UPDATE site_refresh SET status = "error", error = %s where id = %s + """ - q = """ - UPDATE site_refresh SET status = "error", error = %s where id = %s - """ - error = str(failure) + error = str(failure) d = self.dcm.runQuery(q, (error, id)) d.addCallback(self.updateDone) + d.addErrback(self.updateFailed) return self.d + def modifiedUpdateDone(self, *args, **kw): + site_id = self.state["site_id"] + q = """ + UPDATE site SET last_poll = %s WHERE id = %s + """ + d = self.dcm.runQuery(q, (datetime.datetime.utcnow(), site_id)) + d.addCallback(self.updateDone) + d.addErrback(self.updateFailed) + def updateDone(self, *args, **kw): if self.it_failed: self.d.errback(self.orig_failure) @@ -121,3 +137,7 @@ class RefreshSiteError: # this makes the error handler return success retval = dict(site_history_new_ids = [], http_entity_hit=1) self.d.callback(retval) + + def updateFailed(self, failure): + print(" failure in error handler: %s" % str(failure)) + self.d.errback(failure) diff --git a/tests/twisted/network/test_feedrefresh.py b/tests/twisted/network/test_feedrefresh.py index b4e6f1d..0f7cc02 100644 --- a/tests/twisted/network/test_feedrefresh.py +++ b/tests/twisted/network/test_feedrefresh.py @@ -208,3 +208,6 @@ class TestFeedRefresh(unittest.TestCase): # And in the error field we should get an error that indicates we hit the error path self.sr.sync() assert(self.sr.error == "http_not_modified") + + # And the last_poll field should be not null + assert(self.site.lastPoll != None)