@iad-os/irene-kills
TypeScript icon, indicating that this package has built-in type declarations

0.0.5-alpha • Public • Published

IK-logo

Welcome to @iad-os/irene-kills 👋

Version License: Apache--2.0

Yes ... only if necessary, but ... Irene Kills!

Table of content

-----------------------------------------------------

📝 About The Project

Irene Kills is a library written in TypeScript that allows you to easily manage the application life-cycle. We created this library to build applications that respect cloud native principles and to find a standard and tested way to manage the life cycle of our microservices.

IK - goals It allows you to create applications that are resilient, able to detect changes in the system, detect errors and react accordingly, for example by killing itself or going into a sick state.

Ensures that when the application is in a "healthy" state it is actually ready to respond. If an error occurs in the system that could affect the operation of the application, the application will notice the change and change its status.

-----------------------------------------------------

Prerequisites

  • node >= 16.13 <17

-----------------------------------------------------

Install

npm install @iad-os/irene-kills

-----------------------------------------------------

Usage

Instantiate and configure examples:

import { IreneKills } from '@iad-os/irene-kills';
import { introspectCredentials } from '../main-auth';
import * as dbService from '../main-db';
import * as apiService from '../main-http';
import log from '../config/log';

const irene = new IreneKills({ logger: log({ tags: ['ik'] }) });

irene.resource<{ logger: ReturnType<typeof log> }>('database', {
  value: { logger: log({ tags: ['db'] }) },
  need: async ({ value: { logger } }) => {
    logger.info('⏳ initialize db connection');
    await dbService.start();
    return { logger };
  },
  check: async ({ value: { logger } }) => {
    try {
      await dbService.checkDb();
      logger.info('✅ OK check db connection');
      return true;
    } catch (err) {
      logger.error({ error: err }, '💥 KO check db connection');
      return false;
    }
  },

  on: {
    healthcheck: async () => {
      await dbService.checkDb();
      return { healthy: true, kill: false };
    },
  },
});

irene.resource('http', {
  activate: async () => {
    try {
      await apiService.start();
      log({ tags: ['server'] }).info('✅ Application started');
      return { kill: false, healthy: true };
    } catch (err) {
      return { kill: true, healthy: false };
    }
  },
});

irene.resource<{ logger: ReturnType<typeof log> }>('oidc', {
  value: { logger: log({ tags: ['odic'] }) },
  check: async ({ value: { logger } }) => {
    try {
      await introspectCredentials();
      logger.info(`✅ OK Credentials`);
      return true;
    } catch (error) {
      logger.error(error, `💥 KO Credentials`);
      return false;
    }
  },
});

export default irene;

Wake up Irene in main.ts:

irene
  .wakeUp()
  .finally(() =>
    log({ tags: ['wakeup', 'application', 'status'] }).info(
      `⚙️  APPLICATION STATUS -> ${irene.mood()}`
    )
  );

Current application status:

irene.mood()

Trigger healthcheck:

irene.healthcheck();

For more examples check under __test__ folder.

-----------------------------------------------------

Run tests

npm run test

-----------------------------------------------------

Author

👤 Daniele Fiungo daniele.fiungo@iad2.it

-----------------------------------------------------

Contributors

Show your support

Give a ⭐️ if this project helped you!

-----------------------------------------------------

License

Licensed under the APLv2. See the LICENSE file for details.

Made with ❤️ by IAD

Readme

Keywords

none

Package Sidebar

Install

npm i @iad-os/irene-kills

Weekly Downloads

0

Version

0.0.5-alpha

License

Apache-2.0

Unpacked Size

137 kB

Total Files

23

Last publish

Collaborators

  • rcaputo
  • daniele.fiungo
  • nicola.vurchio
  • irenelb