apollo-backend/cmd/apollo-worker/main.go
Andre Medeiros 7fad5ac9e4 initial pass
2021-05-09 20:51:15 -04:00

49 lines
902 B
Go

package main
import (
"database/sql"
"log"
"os"
worker "github.com/contribsys/faktory_worker_go"
"github.com/joho/godotenv"
"github.com/andremedeiros/apollo/internal/data"
"github.com/andremedeiros/apollo/internal/reddit"
)
type application struct {
logger *log.Logger
db *sql.DB
models *data.Models
client *reddit.Client
}
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer db.Close()
rc := reddit.NewClient(os.Getenv("REDDIT_CLIENT_ID"), os.Getenv("REDDIT_CLIENT_SECRET"))
app := &application{
logger,
db,
data.NewModels(db),
rc,
}
mgr := worker.NewManager()
mgr.ProcessStrictPriorityQueues("critical", "default", "bulk")
mgr.Concurrency = 20
mgr.Run()
}