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

🔁 Add task to resend messages #420

Merged
merged 6 commits into from
May 6, 2021
Merged

🔁 Add task to resend messages #420

merged 6 commits into from
May 6, 2021

Conversation

rowanseymour
Copy link
Contributor

Part of #177 which would let us remove last of the topup and message sending code in RP

@codecov
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #420 (a74599e) into main (b3bd3b4) will increase coverage by 0.20%.
The diff coverage is 59.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #420      +/-   ##
==========================================
+ Coverage   54.47%   54.67%   +0.20%     
==========================================
  Files         115      116       +1     
  Lines        8110     8164      +54     
==========================================
+ Hits         4418     4464      +46     
+ Misses       2990     2984       -6     
- Partials      702      716      +14     
Impacted Files Coverage Δ
core/tasks/msgs/resend_msgs.go 46.66% <46.66%> (ø)
core/models/msgs.go 27.82% <64.10%> (+4.75%) ⬆️
core/models/contacts.go 62.22% <0.00%> (+1.45%) ⬆️
core/models/channels.go 51.06% <0.00%> (+2.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3bd3b4...a74599e. Read the comment docs.

@@ -458,12 +514,8 @@ func UpdateMessage(ctx context.Context, tx Queryer, msgID flows.MsgID, status Ms
return nil
}

// MarkMessagesPending marks the passed in messages as pending
func MarkMessagesPending(ctx context.Context, db Queryer, msgs []*Msg) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure it's worth having a separate function for each status

@rowanseymour rowanseymour marked this pull request as ready for review April 26, 2021 19:37
@rowanseymour rowanseymour requested a review from nicpottier April 26, 2021 19:37
Copy link
Member

@nicpottier nicpottier left a comment

Choose a reason for hiding this comment

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

Why are we cloning the message? This feels like some remnant of the previous implementation that just adds complication. I'd rather we just re-queue it and make sure any kind of double sending cache or whatnot is cleared so that works. Cloning just seems odd especially given how often this occurs.

@rowanseymour
Copy link
Contributor Author

Good question I was just copying what we had in RapidPro.. maybe we did it this way to ensure it uses another topup? Will rework this to just requeue.

@nicpottier
Copy link
Member

Was thinking about this on the dog walk and I think it may have to do with the relayer, though that sounds like something perhaps worth revisiting.

@rowanseymour
Copy link
Contributor Author

@nicpottier in order for mailroom to clear the double-send protection, it would have to know the specifics of courier's date-based redis sets we use for that... maybe mailroom queues it to courier with a is_resend flag set and that skips double send checking in courier?

@nicpottier
Copy link
Member

Ya, that makes sense, can look at that today.

@rowanseymour
Copy link
Contributor Author

@nicpottier reworked to reset message state rather than clone messages

// mark message as being a resend so it will be queued to courier as such
msg.m.Status = MsgStatusPending
msg.m.QueuedOn = dates.Now()
msg.m.SentOn = dates.ZeroDateTime
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure about this.. I think it'll put a zero time in the json queued to courier.. but that doesn't matter?

Copy link
Member

Choose a reason for hiding this comment

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

Does omit_empty leave it out if it is a zero value? Feels risky / weird having a 0 value there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently not but aren't we always queuing sent_on="0001-01-01T00:00:00Z" to courier? I need to verify but I can't see how the regular queuing code would be any different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok now I've checked and we always queue to courier with sent_on="0001-01-01T00:00:00Z" and next_attempt="0001-01-01T00:00:00Z" because those are non-null in mailroom's model

// mark message as being a resend so it will be queued to courier as such
msg.m.Status = MsgStatusPending
msg.m.QueuedOn = dates.Now()
msg.m.SentOn = dates.ZeroDateTime
Copy link
Member

Choose a reason for hiding this comment

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

Does omit_empty leave it out if it is a zero value? Feels risky / weird having a 0 value there.

@rowanseymour rowanseymour merged commit ce8d627 into main May 6, 2021
@rowanseymour rowanseymour deleted the resend_msgs branch May 6, 2021 21:12
@nicpottier
Copy link
Member

Ya, if that's what we were doing then fine. Maybe this is an argument to add null.Time to our null package at some point, feels risky / slopping to be writing real dates.

@nicpottier
Copy link
Member

Just realized when looking at this further that both queued_on and sent_on are actually non-null in our DB too, which seems like the first thing to tweak / fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants