How to use the @brigadecore/brigadier/out/events.EventRegistry function in @brigadecore/brigadier

To help you get started, we’ve selected a few @brigadecore/brigadier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brigadecore / brigade / brigade-worker / src / brigadier.ts View on Github external
import * as groupImpl from "@brigadecore/brigadier/out/group";
import * as eventsImpl from "@brigadecore/brigadier/out/events";
import { JobRunner } from "./k8s";

// These are filled by the 'fire' event handler.
let currentEvent = null;
let currentProject = null;

/**
 * events is the main event registry.
 *
 * New event handlers can be registered using `events.on(name: string, (e: BrigadeEvent, p: Project) => {})`.
 * where the `name` is the event name, and the callback is the function to be
 * executed when the event is triggered.
 */
export let events = new eventsImpl.EventRegistry();

/**
 * fire triggers an event.
 *
 * The fire() function takes a BrigadeEvent (the event to be triggered) and a
 * Project (the owner project). If an event handler is found, it is executed.
 * If no event handler is found, nothing happens.
 */
export function fire(e: eventsImpl.BrigadeEvent, p: eventsImpl.Project) {
  currentEvent = e;
  currentProject = p;
  events.fire(e, p);
}

/**
 * Job describes a particular job.