Skip to content

ELEVATE-Project/scheduler

Repository files navigation

Scheduler Service

CircleCI Duplicated Lines (%) Coverage VulnerabilitiesPrettier Docs Docs

GitHub package.json version (subfolder of monorepo) License

CircleCI insights

CircleCI


The Mentoring building block enables effective mentoring interactions between mentors and mentees. The capability aims to create a transparent eco-system to learn, connect, solve, and share within communities.MentorED is an open source mentoring application that facilitates peer learning and professional development by creating a community of mentors and mentees.

System Requirements

  • Operating System: Ubuntu 22
  • Node.js: v20
  • PostgreSQL: 16
  • Citus: 12.1

Setup Options

Elevate scheduler services can be setup in local using two methods:

Dockerized service with local dependencies(Intermediate)

A. Dockerized Service With Local Dependencies

Expectation: Run single docker containerized service with existing local (in host) or remote dependencies.

Local Dependencies Steps

  1. Update dependency (Mongo v4.1.4, Kafka etc) IP addresses in .env with "host.docker.internal".

    Eg:

     #MongoDb Connectivity Url
     MONGODB_URL = mongodb://host.docker.internal:27017/elevate-scheduler
    
     #Kafka Host Server URL
     KAFKA_URL = host.docker.external:9092
    
  2. Find host.docker.internal IP address and added it to mongod.conf file in host.

    Eg: If host.docker.internal is 172.17.0.1, mongod.conf:

    # network interfaces
    net:
        port: 27017
        bindIp: "127.0.0.1,172.17.0.1"
    

    Note: Steps to find host.docker.internal IP address & location of mongod.conf is operating system specific. Refer this for more information.

  3. Build the docker image.

    /ELEVATE/scheduler$ docker build -t elevate/scheduler:1.0 .
    
  4. Run the docker container.

    • For Mac & Windows with docker v18.03+:

      $ docker run --name user elevate/scheduler:1.0
      
    • For Linux:

      $ docker run --name user --add-host=host.docker.internal:host-gateway elevate/scheduler:1.0`
      

      Refer this for more information.

Remote Dependencies Steps

  1. Update dependency (Mongo v4.1.4, Kafka etc) Ip addresses in .env with respective remote server IPs.

    Eg:

     #MongoDb Connectivity Url
     MONGODB_URL = mongodb://10.1.2.34:27017/elevate-scheduler
    
     #Kafka Host Server URL
     KAFKA_URL = 11.2.3.45:9092
    
  2. Add Bind IP to mongod.conf in host:

    Follow instructions given here.

    Note: Instructions might differ based on MongoDB version and operating system.

  3. Build the docker image.

    /ELEVATE/scheduler$ docker build -t elevate/scheduler:1.0 .
    
  4. Run the docker container.

    $ docker run --name scheduler elevate/scheduler:1.0
    
Local Service with local dependencies(Hardest)

B. Local Service With Local Dependencies

Expectation: Run single service with existing local dependencies in host (Non-Docker Implementation).

Installations

Install Node.js LTS

Refer to the NodeSource distributions installation scripts for Node.js installation.

$ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

Install Build Essential

$ sudo apt-get install build-essential

Install PM2

Refer to How To Set Up a Node.js Application for Production on Ubuntu 22.04.

Run the following command

$ sudo npm install pm2@latest -g

Install Redis

Refer to Redis Ubuntu 22.04 setup guide

  1. Update the package list:

    $ sudo apt update
  2. Install Redis:

    $ sudo apt install redis-server
  3. Configure Redis for systemd:

    $ sudo nano /etc/redis/redis.conf

    Find the supervised directive and change it to "systemd" as follows:

    . . .
    # If you run Redis from upstart or systemd, Redis can interact with your
    # supervision tree. Options:
    #   supervised no      - no supervision interaction
    #   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
    #   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
    #   supervised auto    - detect upstart or systemd method based on
    #                        UPSTART_JOB or NOTIFY_SOCKET environment variables
    # Note: these supervision methods only signal "process is ready."
    #       They do not enable continuous liveness pings back to your supervisor.
    supervised systemd
    . . .
    

    Save and exit.

  4. Restart the Redis service:

    $ sudo systemctl restart redis.service

Setting up Repository

Clone the scheduler repository to /opt/backend directory

opt/backend$ git clone -b develop-2.5 --single-branch "https://github.com/ELEVATE-Project/scheduler.git"

Install Npm packages from src directory

backend/scheduler/src$ sudo npm i

Create .env file in src directory

scheduler/src$ sudo nano .env

Copy-paste the following env variables to the .env file:

# Scheduler Service Config

# Application Base URL
APPLICATION_BASE_URL=/scheduler/

# Kafka hosted server URL
KAFKA_URL=localhost:9092

# Kafka topic to push notification data
NOTIFICATION_KAFKA_TOPIC='develop.notifications'

# MongoDB URL
MONGODB_URL='mongodb://localhost:27017/tl-cron-rest'

# App running port
APPLICATION_PORT=4000

# Api doc URL
API_DOC_URL='/api-doc'

APPLICATION_ENV=development

ENABLE_LOG='true'

ERROR_LOG_LEVEL='silly'
DISABLE_LOG=false

DEFAULT_QUEUE='email'

REDIS_HOST='localhost'
REDIS_PORT=6379

Save and exit.

Start the Service

Navigate to the src folder of scheduler service and run pm2 start command:

scheduler/src$ pm2 start app.js -i 2 --name elevate-scheduler

Run pm2 ls command

$ pm2 ls

Output should look like this (Sample output, might slightly differ in your installation):

┌────┬─────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name                    │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼─────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 15 │ elevate-scheduler       │ default     │ 1.0.0   │ cluster │ 86368    │ 47h    │ 0    │ online    │ 0%       │ 89.8mb   │ jenkins  │ disabled │
│ 16 │ elevate-scheduler       │ default     │ 1.0.0   │ cluster │ 86378    │ 47h    │ 0    │ online    │ 0%       │ 86.9mb   │ jenkins  │ disabled │
└────┴─────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

This concludes the services and dependency setup.


Run tests

Integration tests

npm run test:integration

To know more about integration tests and their implementation refer to the project Wiki.

Unit tests

npm test

Used in

This project was built to be used with Mentoring Service and User Service.

The frontend/mobile application repo.

You can learn more about the full implementation of MentorEd here .

Team


Open Source Dependencies

Several open source dependencies that have aided Mentoring's development:

NodeJS MongoDB Apache Kafka Jest Git