fix: user profile not rendering in top navbar

This commit is contained in:
Jordan Knott
2021-10-30 17:20:41 -05:00
parent 800dd2014c
commit cea99397db
17 changed files with 280 additions and 160 deletions

View File

@ -4,6 +4,7 @@ import (
"net/http"
"time"
"github.com/RichardKnop/machinery/v1"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/source/httpfs"
@ -30,9 +31,13 @@ func newWebCmd() *cobra.Command {
log.SetFormatter(Formatter)
log.SetLevel(log.InfoLevel)
connection := config.GetDatabaseConnectionUri()
appConfig, err := config.GetAppConfig()
if err != nil {
return err
}
connection := appConfig.Database.GetDatabaseConnectionUri()
var db *sqlx.DB
var err error
var retryDuration time.Duration
maxRetryNumber := 4
for i := 0; i < maxRetryNumber; i++ {
@ -61,11 +66,16 @@ func newWebCmd() *cobra.Command {
}
}
appConfig, err := config.GetAppConfig()
if err != nil {
return err
var server *machinery.Server
if appConfig.Job.Enabled {
jobConfig := appConfig.Job.GetJobConfig()
server, err = machinery.NewServer(&jobConfig)
if err != nil {
return err
}
}
r, _ := route.NewRouter(db, appConfig)
r, _ := route.NewRouter(db, server, appConfig)
log.WithFields(log.Fields{"url": viper.GetString("server.hostname")}).Info("starting server")
return http.ListenAndServe(viper.GetString("server.hostname"), r)
},

View File

@ -1,18 +1,16 @@
package commands
import (
"fmt"
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/RichardKnop/machinery/v1"
"github.com/RichardKnop/machinery/v1/config"
queueLog "github.com/RichardKnop/machinery/v1/log"
"github.com/jmoiron/sqlx"
"github.com/jordanknott/taskcafe/internal/config"
repo "github.com/jordanknott/taskcafe/internal/db"
"github.com/jordanknott/taskcafe/internal/notification"
"github.com/jordanknott/taskcafe/internal/jobs"
log "github.com/sirupsen/logrus"
)
@ -28,13 +26,11 @@ func newWorkerCmd() *cobra.Command {
log.SetFormatter(Formatter)
log.SetLevel(log.InfoLevel)
connection := fmt.Sprintf("user=%s password=%s host=%s dbname=%s sslmode=disable",
viper.GetString("database.user"),
viper.GetString("database.password"),
viper.GetString("database.host"),
viper.GetString("database.name"),
)
db, err := sqlx.Connect("postgres", connection)
appConfig, err := config.GetAppConfig()
if err != nil {
log.Panic(err)
}
db, err := sqlx.Connect("postgres", config.GetDatabaseConfig().GetDatabaseConnectionUri())
if err != nil {
log.Panic(err)
}
@ -43,25 +39,15 @@ func newWorkerCmd() *cobra.Command {
db.SetConnMaxLifetime(5 * time.Minute)
defer db.Close()
var cnf = &config.Config{
Broker: viper.GetString("queue.broker"),
DefaultQueue: "machinery_tasks",
ResultBackend: viper.GetString("queue.store"),
AMQP: &config.AMQPConfig{
Exchange: "machinery_exchange",
ExchangeType: "direct",
BindingKey: "machinery_task",
},
}
log.Info("starting task queue server instance")
server, err := machinery.NewServer(cnf)
jobConfig := appConfig.Job.GetJobConfig()
server, err := machinery.NewServer(&jobConfig)
if err != nil {
// do something with the error
}
queueLog.Set(&notification.MachineryLogger{})
queueLog.Set(&jobs.MachineryLogger{})
repo := *repo.NewRepository(db)
notification.RegisterTasks(server, repo)
jobs.RegisterTasks(server, repo)
worker := server.NewWorker("taskcafe_worker", 10)
log.Info("starting task queue worker")