Lecture 10: Heroku, Workers, and Postgres Flashcards
(15 cards)
What are the basic files needed to create a Heroku App?
- Procfile
- requirements.txt
- runtime.txt
- webapp.py
What does the runtime file specify?
The language/runtime to use
What does the requirements file specify?
The modules/libraries to install in the environment –
What does the Procfile file specify?
The command(s) we want to run when our application is deployed
- Defines a process type (web/worker/clock)
- Tell gunicorn to look for the webapp.py file
What does the webapp file specify?
The web application code
- Consists of a single app() function definition
Which files help set up our application environment?
- requirements.txt
- runtime.txt
What does the app() function in the webapp file do?
Hooks into WSGI and allows Python to specify a
response when receiving a request
What do we specify in the webapp file?
- Data (streaming bytes)
- Status (HTTP status code)
- Response Headers
What commands do you run to create a new heroku deployment with Git
git init git add . git commit heroku create git push heroku master
Describe the storage between processes
- Individual processes are run in a semi-sandboxed manner
- They don’t have direct access to the same files
What is the database were using with Heroku?
PostgreSQL
How do you connect to PostgreSQL?
requirements. txt file:
- add ‘psycopg2’ line to
webapp. py file:
- In a try/except
- Define DATABASE_URL
- Create DB connection
- Create cursor
- Create table and execute query on cursor
- conn.commit()
- conn.close()
What is the command to scale workers to 1
heroku ps:scale worker=1
What does heroku ps:stop worker do?
- Puts the proccess into idle
- The process will keep on restarting
How do you kill a worker process?
Scale workers to 0
heroku ps:scale worker=0