(
config: Partial<PluginsServerConfig>,
makePiscina: (config: PluginsServerConfig) => Piscina = defaultMakePiscina,
capabilities: PluginServerCapabilities | null = null
)
| 40 | } |
| 41 | |
| 42 | export async function startPluginsServer( |
| 43 | config: Partial<PluginsServerConfig>, |
| 44 | makePiscina: (config: PluginsServerConfig) => Piscina = defaultMakePiscina, |
| 45 | capabilities: PluginServerCapabilities | null = null |
| 46 | ): Promise<ServerInstance> { |
| 47 | const timer = new Date() |
| 48 | |
| 49 | const serverConfig: PluginsServerConfig = { |
| 50 | ...defaultConfig, |
| 51 | ...config, |
| 52 | } |
| 53 | |
| 54 | status.updatePrompt(serverConfig.PLUGIN_SERVER_MODE) |
| 55 | status.info('ℹ️', `${serverConfig.WORKER_CONCURRENCY} workers, ${serverConfig.TASKS_PER_WORKER} tasks per worker`) |
| 56 | |
| 57 | // Structure containing initialized clients for Postgres, Kafka, Redis, etc. |
| 58 | let hub: Hub | undefined |
| 59 | |
| 60 | // Used to trigger reloads of plugin code/config |
| 61 | let pubSub: PubSub | undefined |
| 62 | |
| 63 | // A Node Worker Thread pool |
| 64 | let piscina: Piscina | undefined |
| 65 | |
| 66 | // Ingestion Kafka consumer. Handles both analytics events and screen |
| 67 | // recording events. The functionality roughly looks like: |
| 68 | // |
| 69 | // 1. events come in via the /e/ and friends endpoints and published to the |
| 70 | // plugin_events_ingestion Kafka topic. |
| 71 | // 2. this queue consumes from the plugin_events_ingestion topic. |
| 72 | // 3. update or creates people in the Persons table in pg with the new event |
| 73 | // data. |
| 74 | // 4. passes he event through `processEvent` on any plugins that the team |
| 75 | // has enabled. |
| 76 | // 5. publishes the resulting event to a Kafka topic on which ClickHouse is |
| 77 | // listening. |
| 78 | // |
| 79 | // The queue also handles async handlers, reading from |
| 80 | // clickhouse_events_json topic. |
| 81 | let queue: IngestionConsumer | undefined | null |
| 82 | |
| 83 | // Kafka consumer. Handles events that we couldn't find an existing person |
| 84 | // to associate. The buffer handles delaying the ingestion of these events |
| 85 | // (default 60 seconds) to allow for the person to be created in the |
| 86 | // meantime. |
| 87 | let bufferConsumer: Consumer | undefined |
| 88 | let jobsConsumer: Consumer | undefined |
| 89 | let schedulerTasksConsumer: Consumer | undefined |
| 90 | |
| 91 | let httpServer: Server | undefined // healthcheck server |
| 92 | let mmdbServer: net.Server | undefined // geoip server |
| 93 | |
| 94 | let graphileWorker: GraphileWorker | undefined |
| 95 | |
| 96 | let closeHub: () => Promise<void> | undefined |
| 97 | |
| 98 | let lastActivityCheck: NodeJS.Timeout | undefined |
| 99 | let stopEventLoopMetrics: (() => void) | undefined |
searching dependent graphs…