aboutsummaryrefslogtreecommitdiffstats
path: root/bin/send-daemon
diff options
context:
space:
mode:
Diffstat (limited to 'bin/send-daemon')
-rwxr-xr-xbin/send-daemon23
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;