I have 2 discord bot programs, one is python code and the other is nodejs. I was wondering if in the procfile, like when you say worker: python ___, is there a way so that it runs both my python file and codejs file at the same time? Right now I can only get either or to run.
My procfile right now is just:
worker: python log.py
worker: node bot.js
Thank you for helping.
Instead of your Procfile being:
worker: python log.py
worker: node bot.js
You do:
worker: python log.py & node bot.js & wait -n
see: https://help.heroku.com/CTFS2TJK/how-do-i-run-multiple-processes-on-a-dyno
Related
In the Procfile, worker: node bot.js works fine, but if I move the file in a folder, then how would I format it? I would think something like worker: node folder/bot.js but I don't know. Thanks to anyone who responds.
You can do
worker: node folder/bot.js
or
worker: cd folder && node bot.js
In some cases it does make a difference how you are calling it but it depends on your program.
I am trying to host a discord bot on Heroku (Discord JDA, Maven). I do this by connecting to Github and then deploying. The bot 'deploys' (view attachment) but doesn't actually work (view attachment).
What could I be doing wrong, or has anyone else come across a similar issue?
Quick and dirty way to deploy it:
You'll need to setup a Procfile, extensive info on that right here: https://devcenter.heroku.com/articles/procfile
The procfile is basically a file with no extension that tells the dyno how to execute your program.
A simple
worker: java $JAVA_OPTS -jar <PATH_TO_JAR>
will work fine if you don't need more config, refer to that link for more.
You can then deploy it like this (Good to have procfile and jar on the same directory):
$ heroku deploy:jar -a <YOUR_HEROKU_APP_NAME> --jdk <JDK_VERSION> --jar <PATH_TO_JAR> -i Procfile
Then to start it just do (Assuming you want a worker dyno, which is what discord should need)
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=1
Then stop it with:
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=0
I've found this is much simpler than using git, especially if you're doing tests or simple/quick stuff.
Possible solutions:
Set up a Procfile. A Procfile basically tells Heroku what command to run when your app is deployed. Inside the Procfile, write worker: node index.js. Also, make sure Procfile has a capital "P".
Set up package.json.
npm init
Then just skip through the set up and your file should be automatically created. IMPORTANT. In your package.json file, add your node and npm versions.
node -v
npm -v
Then go an type this in your package.json.
"engines": {
node: "your-version-here"
npm: "your-version-here"
}
Then try deploying your app to Heroku again. Also, make sure you have the "nodejs" buildpack set up for your app. Run it and test the discord bot.
So I'm doing a university group project and we are demonstrating tomorrow. It's a flask API and I'm hosting with Heroku. At first I got this error
code=H14 desc="No web processes running"
After looking around I found a solution to scale dynos with :
heroku ps:scale web=1
Which in turn failed, resulting in this error
Couldn't find that process type (web)
I have no idea what is going wrong. My Procfile is named correctly and updated (no .txt at the end). Any help would be greatly appreciated.
My Procfile:
web:gunicorn api_prediction:medi-ai
Where "api-prediction" is the python file to run and "medi-ai is the project name"
Example for the Procfile
#filename: Procfile
web: gunicorn runserver:app --log-file=-
Example for the gunicorn
# filename: run.gunicorn.sh
gunicorn -b :5000 --access-logfile - --error-logfile - runserver:app
Also install gunicorn and dont miss the requirements.txt file too.
pip install gunicorn
pip freeze > requirements.txt
If this doesn't resolved your issue please reply.
I've seen people say in a couple of different places that clockwork should be run on its own dyno, with a procfile that might look something like this (example from heroku):
clock: bundle exec clockwork lib/clock.rb
Is there any reason not to run it on the same dyno as the workers? With a process that looks something like this:
worker: bundle exec clockwork clock.rb & bundle exec sidekiq -C config/sidekiq.yml -L log/sidekiq.log
It seems to work fine this way, but I'd like to know the underlying reason why people say not to do it this way. Any guidance would be appreciated. Thanks in advance.
I've recently starting running sidekiq and clockwork side by side,
like this:
web: bundle exec puma -C config/puma.rb
worker: bundle exec clockwork clock.rb & bundle exec sidekiq & wait -n
# ^ https://help.heroku.com/CTFS2TJK/how-do-i-run-multiple-processes-on-a-dyno
And so far not seeing any issues....
This is a $25/month saving for us on the heroku hosting.
what would happen if sidekicks dies? (#Anthony said)
Normally sidekiq doesn't die (for me at least), I think it's because
sidekiq is only managing jobs. The actual work happens in classes with
a perform() method, and when those methods "raise / fail", it doesn't
bring down the sidekiq parent with it. Sidekiq has a GUI that shows the retry queue
and a dead queue, so dead jobs would end up in one of those places.
btw Heroku has an article on running multiple jobs in a single "dyno":
https://help.heroku.com/CTFS2TJK/how-do-i-run-multiple-processes-on-a-dyno
OP said:
I've seen people say in a couple of different places
I'd be curious to read those comments though, if you have the links.
I have some miniapp that use delayed_job. On my localhost everything works fine, but when I deploy my app to Heroku and click on the link that should be executed by delayed_job, so nothing happen, the "task" is just saved into the table delayed_job.
In this article on heroku blog is written, that the task from delayed_job table is executed, when is run this command rake jobs:work.
But how can I run this command? Where should be the command placed? In the code, or from terminal console?
If you are running the Cedar stack, run the following from the terminal console:
heroku run rake jobs:work
If you are running the older stacks (Bamboo, Aspen, etc.):
heroku rake jobs:work
see: https://devcenter.heroku.com/articles/rake
According to the delayed_job documentation, you can also start a worker programmatically:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
Delayed::Worker.new.start
You should use a Procfile to scpecify the commands for your dynos.
For example you would have something like this in your Procfile:
appDir/Procfile
web: bundle exec rails server -p $PORT
worker: bundle exec rake jobs:work
To use this on your development machine, you should use Foreman, it's all explained at the docs.
https://devcenter.heroku.com/articles/procfile
In our case we're only running a delayed job once a month, so didn't want to have a worker dyno running constantly.
To solve this we queue up the job (with .delayed) and then use the Heroku platform API to spawn rake jobs:workoff in a one-off worker. The API call returns relatively quickly.
PlatformAPI.connect_oauth(ENV["YOUR_HEROKU_KEY"]).dyno.create(ENV["YOUR_HEROKU_APP_NAME"],{command: 'rake jobs:workoff'})