heroku: flush redis in release phase - heroku

I have a node app running on heroku and I'm trying to use the release phase to flush my redis cache on deploy.
I've added the release: ./release-tasks.sh to my Procfile but I'm having a hard time finding information what tools are available for me to use in the release phase.
Currently my release-tasks.sh file looks like this:
redis-cli -u $REDIS_URL flushall
But it errors out with a redis-cli not found and it cannot find the heroku command either.
It says in the release-phase docs that it is a good place to invalidate a cache, does anyone have any thoughts on how to do this?

redis-cli nor the Heroku CLI is available on a dyno so you can't use them here. Depending on the language your app is built in your could write a task in that language that flushes the cache and then invoke that task from your shell script.

Related

How to stop deployment to Heroku in progress

Is it possible to stop a deploy to Heroku (git push heroku) that is currently being built?
Something like heroku run stopit!
Btw. rolling back after successful deploy is not what I'm looking for.
First, install the Heroku builds plugin:
heroku plugins:install heroku-builds
Then, to cancel a build, fetch the list of the recent builds:
heroku builds -a YOUR_APP_NAME
The first line of the output will be your currently running build, the first column is the build ID.
Cancel it with:
heroku builds:cancel BUILD_ID -a YOUR_APP_NAME
Et voilà, this will force fail the build.
Note: you could also get the build id from the build log URL.
I might have found an answer to this problem, it seems to have been answered by Heroku in May. I'm assuming that by release phase they mean deploy:
https://help.heroku.com/Z44Q4WW4/how-do-i-stop-a-release-phase
Release Phase processes are the same as any other Dyno in your formation, expect they run the codebase from the new release, instead of your current release.
To monitor your Release Phase processes as they execute, you can use the CLI command heroku ps -a YOUR_APP_NAME. as these are normal processes, you can use the ps:kill and ps:scale commands to stop the Release Phase from completing, which in turn, will prevent the latest release from completing.
I haven't tested this yet, but i will update with my exact commands when i have tested it out. If any one tests this out and can confirm, please feel free to update this answer.
I used the command
heroku builds:cancel -a <your_app_name>
and this worked for me

What is a good way to run a task whenever a Heroku app restarts?

Use case is to bust the cache.
What is a good way to run given code (or rake task) whenever a Ruby Heroku app is restarted (or deployed)?
There's no way to do this via the Heroku API far as I know. The Heroku Platform API doesn't support this.
What you can do (if you're fast, however!) is listen for a SIGTERM message in your code (that's what Heroku sends to your application process when it attempts to restart it) -- you can then fire off your script quickly.
Here's more information on SIGTERM on Heroku: https://devcenter.heroku.com/articles/dynos#graceful-shutdown-with-sigterm
If you're using some sort of CI, you can probably configure it there. Heres how to do it with CircleCI:
deployment:
production:
branch: production
commands:
- git push git#heroku.com:foo-bar-123.git $CIRCLE_SHA1:master
- heroku run rake <your task> --app <your app name>
If you're not using a CI you can still whip together a script that first does the git push to Heroku and then executes your cache busting task through heroku run (the app's bin/ folder would be an obvious place to put it).
Note: you can also use heroku run:detached, which will send output to your logs instead of stdout.
You can use "release" feature that allows you to run any command before a new release is deployed. https://devcenter.heroku.com/articles/release-phase
Define the command that should be run in your Procfile.
release: rake db:migrate
From documentation:
The release command is run immediately after a release is created, but before the release is deployed to the app’s dyno formation. That means it will be run after an event that creates a new release.

Have Heroku App Restart it self from Heroku

So, if I run the command heroku ps:restart event_machine.1 --app app-name I get what I want. However, I'm trying to automate our travis-ci deploy process. What needs to happen is the following:
We have a successful test run.
Next, we deploy the code
If we deploy the code successfully, we need to execute a few rake tasks that tell an external service to rebuild it self.
Once this is fired off, we need to restart the heroku app. In travis, ideally, this would be executed on the heroku machine via a deploy run command. This would be done in much the same way that we run bundle exec db:migrate.
Does anyone have any thoughts on how we we can restart a particular dyno(s) via a command that can be ran via heroku run something as that is what travis is executing in the deploy run.
So, to answer this we had a procfile that is executing a rake command to spin up event machine. We've modified this at the proc file level to first tell the external service to rebuild it self, before starting the event machine. This takes travis completely out of the deployment loop, which is better because it allows Heroku and Travis to each do what they should be responsible for.

Edit files on Heroku

I'm stuck at this simple task.
I have some configuration files that should be ignored by Git. But after commit to Heroku, I always get Application Error.
If I ignore those files then I have no way to get around the situation, but adding them to Git is definitely not a good idea.
Is there any way to ssh into Heroku server, I found no instructions on Heroku?
You can run a bash shell for your heroku app by doing this. Note that it will spin up another dyno, which will shut down when you exit the shell:
heroku run bash

How to use Heroku-Scheduler

I've recently installed https://addons.heroku.com/scheduler in my heroku app, but I just cannot make any instruction get to work.
I think I don't know the correct syntax, for now I've tried with heroku pgbackups:capture --expire --app running-app command and selected frequency 10 mins.
It's been more than an hour and still hasn't done anything.
How can I get this to work?
Thanks
EDIT: This command is an example command, nor that I want to use that one specifically
You should be using the pgbackups addon, https://addons.heroku.com/pgbackups which is scheduled for you based on the level you pick.
Heroku Scheduler is more for if you need to run a rack task within your application codebase.
UPDATE BASED ON REVISED QUESTION:
You would write a rake task (assuming your using Rails?) which you could run locally using rake taskname and to schedule it on Heroku you would enter rake taskname as the command in the scheduler page for them to execute it.

Resources