chat_archiver: Allow passing multiple channels on CLI

pull/353/head
Mike Lang 1 year ago committed by Mike Lang
parent 91910c0972
commit 260293d40d

@ -457,7 +457,7 @@ def merge_batch_files(path, batch_time):
os.remove(batch_file) os.remove(batch_file)
def main(channel, nick, oauth_token_path, base_dir='/mnt', name=None, merge_interval=60, metrics_port=8008): def main(nick, oauth_token_path, *channels, base_dir='/mnt', name=None, merge_interval=60, metrics_port=8008):
with open(oauth_token_path) as f: with open(oauth_token_path) as f:
oauth_token = f.read() oauth_token = f.read()
# To ensure uniqueness even if multiple instances are running on the same host, # To ensure uniqueness even if multiple instances are running on the same host,
@ -470,24 +470,28 @@ def main(channel, nick, oauth_token_path, base_dir='/mnt', name=None, merge_inte
stopping = gevent.event.Event() stopping = gevent.event.Event()
gevent.signal_handler(signal.SIGTERM, stopping.set) gevent.signal_handler(signal.SIGTERM, stopping.set)
merger = gevent.spawn(merge_all, mergers = [
os.path.join(base_dir, channel, "chat"), gevent.spawn(merge_all,
interval=merge_interval, os.path.join(base_dir, channel, "chat"),
stopping=stopping interval=merge_interval,
) stopping=stopping
) for channel in channels
]
prom.start_http_server(metrics_port) prom.start_http_server(metrics_port)
logging.info("Starting") logging.info("Starting")
for index in count(): for index in count():
# To ensure uniqueness between clients, include a client number # To ensure uniqueness between clients, include a client number
archiver = Archiver("{}.{}".format(name, index), base_dir, [channel], nick, oauth_token) archiver = Archiver("{}.{}".format(name, index), base_dir, channels, nick, oauth_token)
worker = gevent.spawn(archiver.run) archive_worker = gevent.spawn(archiver.run)
workers = mergers + [archive_worker]
# wait for either graceful exit, error, or for a signal from the archiver that a reconnect was requested # wait for either graceful exit, error, or for a signal from the archiver that a reconnect was requested
gevent.wait([stopping, worker, merger, archiver.got_reconnect], count=1) gevent.wait([stopping, archiver.got_reconnect] + workers, count=1)
if stopping.is_set(): if stopping.is_set():
archiver.stop() archiver.stop()
worker.get() for worker in workers:
worker.get()
break break
# if got reconnect, discard the old archiver (we don't care even if it fails after this) # if got reconnect, discard the old archiver (we don't care even if it fails after this)
# and make a new one # and make a new one
@ -497,10 +501,11 @@ def main(channel, nick, oauth_token_path, base_dir='/mnt', name=None, merge_inte
# the only remaining case is that something failed. stop everything and re-raise. # the only remaining case is that something failed. stop everything and re-raise.
logging.warning("Stopping due to worker dying") logging.warning("Stopping due to worker dying")
stopping.set() stopping.set()
worker.join() archiver.stop()
merger.join() for worker in workers:
# at least one of these two should raise worker.join()
worker.get() # at least one of these should raise
merger.get() for worker in workers:
worker.get()
assert False, "Worker unexpectedly exited successfully" assert False, "Worker unexpectedly exited successfully"
logging.info("Gracefully stopped") logging.info("Gracefully stopped")

@ -528,7 +528,7 @@
[if $.enabled.chat_archiver then "chat_archiver"]: { [if $.enabled.chat_archiver then "chat_archiver"]: {
image: $.get_image("chat_archiver"), image: $.get_image("chat_archiver"),
restart: "always", restart: "always",
command: [$.chat_archiver.channel, $.chat_archiver.user, "/token", "--name", $.localhost], command: [$.chat_archiver.user, "/token", $.chat_archiver.channel, "--name", $.localhost],
volumes: ["%s:/mnt" % $.segments_path, "%s:/token" % $.chat_archiver.token_path], volumes: ["%s:/mnt" % $.segments_path, "%s:/token" % $.chat_archiver.token_path],
[if "chat_archiver" in $.ports then "ports"]: ["%s:8008" % $.ports.chat_archiver], [if "chat_archiver" in $.ports then "ports"]: ["%s:8008" % $.ports.chat_archiver],
environment: $.env, environment: $.env,

Loading…
Cancel
Save