I have this cron job set up on heroku to delete some files in a particular folder and create them again with new data. My code is on Github and connected to heroku. How can I achieve updating my github branch after this cron has been run on heroku?
Asked
Active
Viewed 328 times
0
-
What are you trying to accomplish? It's very likely that this is an [XY problem](https://meta.stackexchange.com/q/66377/248627). – ChrisGPT was on strike Jun 08 '19 at 19:53
1 Answers
0
You really don't want to be doing this. If you have files that are changing they should be stored on S3 or in a database or some other external storage.
Heroku dynos have ephemeral file systems and heroku reboots your dynos at least once every 24 hours. Any changes to the local file system are lost in the reboot.
That means if you change a file, and heroku reboots before you push that file to github you lose the changes.
That also means you'll need to re-deploy whenever you push to the github repo. So if you are pushing frequently you'll be constantly re-deploying.
In theory here's one way.
- Install the heroku-apt-buildpack.
- Configure it to install git.
- Generate an SSH key pair. Put the private key in a config var on your heroku app. Install the public key on github so your dyno can push to github.
- Configure your cron job to pull from git, make local files system changes, and push to git after making any local file system changes, using the private ssh key from the config var.
- If you want "last push wins" semantics force push. Otherwise you'll need handle the case where the push fails "pull, possibly resolve conflicts, push"
- Configure heroku to auto-deploy from github on every push to the master branch.
But really - don't do this. Put your files on some external storage service.

Scott Jacobsen
- 975
- 5
- 16