Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix to emphasize the update or addition of records #2926

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

Baalmart
Copy link
Contributor

@Baalmart Baalmart commented Jan 19, 2024

WHAT DOES THIS PR DO?

  • hotfix to emphasize the update or addition of records

  • Idempotency: Design the function (inside the /bin/store-readings-job job) to be idempotent. This means that even if it's run multiple times, it won't produce different results. For example, instead of inserting records into the database, the function could update them, leaving existing records unchanged.

  • We have been noticing Duplicate errors in the K8S logs yet we are using a mongoose update operation, things were not adding up!

  • Additionally, we noticed some differences in the measurements for staging and production for the same site at the same time --- we think this fix could help to rectify this issue too.

HOW DO I TEST OUT THIS PR?

cd src/device-registry
npm install
npm run dev-mac

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (113a283) 30.98% compared to head (db334ae) 30.97%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           staging    #2926      +/-   ##
===========================================
- Coverage    30.98%   30.97%   -0.01%     
===========================================
  Files          184      184              
  Lines        23812    23815       +3     
  Branches      3055     3055              
===========================================
  Hits          7377     7377              
- Misses       16318    16321       +3     
  Partials       117      117              
Files Coverage Δ
src/device-registry/bin/store-readings-job.js 25.49% <0.00%> (-1.60%) ⬇️

const res = await ReadingModel("airqo").updateOne(doc, doc, {
upsert: true,
});
const filter = { site_id: doc.site_id, time: doc.time };
Copy link
Contributor Author

@Baalmart Baalmart Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly stating the filter we shall use for the update operations. Previous version was using all the fields to filter which also included the _id field from the Events collection yet we are busy inserting in a completely new collection (Readings)! @BenjaminSsempala

Copy link
Contributor

Device registry changes in this PR available for preview here

@Baalmart Baalmart merged commit e08181a into staging Jan 19, 2024
46 of 48 checks passed
@Baalmart Baalmart deleted the hotfix-indempotency branch January 19, 2024 16:30
@Baalmart Baalmart mentioned this pull request Jan 19, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant