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

[ljcom] r9510: LJSUP-6780 (Twitter Digest): checkpoint ...

Committer: ailyin
LJSUP-6780 (Twitter Digest): checkpoint commit
U   trunk/bin/worker/twitter-digest
U   trunk/cgi-bin/LJ/TwitterDigest.pm
Modified: trunk/bin/worker/twitter-digest
===================================================================
--- trunk/bin/worker/twitter-digest	2010-09-16 13:06:04 UTC (rev 9509)
+++ trunk/bin/worker/twitter-digest	2010-09-16 13:07:18 UTC (rev 9510)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl
 use strict;
 use warnings;
 
@@ -11,14 +11,32 @@
 use base qw(LJ::NewWorker::Manual);
 
 use LJ::Client::Twitter;
+use LJ::TwitterDigest;
 
 sub work {
-    warn "hi\n";
-    return 0; ## pretend we didn't work and sleep
+    my $u = LJ::TwitterDigest->get_pending_user;
+
+    # in case there is no user, we can sleep
+    return 0 unless defined $u;
+
+    my $res = LJ::TwitterDigest->post_digest($u);
+
+    warn "digest has been posted: $res->{url}\n"
+        if $LJ::IS_DEV_SERVER;
+
+    LJ::TwitterDigest->set_next_post_time($u);
+
+    # pick next user
+    return 1;
 }
 
 sub on_idle {
-    sleep 1800 unless $LJ::IS_DEV_SERVER;
+    if ($LJ::IS_DEV_SERVER) {
+        warn "all users have been processed\n";
+        exit;
+    }
+
+    sleep 1800;
 }
 
 1;

Modified: trunk/cgi-bin/LJ/TwitterDigest.pm
===================================================================
--- trunk/cgi-bin/LJ/TwitterDigest.pm	2010-09-16 13:06:04 UTC (rev 9509)
+++ trunk/cgi-bin/LJ/TwitterDigest.pm	2010-09-16 13:07:18 UTC (rev 9510)
@@ -74,11 +74,12 @@
     my $tx = LJ::Transaction->new($dbh);
 
     my ($userid) = $dbh->selectrow_array(qq{
-        SELECT FOR UPDATE userid
+        SELECT userid
         FROM twitter_digest_status
-        WHERE turned_on      = 1
+        WHERE disabled       = 0
           AND next_post_time < UNIX_TIMESTAMP()
           AND locked_until   < UNIX_TIMESTAMP()
+        FOR UPDATE
     });
 
     unless (defined $userid) {

Tags: 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