Remove work_done hook
authorJack Miller <jack@codezen.org>
Wed, 15 Jul 2015 02:27:33 +0000 (21:27 -0500)
committerJack Miller <jack@codezen.org>
Thu, 16 Jul 2015 02:44:03 +0000 (21:44 -0500)
- Only used for do_tag_changes

- This is better done when we actually cause changes, instead of
  potentially in the thread reaping thread, or the connection thread.

canto_next/canto_backend.py
canto_next/feed.py
canto_next/fetch.py
canto_next/tag.py

index e590407..611d994 100644 (file)
@@ -545,8 +545,6 @@ class CantoBackend(PluginHandler, CantoServer):
                     log.error("\n" + tb)
 
                 call_hook("daemon_post_" + cmd.lower(), [socket, args])
-
-                call_hook("daemon_work_done", [])
             else:
                 log.info("Got unknown command: %s" % (cmd))
 
@@ -555,8 +553,6 @@ class CantoBackend(PluginHandler, CantoServer):
         if cb:
             cb(r)
 
-        call_hook("daemon_work_done", [])
-
     def run(self):
 
         # Start fetch threads to load from disk. No need for locking as we
index fe4ec99..9bf55ad 100644 (file)
@@ -266,6 +266,7 @@ class CantoFeed(PluginHandler):
         return tags_to_add
 
     def _retag(self, items_to_remove, tags_to_add, tags_to_remove):
+        feed_lock.acquire_read()
         tag_lock.acquire_write()
 
         for item in items_to_remove:
@@ -277,10 +278,10 @@ class CantoFeed(PluginHandler):
         for item, tag in tags_to_remove:
             alltags.remove_tag(self._item_id(item), tag)
 
-        # Go through andc6b18d take items in old_contents that didn't make it
-        # into update_contents / self.items and remove them from all tags.
+        alltags.do_tag_changes()
 
         tag_lock.release_write()
+        feed_lock.release_read()
 
     def _keep_olditem(self, olditem):
         ref_time = time.time()
index 52dd9d3..b43f0db 100644 (file)
@@ -212,7 +212,5 @@ class CantoFetch():
 
         self.threads = newthreads
 
-        if work_done:
-            call_hook("daemon_work_done", [])
-            if self.threads == []:
-                self.shelf.sync()
+        if work_done and self.threads == []:
+            self.shelf.sync()
index 9d1eb8a..592f5ed 100644 (file)
@@ -28,11 +28,6 @@ class CantoTags():
 
         self.extra_tags = {}
 
-        # Batch tag_changes to be sent only after
-        # a block of requests.
-
-        on_hook("daemon_work_done", self.do_tag_changes)
-
     def items_to_tags(self, ids):
         tags = []
         for id in ids:
@@ -117,24 +112,14 @@ class CantoTags():
 
         return tagobj
 
-    #
-    # This is called from a hook, so it has to get the lock itself
-    #
-
-    @read_lock(config_lock)
-    @read_lock(feed_lock)
-    @write_lock(tag_lock)
     def do_tag_changes(self):
-        from .feed import allfeeds, rlock_feed_objs, runlock_feed_objs
         for tag in self.changed_tags:
             tagobj = self.get_tag(tag)
 
-            feeds = allfeeds.items_to_feeds(tagobj)
-            rlock_feed_objs(feeds)
             try:
                 tagobj = self.apply_transforms(tag, tagobj)
-            finally:
-                runlock_feed_objs(feeds)
+            except Exception as e:
+                log.error("Exception applying transforms: %s" % e)
 
             self.tags[tag] = tagobj
             call_hook("daemon_tag_change", [ tag ])