Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r11203: LJSUP-10483 (Selfpromo delivery mechanic...

Committer: ailyin
LJSUP-10483 (Selfpromo delivery mechanics is broken)
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2011-11-22 14:52:45 UTC (rev 11202)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/SelfPromo.pm	2011-11-23 14:25:49 UTC (rev 11203)
@@ -70,6 +70,11 @@
 sub _deliver_item {
     my ( $self, $payment, $buyer_u, $rcpt_u, $note_rec_change ) = @_;
 
+    # if we cannot get a lock straight away, let this be delivered later;
+    # resolves race condition with ljmaint.pl and webs trying to deliver
+    # the same item simultaneously
+    return if LJ::Pay::SelfPromo->lock_taken_elsewhere;
+
     # this should be temporary until we l10n the shop
     my $lang = ($rcpt_u && $rcpt_u->prop('browselang')) ? $rcpt_u->prop('browselang') : $LJ::DEFAULT_LANG;
     my $ml = sub {

Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2011-11-22 14:52:45 UTC (rev 11202)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2011-11-23 14:25:49 UTC (rev 11203)
@@ -563,8 +563,6 @@
         my $row = LJ::MemCache::get_or_set(
             $class->memcache_key,
             sub {
-                my $dbh = LJ::get_db_writer();
-
                 my $res = $class->find_promos(
                     { 'require_active' => 1, 'return_rows' => 1 }
                 );
@@ -585,8 +583,6 @@
     }
 
     return do {
-        my $dbh = LJ::get_db_writer();
-
         my $promos = $class->find_promos( { 'promoid' => $promoid } );
 
         return unless @$promos;
@@ -875,6 +871,14 @@
     return LJ::Pay::SelfPromo::Lock->new;
 }
 
+sub lock_taken {
+    return LJ::Pay::SelfPromo::Lock->taken;
+}
+
+sub lock_taken_elsewhere {
+    return LJ::Pay::SelfPromo::Lock->taken_elsewhere;
+}
+
 # supported opts: entry_url, event, reason, details
 sub log {
     my ( $class, $promoter, %opts ) = @_;
@@ -955,7 +959,8 @@
 
     return if $locked;
 
-    LJ::get_lock( LJ::get_db_writer(), 'global', 'selfpromo' );
+    die "Can't get lock"
+        unless LJ::get_lock( LJ::get_db_writer(), 'global', 'selfpromo' );
 
     $locked = 1;
     return bless {}, $class;
@@ -973,6 +978,17 @@
     $locked = 0;
 }
 
+sub taken {
+    my ($class) = @_;
+    return LJ::lock_taken( LJ::get_db_writer(), 'global', 'selfpromo' );
+}
+
+sub taken_elsewhere {
+    my ($class) = @_;
+
+    return !$locked && $class->taken;
+}
+
 1;
 
 __END__

Tags: ailyin, andy, ljcom, pm
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