remove cmd directory
This commit is contained in:
parent
b13037b882
commit
f82841fc34
28
Makefile
28
Makefile
|
@ -1,31 +1,15 @@
|
|||
.PHONY: tui, md-exprt, worker
|
||||
|
||||
# Define source and destination directories
|
||||
MD_SRC_DIR := public
|
||||
MD_DST_DIR := ../ewintr.nl/content/movies
|
||||
|
||||
run-api:
|
||||
go run ./cmd/api-service/service.go -apikey localOnly
|
||||
|
||||
run-tui-local:
|
||||
EMDB_BASE_URL=http://localhost:8085/ EMDB_API_KEY=hoi go run ./cmd/terminal-client/main.go
|
||||
|
||||
run-tui:
|
||||
tui:
|
||||
go run ./terminal-client/main.go
|
||||
|
||||
run-md-export:
|
||||
go run ./cmd/markdown-export/main.go
|
||||
for dir in $(MD_SRC_DIR)/*; do \
|
||||
if [ -n "$$(ls -A $$dir)" ]; then \
|
||||
cp -r $$dir/* $(MD_DST_DIR)/`basename $$dir`; \
|
||||
fi \
|
||||
done
|
||||
md-export:
|
||||
go run ./markdown-export/main.go
|
||||
|
||||
run-worker:
|
||||
go run ./cmd/worker/main.go
|
||||
worker:
|
||||
go run ./worker/main.go
|
||||
|
||||
|
||||
build-api:
|
||||
go build -o emdb-api ./cmd/api-service/service.go
|
||||
|
||||
deploy-api:
|
||||
ssh ewintr.nl /home/erik/bin/deploy-emdb-api.sh
|
|
@ -1,57 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"code.ewintr.nl/emdb/cmd/api-service/moviestore"
|
||||
"code.ewintr.nl/emdb/storage"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dbSQLite, err := moviestore.NewSQLite("./emdb.db")
|
||||
if err != nil {
|
||||
fmt.Printf("could not create new sqlite repo: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
pgConnStr := ""
|
||||
dbPostgres, err := storage.NewPostgres(pgConnStr)
|
||||
if err != nil {
|
||||
fmt.Printf("could not create new postgres repo: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//fmt.Println("movies")
|
||||
//movieRepoSqlite := moviestore.NewMovieRepository(dbSQLite)
|
||||
//movieRepoPG := moviestore.NewMovieRepositoryPG(dbPostgres)
|
||||
//
|
||||
//movies, err := movieRepoSqlite.FindAll()
|
||||
//if err != nil {
|
||||
// fmt.Println(err)
|
||||
// os.Exit(1)
|
||||
//}
|
||||
//for _, movie := range movies {
|
||||
// if err := movieRepoPG.Store(movie); err != nil {
|
||||
// fmt.Println(err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
//}
|
||||
fmt.Println("reviews")
|
||||
reviewRepoSqlite := storage.NewReviewRepository(dbSQLite)
|
||||
reviewRepoPG := storage.NewReviewRepository(dbPostgres)
|
||||
|
||||
reviews, err := reviewRepoSqlite.FindAll()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, review := range reviews {
|
||||
if err := reviewRepoPG.Store(review); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("success")
|
||||
}
|
15
job/queue.go
15
job/queue.go
|
@ -3,9 +3,7 @@ package job
|
|||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.ewintr.nl/emdb/storage"
|
||||
|
@ -57,22 +55,15 @@ VALUES ($1, $2, 'todo');`, movieID, action)
|
|||
return err
|
||||
}
|
||||
|
||||
func (jq *JobQueue) Next(t JobType) (Job, error) {
|
||||
func (jq *JobQueue) Next() (Job, error) {
|
||||
logger := jq.logger.With("method", "next")
|
||||
|
||||
actions := SimpleActions
|
||||
if t == TypeAI {
|
||||
actions = AIActions
|
||||
}
|
||||
actionsStr := fmt.Sprintf("('%s')", strings.Join(actions, "', '"))
|
||||
query := fmt.Sprintf(`
|
||||
row := jq.db.QueryRow(`
|
||||
SELECT id, action_id, action
|
||||
FROM job_queue
|
||||
WHERE status='todo'
|
||||
AND action = ANY($1)
|
||||
ORDER BY id ASC
|
||||
LIMIT 1;`, actionsStr)
|
||||
row := jq.db.QueryRow(query)
|
||||
LIMIT 1;`)
|
||||
var job Job
|
||||
err := row.Scan(&job.ID, &job.ActionID, &job.Action)
|
||||
if err != nil {
|
||||
|
|
|
@ -33,7 +33,7 @@ func (w *Worker) Run() {
|
|||
logger.Info("starting worker")
|
||||
for {
|
||||
time.Sleep(interval)
|
||||
j, err := w.jq.Next(TypeSimple)
|
||||
j, err := w.jq.Next()
|
||||
switch {
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
logger.Info("no simple jobs found")
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
"text/template"
|
||||
|
||||
"code.ewintr.nl/emdb/client"
|
||||
"code.ewintr.nl/emdb/storage"
|
||||
"code.ewintr.nl/go-kit/slugify"
|
||||
)
|
||||
|
||||
|
@ -26,8 +26,18 @@ extra.movie.rating = {{ .Rating }}
|
|||
)
|
||||
|
||||
func main() {
|
||||
emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
||||
movies, err := emdb.GetMovies()
|
||||
dbHost := os.Getenv("EMDB_DB_HOST")
|
||||
dbName := os.Getenv("EMDB_DB_NAME")
|
||||
dbUser := os.Getenv("EMDB_DB_USER")
|
||||
dbPassword := os.Getenv("EMDB_DB_PASSWORD")
|
||||
pgConnStr := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", dbHost, dbUser, dbPassword, dbName)
|
||||
dbPostgres, err := storage.NewPostgres(pgConnStr)
|
||||
if err != nil {
|
||||
fmt.Printf("could not create new postgres repo: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
movieRepo := storage.NewMovieRepository(dbPostgres)
|
||||
movies, err := movieRepo.FindAll()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
|
@ -19,7 +19,6 @@ func main() {
|
|||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
//emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
||||
dbHost := os.Getenv("EMDB_DB_HOST")
|
||||
dbName := os.Getenv("EMDB_DB_NAME")
|
||||
dbUser := os.Getenv("EMDB_DB_USER")
|
||||
|
|
|
@ -4,11 +4,13 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"code.ewintr.nl/emdb/client"
|
||||
"code.ewintr.nl/emdb/job"
|
||||
"code.ewintr.nl/emdb/storage"
|
||||
"github.com/tmc/langchaingo/chains"
|
||||
"github.com/tmc/langchaingo/llms/ollama"
|
||||
"github.com/tmc/langchaingo/prompts"
|
||||
|
@ -29,29 +31,42 @@ Just answer with the JSON and nothing else. If you don't see any other movie tit
|
|||
)
|
||||
|
||||
func main() {
|
||||
emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
|
||||
dbHost := os.Getenv("EMDB_DB_HOST")
|
||||
dbName := os.Getenv("EMDB_DB_NAME")
|
||||
dbUser := os.Getenv("EMDB_DB_USER")
|
||||
dbPassword := os.Getenv("EMDB_DB_PASSWORD")
|
||||
pgConnStr := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", dbHost, dbUser, dbPassword, dbName)
|
||||
dbPostgres, err := storage.NewPostgres(pgConnStr)
|
||||
if err != nil {
|
||||
fmt.Printf("could not create new postgres repo: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
movieRepo := storage.NewMovieRepository(dbPostgres)
|
||||
reviewRepo := storage.NewReviewRepository(dbPostgres)
|
||||
jobQueue := job.NewJobQueue(dbPostgres, logger)
|
||||
|
||||
go Work(emdb)
|
||||
go Work(movieRepo, reviewRepo, jobQueue)
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-c
|
||||
}
|
||||
|
||||
func Work(emdb *client.EMDB) {
|
||||
func Work(movieRepo *storage.MovieRepository, reviewRepo *storage.ReviewRepository, jobQueue *job.JobQueue) {
|
||||
for {
|
||||
j, err := emdb.GetNextAIJob()
|
||||
j, err := jobQueue.Next()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
review, err := emdb.GetReview(j.ActionID)
|
||||
review, err := reviewRepo.FindOne(j.ActionID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
movie, err := emdb.GetMovie(review.MovieID)
|
||||
movie, err := movieRepo.FindOne(review.MovieID)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
@ -105,7 +120,7 @@ func Work(emdb *client.EMDB) {
|
|||
|
||||
review.Titles = resp
|
||||
|
||||
if err := emdb.UpdateReview(review); err != nil {
|
||||
if err := reviewRepo.Store(review); err != nil {
|
||||
fmt.Printf("could not update review: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
Loading…
Reference in New Issue