From 3a56520e4237ec26cc7eef70b6eabbbeb9cfda42 Mon Sep 17 00:00:00 2001 From: dklawren Date: Tue, 10 Apr 2018 21:19:25 -0400 Subject: Bug 1453122 - The phabbugz feed daemon should use IO::Async::Timer instead of using while loop --- extensions/PhabBugz/lib/Feed.pm | 62 +++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-) (limited to 'extensions/PhabBugz/lib/Feed.pm') diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm index 074ecc0f9..a51f240a8 100644 --- a/extensions/PhabBugz/lib/Feed.pm +++ b/extensions/PhabBugz/lib/Feed.pm @@ -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'); -- cgit v1.2.3-24-g4f1b