]> git.etc.gen.nz Git - whoisi.git/commitdiff
2008-11-27 Christopher Blizzard <blizzard@0xdeadbeef.com>
authorblizzard <blizzard@ae879524-a8bd-4c4c-a5ea-74d2e5fc5a2c>
Fri, 28 Nov 2008 02:46:38 +0000 (02:46 +0000)
committerblizzard <blizzard@ae879524-a8bd-4c4c-a5ea-74d2e5fc5a2c>
Fri, 28 Nov 2008 02:46:38 +0000 (02:46 +0000)
        * 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

ChangeLog
services/command/siterefresh.py
tests/twisted/network/test_feedrefresh.py

index 5a73b4a433029993bf54e6ec3023e96820e422b8..7481a798a3380c9f0a4f9c0b9b55fed110017827 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-11-27  Christopher Blizzard  <blizzard@0xdeadbeef.com>
+
+       * 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  <blizzard@0xdeadbeef.com>
 
        * whoisi/test_controller.py (TestController.modified): Now returns
index 9a6c51223300ea2ad60a87a193bfc7b423a1cf0a..47ad931ea3b7543a357564e98f352c779730ec74 100644 (file)
@@ -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)
index b4e6f1ddf888b871492be2b003bc2d9bc473db9e..0f7cc02ce16ff87a76a5e79c981f483ea5832882 100644 (file)
@@ -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)