bcgov / nr-site-bc-registries

Apache License 2.0
1 stars 0 forks source link

Multiple pods fix #51

Closed mgtennant closed 2 years ago

mgtennant commented 2 years ago

Description

Added an entity called Actions, it has two boolean values: updating and hasData. Updating is set to true when a pod starts updating the database and is set to false after the database update has completed. hasData is set to false before updating the database and is set to true after the database update has succeeded.

When a backend pod starts up it checks hasData to see if it needs to fetch initial data for the database. It will only do this immediate update to the database if hasData and updating are both false.

The cron job is currently set to fire once a day. Once one pod starts updating, all other pods will be blocked from doing so until the update job is done. Since the cron job starts at the same time in each pod (plus the random delay) only one of the pods should end up updating the database.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist

Further comments

github-actions[bot] commented 2 years ago

Backend coverage report

Coverage after merging multiple-pods-fix into main will be
25.96%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   app.controller.ts0%100%0%0%1, 10, 2, 5–6, 9
   app.module.ts0%0%100%0%1, 10–19, 2, 20–27, 29, 3, 30–32, 32, 32–33, 35, 4, 43, 43, 45, 45–46, 46, 5–7, 75, 8
   app.service.ts0%100%0%0%1, 13, 2, 5–6, 8
   main.ts0%0%0%0%1, 15–16, 18, 18, 18–19, 2, 20–21, 23, 3–4, 7–8
src/actions
   actions.controller.ts0%100%0%0%1, 12–14, 18–19, 2, 23–24, 3–4, 8–9
   actions.module.ts0%100%100%0%1, 13, 2–5
   actions.service.ts0%100%0%0%1, 12, 16–18, 2, 22, 26, 3, 30–31, 35–37, 41–44, 46, 48, 53–55, 57, 6, 9
src/actions/dto
   action.dto.ts0%100%100%0%1
   create-action.dto.ts0%100%100%0%1–2, 4
   update-action.dto.ts0%100%100%0%1, 3
src/actions/entities
   action.entity.ts0%100%0%0%1, 10, 13, 4, 6, 8
src/cron
   cron.module.ts0%100%100%0%1, 10–19, 2, 20–29, 3, 30–35, 4–7, 78, 8–9
   cron.service.ts0%0%0%0%1, 10, 100, 107–109, 11, 110–119, 12, 120–122, 124, 13–14, 142, 147, 149, 15, 153–155, 16, 163, 165, 17–18, 185, 189, 19, 190–199, 2, 20, 200–205, 209, 21, 210–215, 217–219, 22, 220–223, 225–229, 23, 230–231, 233–239, 24, 241–247, 249–255, 257–262, 264–270, 272–278, 280–286, 288–294, 296–299, 3, 300–302, 304–310, 312–318, 320–326, 328–334, 336, 340–343, 345–347, 349–351, 353–355, 357–359, 361–363, 365–367, 369–371, 373–375, 377–379, 381–383, 385–387, 389–391, 393–395, 397–399, 4, 401–403, 405, 409, 41, 411, 419–422, 432–435, 44, 46–49, 5, 50–59, 6, 60–62, 67, 67–68, 70–71, 71–73, 78, 8, 80, 82–83, 83, 83–87, 89, 9, 91, 93, 93, 93, 96–98
src/sites
   sites.controller.ts0%100%0%0%1, 10–11, 14–15, 19, 2, 20, 24–25, 29, 3, 30, 34–35, 39, 4, 40, 5–6
   sites.module.ts0%100%100%0%1, 13, 2–5
   sites.service.ts0%100%0%0%1, 10, 13, 17–19, 2, 23, 27, 3, 31–32, 36–39, 4, 41, 43, 48–50, 52
src/sites/dto
   create-site.dto.ts0%100%100%0%1–2, 4
   site.dto.ts0%100%100%0%1, 103, 109, 115, 121, 127, 13, 133, 139, 145, 151, 157, 163, 169, 175, 181, 187, 19, 193, 199, 205, 211, 217, 223, 229, 235, 241, 247, 25, 253, 259, 265, 3, 31, 37, 43, 49, 55, 61, 67, 7, 73, 79, 85, 91, 97
   update-site.dto.ts0%100%100%0%1, 3
src/sites/entities
   site.entity.ts0%100%0%0%1, 101, 11, 14, 16, 18, 2, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 5, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98
src/sraecass
   sraecass.controller.ts0%100%0%0%1, 10, 13–14, 18–19, 2, 23–24, 28–29, 3, 33–34, 38–39, 4–5, 9
   sraecass.module.ts0%100%100%0%1, 13, 2–5
   sraecass.service.ts0%100%0%0%1, 10, 13, 17–19, 2, 23, 27, 3, 31–32, 36–39, 4, 41, 43, 48–50, 52
src/sraecass/dto
   create-sraecass.dto.ts0%100%100%0%1–2, 4
   sraecass.dto.ts0%100%100%0%1
   update-sraecass.dto.ts0%100%100%0%1, 3
src/sraecass/entities
   sraecass.entity.ts0%100%0%0%11, 13, 15, 17, 19, 2, 21, 23, 25, 27, 30, 5, 7, 9
src/srapproa
   srapproas.controller.ts0%100%0%0%1, 10, 13–14, 18–19, 2, 23–24, 28–29, 3, 33–34, 38–39, 4–5, 9
   srapproas.module.ts0%100%100%0%1, 13, 2–5
   srapproas.service.ts0%100%0%0%1, 10, 13, 17–19, 2, 23, 27,