am trying to build a telegram bot on heroku. The bot works fine on my local testing, when I published it to heroku for some reason the dyno is not working. I checked if there any problem in my program bot nothing.
even tried to launch it manually to see if there is any missing package or errors:
heroku run bash -a app1
python bot.py
and the application started normally without any problem.
also tried to restart dynos but nothing happened the dyno is still OFF.
Procfile
worker: python bot.py
PS:
am using the free plan
tried to see the logs but it didn't show any error
2021-10-20T14:59:56.732258+00:00 app[api]: Deploy 348270fc by user *#gmail.com
2021-10-20T14:59:56.732258+00:00 app[api]: Release v9 created by user *#gmail.com
2021-10-20T15:00:08.000000+00:00 app[api]: Build succeeded**
I found the answer after reading heroku documentation on Dynos, because this is a worker dyno not a web dyno you need to rescale it to 1.
PS> heroku scale worker=1
Scaling dynos... done, now running worker at 1:Free
Everything should work fine from there.
Reference:
Dynos and the Dyno Manager
Dyno Types
Related
I have a simply python script that I deploy on Heroku as worker:
Procfile:
worker: python main.py
The script is scheduled to run every day at a specific time with the Heroku Scheduler. I don't want it to run to other times.
Every time I push new changes to heroku (git push heroku master) the script is run automatically which I want to avoid.
How can I do that?
I looked into using another scheduler, that is set up from within the script like the APScheduler. Would this be a solution? Do I need to change my script?
Thanks!
You can scale the worker dyno formation down to zero:
If you want to stop running a particular process type entirely, simply scale it to 0
So:
heroku ps:scale worker=0
Jobs scheduled via Heroku Scheduler should still run as configured.
I coded my bot using nextcord and tried running it 24/7 using Heroku. However, there are no error codes when I deploy my bot, it stays offline. I've used heroku before for my discord-py bots, they all work. This is the first time I am adding slash commands (that work when I run it on my pc) to my bots. I have all the files I need such as requirements.txt, Procfile, runtime.txt and index.py, stored in the same git repo. How do I fix this?
requirement.txt:
nextcord==2.0.0
runtime.txt:
python-3.10.6
procfile:
worker: python3 index.py
I have the worker dyno enabled
I have created an selenium bot that posts every 20 minutes on Instagram
I deployed my project to heroku and everything but i don't know how to make it run forever
I tried heroku run python mycode.py in the command promt but the program would stop working if i close command prompt
heroku run is for ad hoc interactive stuff.
For a long-running background process you should define a worker process in your Procfile:
worker: python mycode.py
Commit that change and redeploy. Then scale up a dyno to run it:
heroku ps:scale worker=1
This will either consume free dyno hours or, if you are using paid dynos, incur costs.
I've deployed a python script on heroku and I can run that in local terminal by
heroku run python script.py
command, But when I close the local terminal the script has been stopped.
Is there a way to run deployed script through the heroku server and independent of local machine ?
You can check:
https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-run-detached
heroku run:detached -t python script.py should do the trick for you
Reddy Abel Tintaya Conde's answer using heroku run:detached is good for ad hoc stuff.
But if your script should run continuously, automatically restarting when it fails, you should define a process for it in your Procfile. Such processes are often called worker processes:
worker: python script.py
Then you can scale your worker process up (or down) with heroku ps:scale:
heroku ps:scale worker=1
Whether you run your script this way or via heroku run:detached, remember that this consumes free dyno hours or, if you are using paid dynos, incurs costs.
I've got a Heroku app which automatically deploys when I'm pushing changes to GitHub. It's a Discord Bot (written in python).
Now I want to automatically start this python script when I'm going to deploy (It should run 24/7 until it's stopped by a new deploy).
I read about Dynos but don't know how to use them. I already added the Procfile with bot: python bot.py but this won't auto start the app. The Dyno is only shown in the resources tab on the dashboard. Using heroku ps -a myapp it responds with No dynos on ⬢ myapp. The bot: python bot.py Dyno in the dashboard also can't be started through that switch.
Screenshot: The switch can't be activated
So I tried to use release: python bot.py which starts the bot but after another deploy the processes are stacking up and the bot is running multiple times.
Don't use a release command for this.
release commands run once as part of the deploy, then they're done. Your application should probably be set up as a web process (if it's supposed to respond to HTTP requests):
web: python myapp.py
or a worker process (if it isn't):
worker: python myapp.py