0.0.7-alpha ā€¢ Published 9 months ago

@iad-os/irene-kills-es v0.0.7-alpha

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
9 months ago

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

Table of content

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

šŸ“ About The Project

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

0.0.7-alpha

9 months ago

0.0.6-alpha

9 months ago

0.0.5-alpha

9 months ago