kandra: Add a mirror of #signups to CZO.

This commit is contained in:
Alex Vandiver
2025-10-02 20:04:55 +00:00
committed by Tim Abbott
parent 890ccec8d4
commit 456354575e
4 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python3
import configparser
import logging
import time
from contextlib import suppress
from typing import Any
import zulip
config_file = configparser.RawConfigParser()
config_file.read("/etc/zulip/zulip.conf")
send_to_channel = config_file.get("mirror_to_czo", "send_to_channel")
reading = zulip.Client(config_file="/etc/zulip/mirror_to_czo.zulipcore.zuliprc")
sending = zulip.Client(config_file="/etc/zulip/mirror_to_czo.czo.zuliprc")
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s mirror_to_czo: %(message)s", level=logging.INFO)
def send_mirror(msg: dict[str, Any]) -> None:
logging.info(msg["message"]["content"])
sending.send_message(
{
"type": "stream",
"to": send_to_channel,
"topic": msg["message"]["subject"],
"content": msg["message"]["content"],
}
)
with suppress(KeyboardInterrupt):
reading.call_on_each_event(
send_mirror,
event_types=["message"],
narrow=[["stream", "signups"]],
)

View File

@@ -0,0 +1,31 @@
class kandra::mirror_to_czo {
include zulip::supervisor
# We embed the hash of the contents into the name of the process, so
# that `supervisorctl reread` knows that it has updated.
$full_script_hash = sha256(file('kandra/mirror_to_czo'))
$script_hash = $full_script_hash[0,8]
$bin = '/usr/local/bin/mirror_to_czo'
file { $bin:
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => 'puppet:///modules/kandra/mirror_to_czo',
}
file { "${zulip::common::supervisor_conf_dir}/mirror_to_czo.conf":
ensure => file,
require => [
User[zulip],
Package[supervisor],
File[$bin],
],
owner => 'root',
group => 'root',
mode => '0644',
content => template('kandra/supervisor/conf.d/mirror_to_czo.conf.template.erb'),
notify => Service[supervisor],
}
}

View File

@@ -3,6 +3,7 @@ class kandra::prod_app_frontend_once {
include zulip::hooks::push_git_ref
include zulip::hooks::zulip_notify
include kandra::hooks::zulip_notify_schema_diff
include kandra::mirror_to_czo
zulip::cron { 'update-first-visible-message-id':
hour => '7',

View File

@@ -0,0 +1,13 @@
[program:mirror_to_czo]
# We record the hash of the script so that we can update this file
# with it, which will make `supervisorctl reread && supervisorctl
# update` restart this job.
command=uv run --no-sync /usr/local/bin/mirror_to_czo
directory=/home/zulip/deployments/current/
process_name=mirror_to_czo_<%= @script_hash %>
priority=10
autostart=true
autorestart=true
user=zulip
redirect_stderr=true
stdout_logfile=/var/log/zulip/mirror_to_czo.log