]> git.sesse.net Git - skvidarsync/commitdiff
Stick ws.pl messages on stderr, which is seemingly better for systemd.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 10 Nov 2023 16:10:41 +0000 (17:10 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 10 Nov 2023 16:10:41 +0000 (17:10 +0100)
bin/ws.pl

index 69c7b1dcdc8cb65813aa7ffaf069e2675af3be4b..fd01cb551bf35ebab43c4327bf65f4db5584b25a 100644 (file)
--- a/bin/ws.pl
+++ b/bin/ws.pl
@@ -53,7 +53,7 @@ while (1) {
        my $ws = AnyEvent::WebSocket::Client->new;
        $ws->connect($ws_url)->cb(\&ws_cb);
        $ws_disconnected->recv;
-       print "Disconnected; trying to reconnect.\n\n";
+       print STDERR "Disconnected; trying to reconnect.\n\n";
 };
 
 sub ws_cb {
@@ -65,11 +65,11 @@ sub ws_cb {
                return;
        }
 
-       print "Connected to the Slack WebSocket.\n";
+       print STDERR "Connected to the Slack WebSocket.\n";
 
        $connection->on(each_message => sub {
                my ($conn, $message) = @_;
-               print "Message: $message->{'body'}\n";
+               print STDERR "Message: $message->{'body'}\n";
                my $json = JSON::XS::decode_json($message->{'body'});
                eval {
                        if (exists($json->{'payload'}{'event'})) {
@@ -77,11 +77,11 @@ sub ws_cb {
                        }
                };
                if ($@) {
-                       print "Error during handling: $@";
+                       print STDERR "Error during handling: $@";
                        die;
                } elsif (exists($json->{'envelope_id'})) {
                        my $ack = { envelope_id => $json->{'envelope_id'} };
-                       print "Ack: " . JSON::XS::encode_json($ack) . "\n";
+                       print STDERR "Ack: " . JSON::XS::encode_json($ack) . "\n";
                        $conn->send(JSON::XS::encode_json($ack))
                                or die "Error sending ack: $!";
                }
@@ -90,7 +90,7 @@ sub ws_cb {
        $connection->on(finish => sub {
                my ($conn, $msg) = @_;
                $msg //= '(none)';
-               print "Finished with message: $msg\n";
+               print STDERR "Finished with message: $msg\n";
                $ws_disconnected->send;
        });
 }
@@ -116,7 +116,7 @@ sub handle_event {
                        my $date = $1;
                        my $channel = $ev->{'channel'};
                        my $ts = $ev->{'message'}{'ts'};
-                       print "Matching message {$channel, $ts} to date $date\n";
+                       print STDERR "Matching message {$channel, $ts} to date $date\n";
                        $dbh->do('INSERT INTO message_sheet_link (channel, ts, sheet_title) VALUES (?,?,?)', undef,
                                $channel, $ts, $date);
                } else {