ssafronova (ssafronova) wrote in changelog,
ssafronova
ssafronova
changelog

[livejournal] r17763: LJSUP-7429: Handle "database unavailable...

Committer: ssafronova
LJSUP-7429: Handle "database unavailable" error in "mark-suspended-entries" worker
U   trunk/bin/worker/mark-suspended-entries
Modified: trunk/bin/worker/mark-suspended-entries
===================================================================
--- trunk/bin/worker/mark-suspended-entries	2010-11-24 04:35:23 UTC (rev 17762)
+++ trunk/bin/worker/mark-suspended-entries	2010-11-24 04:39:04 UTC (rev 17763)
@@ -11,41 +11,48 @@
 
 __PACKAGE__->start;
 
-package LJ::Worker::MarkSuspendedEntries::mark;
+package LJ::Worker::MarkSuspendedEntries::common;
 use base 'TheSchwartz::Worker';
 
-sub work {
-    my ($class, $job) = @_;
+sub grab_for { 60 }
+sub max_retries { 10 }
+
+sub retry_delay {
+    my ($class, $fails) = @_;
+    return (10, 30, 60, 300, 600)[$fails] || 900;
+}    
+
+sub update_all {
+    my ($class, $job, $value) = @_;
     my $args = $job->arg;
     my $userid = $args->{userid};
 
     foreach my $cid (@LJ::CLUSTERS) {
         my $dbh = LJ::get_cluster_master($cid);
-        next unless $dbh;
+        die "Cannot connect to $cid cluster master" unless $dbh;
 
-        $dbh->do("UPDATE log2 SET compressed='S' WHERE posterid=?", undef, $userid);
+        $dbh->do("UPDATE log2 SET compressed=? WHERE posterid=?", undef, $value, $userid);
     }
 
     $job->completed;
 }
 
-package LJ::Worker::MarkSuspendedEntries::unmark;
-use base 'TheSchwartz::Worker';
+package LJ::Worker::MarkSuspendedEntries::mark;
+use base 'LJ::Worker::MarkSuspendedEntries::common';
 
 sub work {
     my ($class, $job) = @_;
-    my $args = $job->arg;
-    my $userid = $args->{userid};
 
-    foreach my $cid (@LJ::CLUSTERS) {
-        my $dbh = LJ::get_cluster_master($cid);
-        next unless $dbh;
+    return $class->update_all($job, 'S');
+}
 
-        $dbh->do("UPDATE log2 SET compressed='N' WHERE posterid=?", undef, $userid);
-    }
+package LJ::Worker::MarkSuspendedEntries::unmark;
+use base 'LJ::Worker::MarkSuspendedEntries::common';
 
-    $job->completed;
+sub work {
+    my ($class, $job) = @_;
+
+    return $class->update_all($job, 'N');
 }
 
-
-1
+1;

Tags: livejournal, ssafronova
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments