Skip to content

Commit 0400355

Browse files
committed
Updated bulk format, added concurrency, Updated CLI
1 parent 8462492 commit 0400355

10 files changed

Lines changed: 301 additions & 143 deletions

File tree

.dprompts.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ temperature = 0.7
1313
topP = 0.9
1414

1515
[worker]
16-
max_workers = 1
16+
concurrent_workers = 1

config.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,23 @@ func NewDBPool(ctx context.Context, configPath string) (*pgxpool.Pool, error) {
6565
}
6666

6767
return dbPool, nil
68-
}
68+
}
69+
70+
func LoadWorkerConfig(path string) (*WorkerConfig, error) {
71+
var conf struct {
72+
Worker WorkerConfig
73+
}
74+
75+
_, err := toml.DecodeFile(path, &conf)
76+
if err != nil {
77+
return nil, err
78+
}
79+
80+
// Default fallback
81+
if conf.Worker.ConcurrentWorkers <= 0 {
82+
conf.Worker.ConcurrentWorkers = 1
83+
}
84+
85+
return &conf.Worker, nil
86+
}
87+

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212

1313
require (
1414
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1516
github.com/jackc/pgpassfile v1.0.0 // indirect
1617
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
1718
github.com/jackc/puddle/v2 v2.2.2 // indirect
@@ -21,6 +22,8 @@ require (
2122
github.com/riverqueue/river/riverdriver v0.26.0 // indirect
2223
github.com/riverqueue/river/rivershared v0.26.0 // indirect
2324
github.com/riverqueue/river/rivertype v0.26.0 // indirect
25+
github.com/spf13/cobra v1.10.2 // indirect
26+
github.com/spf13/pflag v1.0.9 // indirect
2427
github.com/stretchr/testify v1.11.1 // indirect
2528
github.com/tidwall/gjson v1.18.0 // indirect
2629
github.com/tidwall/match v1.1.1 // indirect

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
22
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
33
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
4+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
45
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
56
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
67
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
78
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
9+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
10+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
811
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 h1:Dj0L5fhJ9F82ZJyVOmBx6msDp/kfd1t9GRfny/mfJA0=
912
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds=
1013
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
@@ -44,6 +47,11 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
4447
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
4548
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
4649
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
50+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
51+
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
52+
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
53+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
54+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
4755
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4856
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4957
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -61,6 +69,7 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
6169
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
6270
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
6371
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
72+
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
6473
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
6574
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
6675
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=

groupmanagement.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,32 @@ func DeleteGroupAndResults(ctx context.Context, db *pgxpool.Pool, groupID int) e
2424
fmt.Printf("Deleted %d results and %d group(s) for group ID %d\n", res1.RowsAffected(), res2.RowsAffected(), groupID)
2525
return nil
2626
}
27+
28+
func DeleteGroupAndResultsAll(ctx context.Context, db *pgxpool.Pool,i int) error {
29+
// Delete all results that belong to any group
30+
_ = i
31+
res1, err := db.Exec(ctx, `
32+
DELETE FROM dprompts_results
33+
WHERE group_id IS NOT NULL
34+
`)
35+
if err != nil {
36+
return fmt.Errorf("failed to delete grouped results: %w", err)
37+
}
38+
39+
// Delete all groups
40+
res2, err := db.Exec(ctx, `
41+
DELETE FROM dprompt_groups
42+
`)
43+
if err != nil {
44+
return fmt.Errorf("failed to delete groups: %w", err)
45+
}
46+
47+
fmt.Printf(
48+
"TEMP CLEANUP: Deleted %d grouped results and %d group(s)\n",
49+
res1.RowsAffected(),
50+
res2.RowsAffected(),
51+
)
52+
53+
return nil
54+
}
55+

0 commit comments

Comments
 (0)