message: Add worker_thread workarounds
diff: @@ -35,7 +35,6 @@ import { MatrixAction } from "../models/MatrixAction";
  import { BridgeConfig } from "../config/BridgeConfig";
  import { MembershipQueue } from "../util/MembershipQueue";
  import { BridgeStateSyncer } from "./BridgeStateSyncer";
  -import { spawnMetricsWorker } from "../workers/MetricsWorker";
  import { Registry } from "prom-client";
  const log = getLogger("IrcBridge");
  @@ -45,6 +44,16 @@ const DELAY_FETCH_ROOM_LIST_MS = 3 * 1000;
  const DEAD_TIME_MS = 5 * 60 * 1000;
  const TXN_SIZE_DEFAULT = 10000000 // 10MB
  +let spawnMetricsWorker: undefined|(
  + (port: number, hostname: string|undefined, metricFunc: () => string) => void
  +) = undefined;
  +try {
  + spawnMetricsWorker = require("../workers/MetricsWorker").spawnMetricsWorker;
  +}
  +catch (ex) {
  + log.warn(`Your version of node does NOT support worker_threads. Workers will be unavailable`);
  +}
  +
  export class IrcBridge {
  public static readonly DEFAULT_LOCALPART = "appservice-irc";
  public onAliasQueried: (() => void)|null = null;
  @@ -192,15 +201,17 @@ export class IrcBridge {
  const metrics = this.bridge.getPrometheusMetrics(!usingRemoteMetrics, registry);
  if (this.config.ircService.metrics.port) {
  + if (!spawnMetricsWorker) {
  + log.error("Your version of NodeJS doesn't support workers, so workerized metrics cannot be used");
  + throw Error('Unable to start metrics');
  + }
  log.info(
  `Started metrics on http://${this.config.ircService.metrics.host}:${this.config.ircService.metrics.port}`
  );
  spawnMetricsWorker(
  this.config.ircService.metrics.port,
  this.config.ircService.metrics.host,
  - () => {
  - return registry.metrics();
  - }
  + registry.metrics.bind(registry),
  );
  }
  