Issue with my bot

Hello everyone,

I’m learning python. I built a bot which parses data from some website every 30 minutes and sends me a message. When I deploy it to Render.com it kinda works but manually sending message doesn’t work. I’m talking about send_new_tweet(channel) function which is not getting executed. When I test it locally it works es expected.
I’m launching the app with gunicorn main:app command.
I marked with # executes pieces of code which I see in the log.

@app.route(‘/’, methods=[‘POST’,‘GET’])
def index():
if request.method == ‘POST’:
r = request.get_json()
if ‘message’ in r:
chat_id = r[‘message’][‘chat’][‘id’]
msg = r[‘message’][‘text’]
print(‘private message’, msg)
if ‘/start’ in msg:
send_message(chat_id, ‘working!’, disable_notification=True) # executes
send_new_tweet(channel) # DOES NOT EXECUTE ?
# send_message(channel, ‘test message’)
elif ‘channel_post’ in r:
print(‘channel message received’)
return '20

delete_webhook() # executes
set_webhook(webhook_host) # executes

worker1 = Thread(target=check_for_new_tweet, daemon=True)
worker1.start() # executes
print(‘main thread execution…’) # executes

if name == ‘main’:
app.run()

EDIT: I should probably mention there are no errors… it seems like its running fine but it does not execute that function. Also tested it on railway.app and it works as expected.

Thanks!

Hey,

I see that the service mentioned originally has now been deleted. Do you still require any help?

Jérémy, Render Support

Yes please!
I’ll try to re-deploy it today.
Thanks!

EDIT:
Actually I’m going to make some changes and will see how it runs and post an update here.

Please update this topic when you need any help.

Jérémy, Render Support

Here I am again lol…

Trying to deploy and it fails for some reason. This is what I see in the log…

Jan 16 04:47:35 PM You should consider upgrading via the ‘pip install --upgrade pip’ command.
Jan 16 04:47:35 PM ==> Generating container image from build. This may take a few minutes…
Jan 16 04:49:09 PM ==> Uploading build…
Jan 16 04:49:30 PM ==> Build uploaded in 16s
Jan 16 04:49:30 PM ==> Build successful :tada:
Jan 16 04:49:30 PM ==> Deploying…

what’s weird is that it shows that the build failed but my bot is actually working…
It supposed to print some stuff in the log but I dont see it, maybe it just has some delay…

Also web service link which I used for webhook is shows 502 error bad gateway.

surpisingly it still works… even tho the status of it is “deploy failed”

Right now is it says “Exited with status 1 because of an internal system error. Our team has been notified.” and the status is failed but it still works…

ok I’m an idiot I was starting my app with gunicorn app:app while I should’ve done that with gunicorn main:app… and now it’s working

So my bot is working now, but for some reason sometimes its not responding. It supposed to print something in the log every 2 minutes but it went quiet for 20 minutes and then restarted.
Why does that happen? Any help is appreciated!

I see its probably because of this huh?

Web Services on the free instance type are automatically spun down after 15 minutes of inactivity. When a new request for a free service comes in, Render spins it up again so it can process the request.

Yep, free instance types will shut down after 15 minutes of inactivity,

Regards,

John B

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.