66 "fmt"
77 "os"
88 "os/signal"
9- "path/filepath"
109 "strconv"
1110 "syscall"
1211 "time"
@@ -41,7 +40,6 @@ func humanizeDuration(d time.Duration) string {
4140 }
4241}
4342
44-
4543func (w * DPromptsWorker ) Work (ctx context.Context , job * river.Job [DPromptsJobArgs ]) error {
4644 jobStart := time .Now ()
4745 jobID := strconv .FormatInt (job .ID , 10 )
@@ -62,10 +60,10 @@ func (w *DPromptsWorker) Work(ctx context.Context, job *river.Job[DPromptsJobArg
6260
6361 homeDir , err := os .UserHomeDir ()
6462 if err != nil {
63+ log .Error ().Err (err ).Msg ("Unable to determine home directory for config file" )
6564 return err
6665 }
67- configPath := filepath .Join (homeDir , ".dprompts.toml" )
68-
66+ configPath := homeDir + string (os .PathSeparator ) + ".dprompts.toml"
6967 tx , err := w .db .Begin (ctx )
7068 if err != nil {
7169 return err
@@ -85,10 +83,10 @@ func (w *DPromptsWorker) Work(ctx context.Context, job *river.Job[DPromptsJobArg
8583 // ---- subtasks ----
8684 for i , sub := range job .Args .SubTasks {
8785 log .Info ().
88- Str ("job_id" , jobID ).
89- Int ("subtask" , i ).
90- Any ("metadata" , sub .Metadata ).
91- Msg ("Subtask started" )
86+ Str ("job_id" , jobID ).
87+ Int ("subtask" , i ).
88+ Any ("metadata" , sub .Metadata ).
89+ Msg ("Subtask started" )
9290 ollamaStart := time .Now ()
9391
9492 response , err := CallOllama (
@@ -155,11 +153,6 @@ func (w *DPromptsWorker) Work(ctx context.Context, job *river.Job[DPromptsJobArg
155153 return nil
156154}
157155
158-
159-
160-
161-
162-
163156func RegisterWorkers (db * pgxpool.Pool ) * river.Workers {
164157 workers := river .NewWorkers ()
165158 river .AddWorker (workers , & DPromptsWorker {db : db })
@@ -171,8 +164,8 @@ func createWorkerClient(
171164 workers * river.Workers ,
172165 concurrentWorkers int ) (* river.Client [pgx.Tx ], error ) {
173166 log .Info ().
174- Int ("concurrent_workers" , concurrentWorkers ).
175- Msg ("Initializing River worker client" )
167+ Int ("concurrent_workers" , concurrentWorkers ).
168+ Msg ("Initializing River worker client" )
176169 return river .NewClient [pgx.Tx ](driver , & river.Config {
177170 Queues : map [string ]river.QueueConfig {
178171 river .QueueDefault : {MaxWorkers : concurrentWorkers },
@@ -183,7 +176,7 @@ func createWorkerClient(
183176}
184177
185178func RunWorker (ctx context.Context , driver * riverpgxv5.Driver , cancel context.CancelFunc , db * pgxpool.Pool ) {
186-
179+
187180 homeDir , err := os .UserHomeDir ()
188181 if err != nil {
189182 log .Fatal ().Err (err ).Msg ("Unable to determine home directory" )
@@ -256,7 +249,6 @@ func (w *DPromptsWorker) resolveGroup(ctx context.Context, tx pgx.Tx, jobID stri
256249 return & id , nil
257250}
258251
259-
260252// insertResult inserts or updates a dprompt result for a job
261253func (w * DPromptsWorker ) insertResult (ctx context.Context , tx pgx.Tx , jobID int64 , jsonResponse []byte , groupID * int ) error {
262254 _ , err := tx .Exec (ctx ,
@@ -275,5 +267,3 @@ func (w *DPromptsWorker) insertResult(ctx context.Context, tx pgx.Tx, jobID int6
275267 }
276268 return nil
277269}
278-
279-
0 commit comments