2.7.1 • Published 2 years ago

@microloop/scheduler-service v2.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

scheduler-service

LoopBack

This is a loopback4 component for scheduling events in calendar (scheduler/calendar server).

Various features of Scheduler Service:

  1. CRUD feature: Basic add/edit/delete Event/Invitation in calendar. (As a REST API)

  2. Reminder Feature: Support or provide integration with notification/reminder service, which has the option of sending email/popup and SMS notification.

  3. Importing Calendar: The Scheduler supports exporting all its event data to iCal format, and it supports importing events from an iCal file into the Scheduler.

  4. Third party calendar support: Provide a way to import events information from third party components like : Outlook and Google Calendar.

Main feature set:

  • Calendar
  • Calendar Subscription
  • Working Hours
  • Events
  • Event Attendee
  • Event Attachment

You can see the database schema here.

To get started with a basic implementation of this service, see /sandbox/scheduler-example.

Install

npm install @microloop/scheduler-service

Usage

  • Create a new Loopback4 Application (If you don't have one already) lb4 testapp
  • Install the scheduler service npm i @microloop/scheduler-service
  • Set the environment variables.
  • Run the migrations.
  • Bind the Scheduler Config to SchedulerBindings.Config key-
    this.bind(SchedulerBindings.Config).to({
        jwtIssuer: process.env.JWT_ISSUER;
        jwtSecret: process.env.JWT_SECRET;
    });
  • Add the SchedulerComponent to your Loopback4 Application (in application.ts).
    // import the SchedulerComponent
    import {SchedulerComponent} from '@microloop/scheduler-service';
    ...
    // add Component for SchedulerComponent
    this.component(SchedulerComponent);
    ...
  • Set up a Loopback4 Datasource with dataSourceName property set to SchedulerDatasourceName. You can see an example datasource here.
  • Set up a Loopback4 Datasource with dataSourceName property set to AuthCacheDatasourceName. You can see an example datasource here.
  • Start the application npm start

Workflow Diagrams

Schedular

event

Environment Variables

Do not forget to set Environment variables. The examples below show a common configuration for a PostgreSQL Database and Redis Database running locally.

NODE_ENV=dev
LOG_LEVEL=DEBUG
HOST=0.0.0.0
PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_USER=pg_service_user
DB_PASSWORD=pg_service_user_password
DB_DATABASE=schedular_db
DB_SCHEMA=public
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_URL=redis_url
REDIS_PASSWORD=redis_service_user_password
REDIS_DATABASE=redis_schedular_db
JWT_SECRET=super_secret_string
JWT_ISSUER=https://authentication.service
NameRequiredDefault ValueDescription
NODE_ENVYNode environment value, i.e. dev, test, prod
LOG_LEVELYLog level value, i.e. error, warn, info, verbose, debug
HOSTYHost for the service to run under, i.e. 0.0.0.0
PORTY3000Port for the service to listen on.
DB_HOSTYHostname for the database server.
DB_PORTYPort for the database server.
DB_USERYUser for the database.
DB_PASSWORDYPassword for the database user.
DB_DATABASEYDatabase to connect to on the database server.
DB_SCHEMAYpublicDatabase schema used for the data source. In PostgreSQL, this will be public unless a schema is made explicitly for the service.
REDIS_HOSTYHostname for the Redis server.
REDIS_PORTYPort to connect to redis server.
REDIS_URLYFully composed URL for Redis connection. Used
instead of other settings if set.
REDIS_PASSWORDYPassword for the redis user.
REDIS_DATABASEYDatabase to connect to on the redis server.
JWT_SECRETYSymmetric signing key of the JWT token.
JWT_ISSUERYIssuer of the JWT token.

Setting up a DataSource

Here is a sample Implementation DataSource implementation using environment variables and PostgreSQL as the data source.

import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';
import {SchedulerDatasourceName} from '@microloop/scheduler-service';

const config = {
  name: SchedulerDatasourceName,
  connector: 'postgresql',
  host: process.env.DB_HOST,
  port: process.env.DB_PORT,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_DATABASE,
  schema: process.env.DB_SCHEMA,
};

@lifeCycleObserver('datasource')
export class SchedulerDataSource extends juggler.DataSource implements LifeCycleObserver {
  static dataSourceName = SchedulerDatasourceName;
  static readonly defaultConfig = config;

  constructor(
    @inject(`datasources.config.${SchedulerDatasourceName}`, {optional: true})
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}

Here is a sample Implementation Cache DataSource implementation using environment variables and Redis as the data source.

import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
import {juggler} from '@loopback/repository';

const config = {
  name: 'AuthCache',
  connector: 'kv-redis',
  url: '',
  host: process.env.REDIS_HOST,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD,
  db: process.env.REDIS_DB,
};

@lifeCycleObserver('datasource')
export class AuthCacheDataSource extends juggler.DataSource implements LifeCycleObserver {
  static dataSourceName = 'AuthCache';
  static readonly defaultConfig = config;

  constructor(
    @inject('datasources.config.AuthCache', {optional: true})
    dsConfig: object = config,
  ) {
    super(dsConfig);
  }
}

Migrations

The migrations required for this service are processed during the installation automatically if you set the SCHEDULER_MIGRATION or BLECO_MIGRATION env variable. The migrations use db-migrate with db-migrate-pg driver for migrations, so you will have to install these packages to use auto-migration. Please note that if you are using some pre-existing migrations or database, they may be effected. In such scenario, it is advised that you copy the migration files in your project root, using the SCHEDULER_MIGRATION_COPY or BLECO_MIGRATION_COPY env variables. You can customize or cherry-pick the migrations in the copied files according to your specific requirements and then apply them to the DB.

Database Schema

db-schema

API's Details

Visit the OpenAPI spec docs

Feedback

If you've noticed a bug or have a question or have a feature request, search the issue tracker to see if someone else in the community has already created a ticket. If not, go ahead and make one! All feature requests are welcome. Implementation time may vary. Feel free to contribute the same, if you can. If you think this extension is useful, please star it. Appreciation really helps in keeping this project alive.

Contributing

Please read CONTRIBUTING.md for details on the process for submitting pull requests to us.

Code of conduct

Code of conduct guidelines here.

License

MIT