Hey guys!
Please feel free to dig into my account and look at the server and error logs.
I have a function that sends a text blast. Regulatory whatnots have led to me using a pool of numbers so my messages get through. From that, I had to tweak my code to include the source of the incoming text, so that every user consistently communicates with the same number.
Problem is, at the bottom of this function my server log starts predictably going crazy. Everyone ends up getting 4 messages over the course of 10 minutes or so, and I get 4 "send_intro complete" over that time.
The only error in the error log is OS: write error. The server log itself is doing its haywire thing, with a "Broken Pipe" reference I don't understand. It looks like something in here is getting stuck and causing it to just run repeatedly until it gives up.
Help!
def execute_intro():
introMessage = '''Hi {name}! This is... and I'd love to have an agent reach out to schedule your trip! Reply "yes"
to set up a call, "no" to wait, or "stop" if you don't remember purchase.'''
print ("EXECUTE message received")
allUsers = Chat_Users.query.all()
#try:
goodCount = 0
badCount = 0
for item in allUsers:
#try:
send_intro(item.user_number, item.user_name)
item.current_status = "intro"
item.call_accepted = False
item.call_time = ""
item.email_accepted = False
item.new_email = ""
item.feedback = ""
item.previous_error = False
db.session.commit()
print ("intro sent and properties updated for user ", item.user_number)
timeSent = datetime.now().strftime("%x at %X")
sentLogEntry = Chat_Log(
timestamp = timeSent,
direction = "outgoing",
user_number = item.user_number,
user_name = item.user_name,
message = introMessage,
current_status = "intro",
call_accepted = None,
call_time = "",
email_accepted = None,
new_email = "",
feedback = "",
previous_error = False
)
db.session.add(sentLogEntry)
db.session.commit()
goodCount += 1
print ("sentLogEntry updated for user ", item.user_number)
time.sleep(5)
print ("wait 5 seconds")
#except:
# print ("intro/sentLogEntry failed for user ", item.user_number)
# badCount += 1
# time.sleep(5)
# print ("wait 5 seconds")
send_sms("FROM FLASK--send_intro executed. {goodCount} records successfully initiated and {badCount} records failed.".format(goodCount=goodCount,badCount=badCount), "1------", "1------")
#except:
#print ("sending intro failed")
#send_sms("FROM FLASK--send_intro failed.", "1------", "1------")
outputDict = {
"good count": goodCount,
"bad count": badCount
}
return outputDict
Below is the server log stuff that's telling me it's going crazy. HELP!!
2019-11-30 02:16:51 intro sent and properties updated for user 1------
2019-11-30 02:16:51 sentLogEntry updated for user 1------
2019-11-30 02:16:56 wait 5 seconds
2019-11-30 02:16:56 send_sms reached -- FROM FLASK--send_intro executed. 4 records successfully initiated
and 0 records failed. -- 1------
2019-11-30 02:16:57 Sat Nov 30 02:16:57 2019 - uwsgi_response_writev_headers_and_body_do(): Broken pipe
[core/writer.c line 306] during POST /foo (10.0.0.249)