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
|
# Define source and destination directories
|
||||||
MD_SRC_DIR := public
|
MD_SRC_DIR := public
|
||||||
MD_DST_DIR := ../ewintr.nl/content/movies
|
MD_DST_DIR := ../ewintr.nl/content/movies
|
||||||
|
|
||||||
run-api:
|
tui:
|
||||||
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:
|
|
||||||
go run ./terminal-client/main.go
|
go run ./terminal-client/main.go
|
||||||
|
|
||||||
run-md-export:
|
md-export:
|
||||||
go run ./cmd/markdown-export/main.go
|
go run ./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
|
|
||||||
|
|
||||||
run-worker:
|
worker:
|
||||||
go run ./cmd/worker/main.go
|
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 (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.ewintr.nl/emdb/storage"
|
"code.ewintr.nl/emdb/storage"
|
||||||
|
@ -57,22 +55,15 @@ VALUES ($1, $2, 'todo');`, movieID, action)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jq *JobQueue) Next(t JobType) (Job, error) {
|
func (jq *JobQueue) Next() (Job, error) {
|
||||||
logger := jq.logger.With("method", "next")
|
logger := jq.logger.With("method", "next")
|
||||||
|
|
||||||
actions := SimpleActions
|
row := jq.db.QueryRow(`
|
||||||
if t == TypeAI {
|
|
||||||
actions = AIActions
|
|
||||||
}
|
|
||||||
actionsStr := fmt.Sprintf("('%s')", strings.Join(actions, "', '"))
|
|
||||||
query := fmt.Sprintf(`
|
|
||||||
SELECT id, action_id, action
|
SELECT id, action_id, action
|
||||||
FROM job_queue
|
FROM job_queue
|
||||||
WHERE status='todo'
|
WHERE status='todo'
|
||||||
AND action = ANY($1)
|
|
||||||
ORDER BY id ASC
|
ORDER BY id ASC
|
||||||
LIMIT 1;`, actionsStr)
|
LIMIT 1;`)
|
||||||
row := jq.db.QueryRow(query)
|
|
||||||
var job Job
|
var job Job
|
||||||
err := row.Scan(&job.ID, &job.ActionID, &job.Action)
|
err := row.Scan(&job.ID, &job.ActionID, &job.Action)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -33,7 +33,7 @@ func (w *Worker) Run() {
|
||||||
logger.Info("starting worker")
|
logger.Info("starting worker")
|
||||||
for {
|
for {
|
||||||
time.Sleep(interval)
|
time.Sleep(interval)
|
||||||
j, err := w.jq.Next(TypeSimple)
|
j, err := w.jq.Next()
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, sql.ErrNoRows):
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
logger.Info("no simple jobs found")
|
logger.Info("no simple jobs found")
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"code.ewintr.nl/emdb/client"
|
"code.ewintr.nl/emdb/storage"
|
||||||
"code.ewintr.nl/go-kit/slugify"
|
"code.ewintr.nl/go-kit/slugify"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,8 +26,18 @@ extra.movie.rating = {{ .Rating }}
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
dbHost := os.Getenv("EMDB_DB_HOST")
|
||||||
movies, err := emdb.GetMovies()
|
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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
|
@ -19,7 +19,6 @@ func main() {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
//emdb := client.NewEMDB(os.Getenv("EMDB_BASE_URL"), os.Getenv("EMDB_API_KEY"))
|
|
||||||
dbHost := os.Getenv("EMDB_DB_HOST")
|
dbHost := os.Getenv("EMDB_DB_HOST")
|
||||||
dbName := os.Getenv("EMDB_DB_NAME")
|
dbName := os.Getenv("EMDB_DB_NAME")
|
||||||
dbUser := os.Getenv("EMDB_DB_USER")
|
dbUser := os.Getenv("EMDB_DB_USER")
|
||||||
|
|
|
@ -4,11 +4,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"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/chains"
|
||||||
"github.com/tmc/langchaingo/llms/ollama"
|
"github.com/tmc/langchaingo/llms/ollama"
|
||||||
"github.com/tmc/langchaingo/prompts"
|
"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() {
|
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)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-c
|
<-c
|
||||||
}
|
}
|
||||||
|
|
||||||
func Work(emdb *client.EMDB) {
|
func Work(movieRepo *storage.MovieRepository, reviewRepo *storage.ReviewRepository, jobQueue *job.JobQueue) {
|
||||||
for {
|
for {
|
||||||
j, err := emdb.GetNextAIJob()
|
j, err := jobQueue.Next()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
review, err := emdb.GetReview(j.ActionID)
|
review, err := reviewRepo.FindOne(j.ActionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
movie, err := emdb.GetMovie(review.MovieID)
|
movie, err := movieRepo.FindOne(review.MovieID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -105,7 +120,7 @@ func Work(emdb *client.EMDB) {
|
||||||
|
|
||||||
review.Titles = resp
|
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)
|
fmt.Printf("could not update review: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
Loading…
Reference in New Issue