|
| 1 | +# UBahn - Backend Job |
| 2 | + |
| 3 | +Queries U-bahn's database for users and posts them to kafka to be picked up by the u-bahn-skill processor |
| 4 | + |
| 5 | +## Dependencies |
| 6 | + |
| 7 | +- Nodejs(v12+) |
| 8 | +- docker |
| 9 | +- Redis |
| 10 | +- PostgreSQL |
| 11 | + |
| 12 | +## Configuration |
| 13 | + |
| 14 | +Configuration for the skill processor trigger is at `config/default.js`. |
| 15 | +The following parameters can be set in config files or in env variables: |
| 16 | + |
| 17 | +- LOG_LEVEL: the log level; default value: 'debug' |
| 18 | +- DB_NAME: the database name |
| 19 | +- DB_USERNAME: the database username |
| 20 | +- DB_PASSWORD: the database password |
| 21 | +- DB_HOST: the database host |
| 22 | +- DB_PORT: the database port |
| 23 | +- AUTH0_URL: Auth0 URL, used to get TC M2M token |
| 24 | +- AUTH0_AUDIENCE: Auth0 audience, used to get TC M2M token |
| 25 | +- TOKEN_CACHE_TIME: Auth0 token cache time, used to get TC M2M token |
| 26 | +- AUTH0_CLIENT_ID: Auth0 client id, used to get TC M2M token |
| 27 | +- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token |
| 28 | +- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token |
| 29 | +- BUSAPI_URL: Topcoder Bus API URL |
| 30 | +- KAFKA_ERROR_TOPIC: The error topic at which bus api will publish any errors |
| 31 | +- KAFKA_MESSAGE_ORIGINATOR: The originator value for the kafka messages |
| 32 | +- SKILL_SYNC_TOPIC: the sync skill Kafka message topic, default value is 'backgroundjob.sync.user.skills' |
| 33 | +- REDIS_HOST: the redis host, default value is 'localhost', |
| 34 | +- REDIS_PORT: the redis port, default value is 6379, |
| 35 | +- REDIS_PASSWORD: the redis password, |
| 36 | +- REDIS_USER: the redis user, |
| 37 | +- USER_RECORD_OFFSET: the record offset, default value is 0, |
| 38 | +- USER_RECORD_LIMIT: the record limit, default value is 10, |
| 39 | +- OFFSET_REDIS_KEY: the redis of offset key, default value is 'USER_RECORD_OFFSET', |
| 40 | +- SLEEP_TIME: The pause time between two create operations, default value: 1000 ms |
| 41 | + |
| 42 | +## Local install with Docker |
| 43 | + |
| 44 | +- Navigate to the directory `docker-redis-db` |
| 45 | +- Run the command `docker-compose up -d` |
| 46 | + |
| 47 | +## Local deployment |
| 48 | + |
| 49 | +1. From the project root directory, run the following command to install the dependencies |
| 50 | + |
| 51 | + ```bash |
| 52 | + npm install |
| 53 | + ``` |
| 54 | + |
| 55 | +2. To run linters if required |
| 56 | + |
| 57 | + ```bash |
| 58 | + npm run lint |
| 59 | + ``` |
| 60 | + |
| 61 | + To fix possible lint errors: |
| 62 | + |
| 63 | + ```bash |
| 64 | + npm run lint:fix |
| 65 | + ``` |
| 66 | + |
| 67 | +3. Start the processor and health check dropin |
| 68 | + |
| 69 | + ```bash |
| 70 | + npm start |
| 71 | + ``` |
| 72 | + |
| 73 | +## Local Deployment with Docker |
| 74 | + |
| 75 | +To run the Skill Processor Trigger using docker, follow the below steps |
| 76 | + |
| 77 | +1. Navigate to the directory `docker` |
| 78 | + |
| 79 | +2. Rename the file `sample.api.env` to `api.env` |
| 80 | + |
| 81 | +3. Set the auth0 config in the file `api.env` |
| 82 | + |
| 83 | +4. Once that is done, run the following command |
| 84 | + |
| 85 | + ```bash |
| 86 | + docker-compose up |
| 87 | + ``` |
| 88 | + |
| 89 | +5. When you are running the application for the first time, It will take some time initially to download the image and install the dependencies |
| 90 | + |
| 91 | +## Verification |
| 92 | + |
| 93 | +1. config `AUTH0_CLIENT_ID`, `AUTH0_CLIENT_SECRET` |
| 94 | +2. run `npm run insert-data` to load test data to db |
| 95 | +3. run `npm start` to post event when there is not offset key in redis |
| 96 | +4. run `npm start` to post event when there is an offset key in redis |
| 97 | +6. watch the app console, it will show the offset and post message |
0 commit comments