]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1453122 - The phabbugz feed daemon should use IO::Async::Timer instead of using...
authordklawren <dklawren@users.noreply.github.com>
Wed, 11 Apr 2018 01:19:25 +0000 (21:19 -0400)
committerDylan William Hardison <dylan@hardison.net>
Wed, 11 Apr 2018 01:19:25 +0000 (21:19 -0400)
extensions/PhabBugz/lib/Constants.pm
extensions/PhabBugz/lib/Feed.pm

index 754130f0b1e221767dee19d8cbd0a6d34aac7f95..2fd8613a078ab33fee5f46eeafa6cbb8082d113e 100644 (file)
@@ -16,12 +16,14 @@ our @EXPORT = qw(
     PHAB_AUTOMATION_USER
     PHAB_ATTACHMENT_PATTERN
     PHAB_CONTENT_TYPE
-    PHAB_POLL_SECONDS
+    PHAB_FEED_POLL_SECONDS
+    PHAB_USER_POLL_SECONDS
 );
 
 use constant PHAB_ATTACHMENT_PATTERN => qr/^phabricator-D(\d+)/;
 use constant PHAB_AUTOMATION_USER    => 'phab-bot@bmo.tld';
 use constant PHAB_CONTENT_TYPE       => 'text/x-phabricator-request';
-use constant PHAB_POLL_SECONDS       => 5;
+use constant PHAB_FEED_POLL_SECONDS  => 5;
+use constant PHAB_USER_POLL_SECONDS  => 60;
 
 1;
index 074ecc0f9c91575e98db68376141ec0348760b15..a51f240a835f3c9985d5d8ff446b67deb8abac58 100644 (file)
@@ -9,9 +9,12 @@ package Bugzilla::Extension::PhabBugz::Feed;
 
 use 5.10.1;
 
+use IO::Async::Timer::Periodic;
+use IO::Async::Loop;
 use List::Util qw(first);
 use List::MoreUtils qw(any);
 use Moo;
+use Try::Tiny;
 
 use Bugzilla::Logging;
 use Bugzilla::Constants;
@@ -40,22 +43,49 @@ has 'is_daemon' => ( is => 'rw', default => 0 );
 
 sub start {
     my ($self) = @_;
-    while (1) {
-        my $ok = eval {
-            if (Bugzilla->params->{phabricator_enabled}) {
+
+    # Query for new revisions or changes
+    my $feed_timer = IO::Async::Timer::Periodic->new(
+        first_interval => 0,
+        interval       => PHAB_FEED_POLL_SECONDS,
+        reschedule     => 'drift',
+        on_tick        => sub { 
+            try{
                 $self->feed_query();
-                Bugzilla->_cleanup();
             }
-            1;
-        };
-        ERROR( $@ // "unknown exception" ) unless $ok;
-        sleep(PHAB_POLL_SECONDS);
-    }
+            catch {
+                FATAL($_);
+            };
+            Bugzilla->_cleanup();
+        },
+    );
+
+    # Query for new users
+    my $user_timer = IO::Async::Timer::Periodic->new(
+        first_interval => 0,
+        interval       => PHAB_USER_POLL_SECONDS,
+        reschedule     => 'drift',
+        on_tick        => sub { 
+            try{
+                $self->user_query();
+            }
+            catch {
+                FATAL($_);
+            };
+            Bugzilla->_cleanup();
+        },
+    );
+
+    my $loop = IO::Async::Loop->new;
+    $loop->add($feed_timer);
+    $loop->add($user_timer);
+    $feed_timer->start;
+    $user_timer->start;
+    $loop->run;
 }
 
 sub feed_query {
     my ($self) = @_;
-    my $dbh = Bugzilla->dbh;
 
     # Ensure Phabricator syncing is enabled
     if (!Bugzilla->params->{phabricator_enabled}) {
@@ -110,10 +140,20 @@ sub feed_query {
         };
         $self->save_last_id($story_id, 'feed');
     }
+}
+
+sub user_query {
+    my ( $self ) = @_;
+
+    # Ensure Phabricator syncing is enabled
+    if (!Bugzilla->params->{phabricator_enabled}) {
+        INFO("PHABRICATOR SYNC DISABLED");
+        return;
+    }
 
     # PROCESS NEW USERS
 
-    INFO("FEED: Fetching new users");
+    INFO("USERS: Fetching new users");
 
     my $user_last_id = $self->get_last_id('user');