ugent-library / old-people-service

People service
Apache License 2.0
0 stars 0 forks source link

people-service

Person service

Build process

go build

Prepare environment variables

Declare the following environment variables,

or store them in file .env in the root of your folder (important: exclude export statement) (see .env.example):

Run database migrations

Before starting the application you should run any pending database migrations.

For this we use atlas, which can be installed via homebrew on your MAC:

brew install ariga/tap/atlas

Or manually

curl -sSf https://atlasgo.sh | sh

Atlas is a database migration tool, that is used both for generating the necessary sql migration files (during development), and for managing the state of the running database (in production).

Copy the example file atlas.hcl.example to atlas.hcl and update where necessary

Now run atlas migrate apply --env local to apply any pending migrations

If you change anything to your entgo schema, run this atlas command:

atlas migrate diff <migration-name> --env local

This will generate new sql files in folder ent/migrate/migrations You can update these by hand, but be sure to run atlas hash --env local afterwards to update the checksum file atlas.sum

Due to some inconveniences we can only use atlas during development, in order to generate migration files. These are stored in ent/migrate/migrations

In production we use tern. Make sure that directories ent/migrate/migrations (for atlas) and etc/migrations (for tern) are kept in sync. And note that tern uses a different naming for sql files (prefix is a padded number instead of a timestamp)

Start the api server (openapi)

$ ./people-service server

Start NATS consumer organization

$ ./people-service inbox listen organization

Start NATS consumer person

$ ./people-service inbox listen person

run in docker

Build base docker image people-service:

$ docker build -t ugentlib/people-service .
$ docker push ugentlib/people-service

If image people-service is already docker github,

then you may skip that step.

Start set of services using docker compose:

$ docker compose up

Docker compose uses that image people-service

Update flow organizations

incoming message via NATS consumer

Any nats message on subject ${PEOPLE_NATS_STREAM_NAME}.organization is processed by the command people-service inbox listen organization. Expected is a CERIF XML blob. The message translates this XML into a list of attributes (with start and end date), and assigns them to a new/existing organization record with the following rules:

Problems:

call to openapi /api/v1/add-organization

Any call to the the openapi handler /api/v1/add-organization overwrites the existing record. Note that only updates that contain an id are considered updates, and those without as new records (for who a new id is minted).

Any call to this handler should happen rarely.

The route via the nats consumer is preferred.

Update flow people

incoming message via NATS consumer

Any nats message on subject ${PEOPLE_NATS_STREAM_NAME}.person is processed by the command people-service inbox listen person. Expected is a CERIF XML blob. The message translates this XML into a list of attributes (with start and end date), and assigns them to a new/existing person record with the following rules:

Problems:

nightly cron job that upserts student records

A nightly cron job reads student record from the ugent ldap

and inserts/updates person records. Matching on existing records

is done by matching on identifier historic_ugent_id.

The following attributes are overwritten:

Note that if no organization be found based on identifier->'ugent' then no (dummy) organization record is made for it. In that case the attribute is ignored.

nightly cron job that deactivates expired person records

All person records with column expiration_date set to a non zero value,

and whose expiration date has passed, are deactivated, by setting column

active to false. The expiration date is cleared also.

Expiration dates are taken from the ugent ldap entry.

call to openapi /api/v1/add-person