Why is the bot on Heroku Server not responding? - heroku

I programmed a simple bot that is connected to Google Sheets API. It asks a few questions to the user and stores it in the Sheet I have. When I use bot.polling it works fine, but I was trying the webhook so I could use Heroku to have my bot running 24/7.
I introduced the code:
#server.route('/' + token, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
#server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url = '<Heroku App Link>' + token)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port = int(os.environ.get('PORT', 5000)))
I have the requirements.txt file and the Procfile that currently is like this:
web: python3 bot.py
I tried a bunch of things in the Procfile but this is the only one that didn't gave an error.
When I saw the log this is what I got:
2019-09-24T10:18:54.369238+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-24T10:19:04.416777+00:00 heroku[web.1]: Starting process with command `python3 bot.py`
2019-09-24T10:19:09.868915+00:00 heroku[web.1]: State changed from starting to up
2019-09-24T10:19:09.790773+00:00 app[web.1]: * Serving Flask app "bot" (lazy loading)
2019-09-24T10:19:09.790800+00:00 app[web.1]: * Environment: production
2019-09-24T10:19:09.790853+00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2019-09-24T10:19:09.790940+00:00 app[web.1]: Use a production WSGI server instead.
2019-09-24T10:19:09.790991+00:00 app[web.1]: * Debug mode: off
2019-09-24T10:19:09.799470+00:00 app[web.1]: * Running on http://0.0.0.0:57826/ (Press CTRL+C to quit)
2019-09-24T10:19:15.000000+00:00 app[api]: Build succeeded
Can anyone help me understand why the bot doesn't answer any commands?

Related

My Spider crashes whenever I schedule to production on Heroku

My spider is working both on the local machine and on the Heroku platform, however, I wish to schedule the spider so it works according to the time given through cron expression.
This is my periodic_requests.py file:
from pytz import timezone
import requests, pytz
from apscheduler.schedulers.twisted import TwistedScheduler
from twisted.internet import reactor
def send_request():
requests.post(
url="https://datacrawlapp.herokuapp.com/schedule.json",
data={"project":"datahubsitecrawler",
"spider":"datahubcrawlapp",
"data_url": "https://drive.google.com/file/d/1zBfsWZdoFzoAq6ZELfw-tvvBFcVmCMI7/view?usp=sharing"
}
)
if __name__ == '__main__':
scheduler = TwistedScheduler(timezone=pytz.utc),
scheduler.add_job(send_request, 'cron', day_of_week='mon-sun', hour='19', minute='47')
scheduler.start()
try:
reactor.run() # the script will block here until the crawling is finished
except (KeyboardInterrupt, SystemExit):
pass
Procfile:
web: scrapyd
clock: python periodic_requests
I get error:
File "/app/.heroku/python/lib/python3.8/site-packages/scrapyd/website.py", line 212,
in prep_tab_finished
2022-02-07T08:58:06.697647+00:00 app[web.1]: return '\n'.join(
2022-02-07T08:58:06.697647+00:00 app[web.1]: builtins.TypeError: 'NoneType' object is not iterable:
and then it crashes as shown below:
2022-02-07T08:48:32.411005+00:00 heroku[web.1]: State changed from starting to up
2022-02-07T08:48:32.611649+00:00 heroku[clock.1]: Process exited with status 0
2022-02-07T08:48:32.721748+00:00 heroku[clock.1]: State changed from up to crashed
2022-02-07T08:48:32.742567+00:00 heroku[clock.1]: State changed from crashed to starting
2022-02-07T08:48:41.000000+00:00 app[api]: Build succeeded
2022-02-07T08:48:42.473990+00:00 heroku[clock.1]: Starting process with command `python periodic_requests.py`
2022-02-07T08:48:43.195961+00:00 heroku[clock.1]: State changed from starting to up
2022-02-07T08:48:44.920927+00:00 heroku[clock.1]: Process exited with status 0
2022-02-07T08:48:44.984024+00:00 heroku[clock.1]: State changed from up to crashed
Will appreciate your help!

NestJS (Nx workspace) build failing on Heroku

I'm trying to deploy a NestJS app (in Nx workspace) on Heroku, but the deploy is failing with error:
2021-12-24T11:03:17.280952+00:00 app[web.1]: at /app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:26:38
2021-12-24T11:03:17.280953+00:00 app[web.1]: at Array.forEach (<anonymous>)
2021-12-24T11:03:17.280953+00:00 app[web.1]: at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:25:86)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/schema.factory.js:9:75)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at Object.89 (/app/dist/apps/api/main.js:1:4717)
2021-12-24T11:03:17.280954+00:00 app[web.1]: at o (/app/dist/apps/api/main.js:1:12427)
2021-12-24T11:03:17.280955+00:00 app[web.1]: at Object.812 (/app/dist/apps/api/main.js:1:5865)
2021-12-24T11:03:17.280955+00:00 app[web.1]: at o (/app/dist/apps/api/main.js:1:12427)
2021-12-24T11:03:17.424198+00:00 heroku[web.1]: Process exited with status 1
2021-12-24T11:03:17.602083+00:00 heroku[web.1]: State changed from starting to crashed
I have seen some Mongoose issues and they don't seem to be the problem here, since the packages have since gotten multiple updates.
Edit:
After running the app from the Heroku console I got a more explicit error:
/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:43
optionsOrType = isClass ? optionsOrType : optionsOrType();
^
TypeError: Class constructors cannot be invoked without 'new'
at Function.inspectTypeDefinition (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:43:55)
at Function.inspectTypeDefinition (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:52:39)
at /app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:26:38
at Array.forEach (<anonymous>)
at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/definitions.factory.js:25:86)
at Function.createForClass (/app/node_modules/#nestjs/mongoose/dist/factories/schema.factory.js:9:75)
at Object.89 (/app/dist/apps/api/main.js:1:4301)
at o (/app/dist/apps/api/main.js:1:12011)
at Object.812 (/app/dist/apps/api/main.js:1:5449)
at o (/app/dist/apps/api/main.js:1:12011)
I had the same problem and it was caused by an upgrade of nrwl/nx to 13.3.1.
A downgrade of nrwl/nx to 13.2.4 fixed it.
So it seems that nx 13.3.0 introduced a dependency update which breaks the application.

Heroku: no module named flask though it is in requirements.txt

Can anyone help with this error on Heroku?
2015-01-12T22:26:00.575669+00:00 heroku[web.1]: Starting process with command `python hangman.py`
2015-01-12T22:26:01.066240+00:00 app[web.1]: Traceback (most recent call last):
2015-01-12T22:26:01.066256+00:00 app[web.1]: File "hangman.py", line 3, in <module>
2015-01-12T22:26:01.066262+00:00 app[web.1]: from flask import (
2015-01-12T22:26:01.066268+00:00 app[web.1]: ImportError: No module named flask
2015-01-12T22:26:01.742444+00:00 heroku[web.1]: Process exited with status 1
2015-01-12T22:26:01.751614+00:00 heroku[web.1]: State changed from starting to crashed
My git repo is here: https://github.com/PJBentham/Hangman
I believe I have done everything correct as far as set up is concerned but I'm still getting the above error and can't figure out why?
You have to show the last or pull traceback to debug further ...! You git repo working perfectly fine.
From your traceback snippet flask is not there. Check if your app environ having flask or not using heroku run pip freeze

Akka Scheduling in Heroku with Play 2 Framework

I can't get Akka schedule method to work properly in Heroku. It works fine locally and prints out "Heartbeat" to the log.
Here is the file in question: https://github.com/magnusart/actor-test/blob/master/app/Global.scala and snippet below.
override def onStart(app: Application) {
Logger.debug("Starting application")
Akka.system(app).scheduler.schedule(2 seconds, 10 seconds) {
Logger.debug("Heartbeat")
}
}
The full application is here (isolated for this purpose, also on actor-test.herokuapp.com).
https://github.com/magnusart/actor-test
What does happen after startup is that I see Starting application in the logs and then I don't see anything further after that:
2012-05-26T16:29:40+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=43943 -Xmx384m -Xss512k -XX:+UseCompressedOops`
2012-05-26T16:29:41+00:00 app[web.1]: Play server process ID is 3
2012-05-26T16:29:42+00:00 app[web.1]: [debug] application - Starting application
2012-05-26T16:29:42+00:00 app[web.1]: [info] play - Starting application default Akka system.
2012-05-26T16:29:42+00:00 app[web.1]: [info] play - Application started (Prod)
2012-05-26T16:29:42+00:00 app[web.1]: [info] play - Listening for HTTP on port 43943...
So the scheduled actor doesn't actually seem to start (which it of course does locally). I'm on Heroku Cedar. I grateful for any hints as to why this isn't working, what am I missing?
BR Magnus Andersson
Update
From what I've found, this seems to be a bug in Play 2 (I'm running version 2.0.1) and not be related to Heroku. I have updated a Play 2 Lighthouse ticket with relevant information. The ticket can be found here: https://play.lighthouseapp.com/projects/82401-play-20/tickets/448-play-dist-ignores-loggerxml#ticket-448-5
The problem seems to come from your logger setting, because in your Heartbeat you print a message with the "debug" level.
AFAIK, Heroku runs your Play app in "production" mode (= "play start"), ie the log level is set to "info" so the debug messages are never printed on Heroku.

Deploying Play 2.0 app on Heroku

So I am kind of new to setting up servers. And I have been struggling with various sql issues all night. I think the only thing that sits between me and a successfully running play app is this: error
Starting process with command `target/start -Dhttp.port=80 `
2012-04-04T05:58:52+00:00 app[web.1]: Play server process ID is 1
2012-04-04T05:58:53+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T05:58:56+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T05:58:56+00:00 app[web.1]: Oops, cannot start the server.
2012-04-04T05:58:56+00:00 app[web.1]: org.jboss.netty.channel.ChannelException: Failed to bind to: /0.0.0.0:80
... more errors
Does anyone spot any problems? Do I need any java options arguments?
I tried specifying a user port in the Procfile, and got a different error message:
2012-04-04T07:01:36+00:00 heroku[web.1]: Starting process with command `target/start -Dhttp.port=2000`
2012-04-04T07:01:37+00:00 app[web.1]: Play server process ID is 1
2012-04-04T07:01:40+00:00 app[web.1]: [info] play - database [default] connected at jdbc:mysql://us-cdbr-east.cleardb.com/heroku_cd914b667dae168
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Application started (Prod)
2012-04-04T07:01:45+00:00 app[web.1]: [info] play - Listening for HTTP on port 2000...
2012-04-04T07:01:46+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 2000, should be 47248 (see environment variable PORT)
2012-04-04T07:01:46+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-04-04T07:01:47+00:00 heroku[web.1]: Process exited with status 137
2012-04-04T07:01:47+00:00 heroku[web.1]: State changed from starting to crashed
I have no idea what is happening. How do I change this environment variable? This heroku process model is very confusing to me.
I think the problem is that you're not allowing Heroku to specify the port. Googling your error I find: https://devcenter.heroku.com/articles/error-codes#r11__bad_bind
So instead of doing this:
web: target/start -Dhttp.port=80
Do this
web: target/start -Dhttp.port=$PORT
James has a nice writeup on getting a more advanced Play 2.0 app deployed here.

Resources