OCM-2211 pgq_coop doesnt remove timed out subconsumers without active batch
authorEgon Valdmees <egon.valdmees@skype.net>
Mon, 9 May 2011 13:54:53 +0000 (16:54 +0300)
committerMarko Kreen <markokr@gmail.com>
Wed, 11 May 2011 09:39:45 +0000 (12:39 +0300)
sql/pgq_coop/functions/pgq_coop.next_batch.sql

index adb65a9861894a142363f59a174af889cdb44c7e..7056102bf0fca5fec2fa448f85470e974d66bc14 100644 (file)
@@ -165,7 +165,6 @@ begin
             where s.sub_queue = _queue_id
               and s.sub_id = _sub_id
               and s.sub_consumer <> _subcon_id
-              and s.sub_batch is not null
               and sub_active < now() - i_dead_interval
             limit 1;
 
@@ -175,16 +174,18 @@ begin
                 where sub_queue = _queue_id
                   and sub_consumer = _dead.sub_consumer;
 
-            -- copy batch over
-            update pgq.subscription
-                set sub_batch = _dead.sub_batch,
-                    sub_last_tick = _dead.sub_last_tick,
-                    sub_next_tick = _dead.sub_next_tick,
-                    sub_active = now()
-                where sub_queue = _queue_id
-                  and sub_consumer = _subcon_id;
+            -- if dead consumer had batch, copy it over and return
+            if _dead.sub_batch is not null then
+                update pgq.subscription
+                    set sub_batch = _dead.sub_batch,
+                        sub_last_tick = _dead.sub_last_tick,
+                        sub_next_tick = _dead.sub_next_tick,
+                        sub_active = now()
+                    where sub_queue = _queue_id
+                      and sub_consumer = _subcon_id;
 
-            return _dead.sub_batch;
+                return _dead.sub_batch;
+            end if;
         end if;
     end if;