-
Notifications
You must be signed in to change notification settings - Fork 409
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 job to load messages in from a csv and fix some crucial bugs in twilio.js #1346
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,13 +56,16 @@ async function convertMessagePartsToMessage(messageParts) { | |
const lastMessage = await getLastMessage({ | ||
contactNumber | ||
}); | ||
if (!lastMessage) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Often SMS spam comes in. If we failed to find a lastMessage, then this failed rather than returning and completing normally -- leaving a db connection open -- and possibly a transaction. |
||
return; | ||
} | ||
return new Message({ | ||
contact_number: contactNumber, | ||
user_number: userNumber, | ||
is_from_contact: true, | ||
text, | ||
error_code: null, | ||
service_id: serviceMessages[0].MessagingServiceSid, | ||
service_id: firstPart.service_id, | ||
assignment_id: lastMessage.assignment_id, | ||
service: "twilio", | ||
send_status: "DELIVERED" | ||
|
@@ -345,7 +348,6 @@ async function handleIncomingMessage(message) { | |
user_number: userNumber, | ||
contact_number: contactNumber | ||
}); | ||
|
||
if (!process.env.JOBS_SAME_PROCESS) { | ||
// If multiple processes, just insert the message part and let another job handle it | ||
await r.knex("pending_message_part").insert(pendingMessagePart); | ||
|
@@ -355,6 +357,9 @@ async function handleIncomingMessage(message) { | |
pendingMessagePart | ||
]); | ||
if (finalMessage) { | ||
if (message.spokeCreatedAt) { | ||
finalMessage.created_at = message.spokeCreatedAt; | ||
} | ||
await saveNewIncomingMessage(finalMessage); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { loadMessages } from "./jobs"; | ||
import fs from "fs"; | ||
|
||
const csvFilename = process.argv.filter(f => /\.csv/.test(f))[0]; | ||
|
||
new Promise((resolve, reject) => { | ||
fs.readFile(csvFilename, "utf8", function(err, contents) { | ||
loadMessages(contents) | ||
.then(msgs => { | ||
resolve(msgs); | ||
process.exit(); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
reject(err); | ||
console.log("Error", err); | ||
process.exit(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A theory about the failure was that this was getting a count rather than a single message -- it therefore deadlocked on two of the same messages coming in, because it didn't need to find just one, but get a full count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, though it would be good to rename this variable, since it is no longer the count (unless I'm misunderstanding the change).