daily personalized reddit newsletters in your inbox
{root}
src
├── controllers # defines methods for interacting with our database
│ ├── newsletter.ts
│ └── subreddit.ts
├── db.ts # database connection handler
├── handlers.ts
├── index.ts # main entrypoint - runs as server, publish and update worker modes
├── reddit.ts # reddit restful utilities
├── routes.ts # defines the structure of our API
├── server.ts # Express.js server + middleware
├── types.ts
└── workers # defines lambda like functions for executing various tasks
├── publish.ts
└── update.ts
...
- npm i
sudo ifconfig lo0 alias 10.254.254.254
sudo apt-get install net-tools -y
sudo ifconfig lo:0 10.254.254.254.254
make dcu
make start
other dev tasks
npm run format
uses prettier
Create new migration
npx knex migrate:make <migration_name> -x ts
Running migrations
npx knex migrate:latest --env <env>
where env can be development, staging or productionnpx knex migrate:rollback
rollback latestnpx knex migrate:list
list pending migrations- For more commands available from knex checkout this page
Workers are lambda like functions that execute a given task and exit. They are designed to interact with our API service and can be deployed and scaled independently of user requests.
- update-worker: updates subreddit's top column with the latest top 3 posts
- publish-worker: publishes a newsletter (right now all it does is print to STDOUT but it will be useful soon :)
make dcu
# starts docker-compose with postgres DBmake start
# starts API servermake build workers
# builds worker code + imagedocker run -it --network host reddit-newsletter/update-worker
# runs worker once and exists
Running workers locally with kubernetes (I use minikube but you are welcomed to use something more lightweight)
- Please refer to this doc for usage
- Abstract more db interaction code intro controllers so we can reuse queries and business logic
- Write test
- CICD
- Build out the operator pattern to kick off more request to kubernetes job workers on demand from API server
- Add infra for API service
make build worker
# builds worker imagesmake build service
# builds service image aka API server