diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-03-13 15:25:24 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-04-28 18:50:19 +0100 |
commit | 96973c1fbecb5db3ba22059f2e4ade2096ec1c04 (patch) | |
tree | 818661c903837df06ac9fe8dfe032c95680af52f /bin/send-daemon | |
parent | d3b17d7e96597373a6f1243c5e0f6001d4487588 (diff) |
Add sending updates capability to daemon.
Diffstat (limited to 'bin/send-daemon')
-rwxr-xr-x | bin/send-daemon | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/bin/send-daemon b/bin/send-daemon index 6df5aa17f..dee9e949f 100755 --- a/bin/send-daemon +++ b/bin/send-daemon @@ -21,6 +21,7 @@ use FixMyStreet; use FixMyStreet::DB; use FixMyStreet::Script::Reports; use FixMyStreet::Queue::Item::Report; +use Open311::PostServiceRequestUpdates; my ($opts, $usage) = describe_options( '%c %o', @@ -76,6 +77,7 @@ while (!$exit) { while (!$exit) { $0 = "fmsd (running queue)"; $db->txn_do(\&look_for_report); + $db->txn_do(\&look_for_update); $0 = "fmsd"; sleep(5 + rand(10)); } @@ -106,6 +108,27 @@ sub look_for_report { $item->process; } +sub look_for_update { + my $updates = Open311::PostServiceRequestUpdates->new( + verbose => $verbose, + ); + + my $bodies = $updates->fetch_bodies; + my $params = $updates->construct_query($opts->debug); + my $comment = FixMyStreet::DB->resultset('Comment') + ->to_body([ keys %$bodies ]) + ->search($params, { for => \'UPDATE SKIP LOCKED', rows => 1 }) + ->single or return; + + print_log('debug', "Trying to send update " . $comment->id); + + my ($body) = grep { $bodies->{$_} } @{$comment->problem->bodies_str_ids}; + $body = $bodies->{$body}; + + $updates->construct_open311($body); + $updates->process_update($body, $comment); +} + sub print_log { my $prio = shift; |