Skip to content

Commit 016e925

Browse files
committed
Formatted
1 parent 3cf0572 commit 016e925

4 files changed

Lines changed: 26 additions & 63 deletions

File tree

export.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ type ExportOptions struct {
2222
Overwrite bool
2323
}
2424

25-
2625
type ExportResult struct {
2726
JobID int64
2827
Response []byte
2928
GroupName *string
3029
CreatedAt time.Time
3130
}
3231

33-
34-
3532
func ExportResults(
3633
ctx context.Context,
3734
dbPool *pgxpool.Pool,
@@ -179,7 +176,6 @@ func ExportResults(
179176
return exported, rows.Err()
180177
}
181178

182-
183179
func writeExportFile(opts ExportOptions, r ExportResult) error {
184180
filename := fmt.Sprintf("%d.json", r.JobID)
185181
path := filepath.Join(opts.OutDir, filename)
@@ -212,7 +208,6 @@ func writeExportFile(opts ExportOptions, r ExportResult) error {
212208
return os.WriteFile(path, data, 0644)
213209
}
214210

215-
216211
func scanExistingExports(dir, format string) map[int64]struct{} {
217212
result := make(map[int64]struct{})
218213

main.go

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,40 @@ func main() {
5858
Use: "worker",
5959
Short: "Run the worker",
6060
Run: func(cmd *cobra.Command, args []string) {
61-
61+
6262
if !isOllamaRunning() {
6363
log.Warn().Msg("Ollama server is not running")
64-
64+
6565
if !askForConfirmation("Ollama is not running. Do you want me to start it for you?") {
6666
log.Fatal().Msg("Ollama is required to run the worker")
6767
}
68-
68+
6969
log.Info().Msg("Starting Ollama...")
7070
if err := startOllama(); err != nil {
7171
log.Fatal().Err(err).Msg("Failed to start Ollama")
7272
}
73-
73+
7474
log.Info().Msg("Waiting for Ollama to become ready...")
7575
if err := waitForOllama(15 * time.Second); err != nil {
7676
log.Fatal().Err(err).Msg("Ollama did not become ready")
7777
}
78-
78+
7979
log.Info().Msg("Ollama is running")
8080
}
81-
81+
8282
ctx, cancel := context.WithCancel(context.Background())
8383
defer cancel()
84-
84+
8585
dbPool, err := NewDBPool(ctx, configPath)
8686
if err != nil {
8787
log.Fatal().Err(err).Msg("Failed to connect to database")
8888
}
8989
defer dbPool.Close()
90-
90+
9191
driver := riverpgxv5.New(dbPool)
9292
RunWorker(ctx, driver, cancel, dbPool)
9393
},
9494
}
95-
9695

9796
// ---- View subcommand ----
9897
var totalGroups bool
@@ -127,11 +126,6 @@ func main() {
127126
viewCmd.Flags().IntVar(&groupID, "group", 0, "Display results for a specific group ID")
128127
viewCmd.Flags().IntVarP(&n, "number", "n", 10, "Number of results to display")
129128

130-
131-
132-
133-
134-
135129
// ---- Delete-group subcommand ----
136130
var deleteGroupID int
137131
// ---- Delete-group subcommand ----
@@ -163,9 +157,6 @@ func main() {
163157
}
164158
deleteGroupCmd.Flags().IntVar(&deleteGroupID, "group-id", 0, "Group ID to delete")
165159

166-
167-
168-
169160
// ---- Queue subcommands ----
170161
var queueN int
171162

@@ -207,7 +198,6 @@ func main() {
207198
},
208199
}
209200

210-
// ---- Queue Clear subcommand ----
211201
queueClearCmd := &cobra.Command{
212202
Use: "clear",
213203
Short: "Clear queued jobs",
@@ -285,7 +275,6 @@ func main() {
285275
},
286276
}
287277
queueCompletedFirstCmd.Flags().IntVarP(&queueN, "number", "n", 10, "Number of jobs to display")
288-
289278
queueCompletedLastCmd := &cobra.Command{
290279
Use: "last",
291280
Short: "View last completed jobs",
@@ -302,22 +291,16 @@ func main() {
302291
},
303292
}
304293
queueCompletedLastCmd.Flags().IntVarP(&queueN, "number", "n", 10, "Number of jobs to display")
305-
306-
// Wire completed commands
307294
queueCompletedCmd.AddCommand(queueCompletedCountCmd, queueCompletedFirstCmd, queueCompletedLastCmd)
308-
309-
// Wire main queue commands
310295
queueCmd.AddCommand(queueViewCmd, queueCountCmd, queueClearCmd, queueFailedCmd, queueCompletedCmd)
311296

312-
313-
314297
// ---- Export subcommand ----
315298
var (
316-
exportFormat string
317-
exportOutDir string
318-
exportFromDate string
319-
exportDryRun bool
320-
exportOverwrite bool
299+
exportFormat string
300+
exportOutDir string
301+
exportFromDate string
302+
exportDryRun bool
303+
exportOverwrite bool
321304
exportFullExport bool
322305
)
323306

@@ -341,7 +324,7 @@ func main() {
341324
DryRun: exportDryRun,
342325
Overwrite: exportOverwrite,
343326
})
344-
327+
345328
if err != nil {
346329
log.Fatal().Err(err).Msg("Export failed")
347330
}
@@ -351,7 +334,7 @@ func main() {
351334
Msg("Export completed successfully")
352335
},
353336
}
354-
337+
355338
exportCmd.Flags().StringVar(&exportFormat, "format", "json", "Export format: json | txt")
356339
exportCmd.Flags().StringVar(&exportOutDir, "out", "./dprompts_exports", "Output directory")
357340
exportCmd.Flags().StringVar(&exportFromDate, "from-date", "", "Export results created after this date (YYYY-MM-DD)")
@@ -363,12 +346,11 @@ func main() {
363346
false,
364347
"Export all results (ignores --from-date)",
365348
)
366-
349+
367350
// Add subcommands
368-
rootCmd.AddCommand(clientCmd, workerCmd, viewCmd, deleteGroupCmd, queueCmd,exportCmd)
351+
rootCmd.AddCommand(clientCmd, workerCmd, viewCmd, deleteGroupCmd, queueCmd, exportCmd)
369352

370353
if err := rootCmd.Execute(); err != nil {
371354
log.Fatal().Err(err).Msg("Command execution failed")
372355
}
373356
}
374-

managequeuedjobs.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ func ViewLastCompletedJobs(ctx context.Context, db *pgxpool.Pool, n int) error {
159159
return rows.Err()
160160
}
161161

162-
163162
func ViewJobsWithFailedAttempts(
164163
ctx context.Context,
165164
dbPool *pgxpool.Pool,
@@ -214,14 +213,14 @@ func ViewJobsWithFailedAttempts(
214213

215214
for rows.Next() {
216215
var (
217-
id int64
218-
state string
219-
attempt int
220-
maxAttempts int
221-
kind string
222-
createdAt time.Time
223-
attemptedAt *time.Time
224-
scheduledAt *time.Time
216+
id int64
217+
state string
218+
attempt int
219+
maxAttempts int
220+
kind string
221+
createdAt time.Time
222+
attemptedAt *time.Time
223+
scheduledAt *time.Time
225224
)
226225

227226
if err := rows.Scan(
@@ -266,4 +265,3 @@ func ViewJobsWithFailedAttempts(
266265

267266
return rows.Err()
268267
}
269-

ollama.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ func CallOllama(
9393
return ollamaResp.Message.Content, nil
9494
}
9595

96-
97-
9896
func isOllamaRunning() bool {
9997
client := http.Client{
10098
Timeout: 2 * time.Second,
@@ -109,12 +107,6 @@ func isOllamaRunning() bool {
109107
return resp.StatusCode == http.StatusOK
110108
}
111109

112-
113-
114-
//
115-
// -------- Linux detection helpers --------
116-
//
117-
118110
func hasSystemdOllama() bool {
119111
cmd := exec.Command("systemctl", "list-unit-files", "ollama.service")
120112
return cmd.Run() == nil
@@ -155,10 +147,6 @@ func askLinuxStartMethod() (string, error) {
155147
return choice, err
156148
}
157149

158-
//
159-
// -------- Start Ollama --------
160-
//
161-
162150
func startOllamaLinux() error {
163151
choice, err := askLinuxStartMethod()
164152
if err != nil {
@@ -232,4 +220,4 @@ func waitForOllama(timeout time.Duration) error {
232220
}
233221

234222
return fmt.Errorf("ollama did not start within %s", timeout)
235-
}
223+
}

0 commit comments

Comments
 (0)