Skip to content

Commit 77f5125

Browse files
committed
✨ parametrize call intervals
1 parent da15835 commit 77f5125

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ docker run -v $(pwd)/migrations:/migrations --network host migrate/migrate -path
8181
## TODO
8282

8383
- [ ] display user in interface and labels
84-
- [ ] configure interval / notification frequency

internal/datacontroller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/charmbracelet/log"
1212
)
1313

14-
const CHECK_INTERVAL_S = 3000
1514
const DATA_REFRESH_INTERVAL_H = 2
1615
const MAX_ISSUE_NOTIFS = 7
1716

@@ -73,7 +72,7 @@ func (d *DataController) Worker() {
7372

7473
} else {
7574
log.Debug(".")
76-
time.Sleep(time.Duration(CHECK_INTERVAL_S) * time.Millisecond)
75+
time.Sleep(time.Duration(GetSettings().Interval) * time.Hour)
7776
}
7877
}
7978
}

internal/settings.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ import (
99
var settings *Settings
1010

1111
type Settings struct {
12-
GhToken string
13-
Labels string
12+
GhToken string
13+
// Hours interval between Github queries
14+
Interval int
15+
DBFile string
16+
// labels to look for
17+
// ex: "\"help-wanted\", \"help wanted\",\"junior friendly\",\"good first issue\""
18+
Labels string
19+
//optional
1420
MatrixRoomID string
1521
MatrixUsername string
1622
MatrixPassword string
1723
MatrixServer string
18-
DBFile string
1924
}
2025

2126
func GetSettings() *Settings {
@@ -38,6 +43,9 @@ func (s *Settings) checkSettings() {
3843
if s.GhToken == "" {
3944
log.Fatal("Missing Github token")
4045
}
46+
if s.Interval < 1 || s.Interval > 100 {
47+
log.Fatal("Invalid interval : should be between 1 and 100 hours")
48+
}
4149
if s.DBFile == "" {
4250
log.Fatal("Missing database file path")
4351
}

main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func main() {
2727
}
2828

2929
debugFlag := flag.Bool("debug", false, "Display debug logs")
30+
interval := flag.Int("interval", 7, "Hours interval between github queries")
3031
ghTokenFlag := flag.String("gh-token", "", "Github token")
3132
labels := flag.String("labels", "\"help-wanted\", \"help wanted\",\"junior friendly\",\"good first issue\"", "labels to look for")
3233
dbFile := flag.String("db-file", "db/help-the-stars.db", "SQLite database file")
@@ -38,13 +39,14 @@ func main() {
3839
flag.Parse()
3940

4041
internal.SetSettings(&internal.Settings{
41-
GhToken: *ghTokenFlag,
42-
Labels: *labels,
43-
DBFile: *dbFile,
44-
MatrixServer: *matrixServer,
42+
GhToken: *ghTokenFlag,
43+
Interval: *interval,
44+
Labels: *labels,
45+
DBFile: *dbFile,
46+
MatrixServer: *matrixServer,
4547
MatrixUsername: *matrixUsername,
4648
MatrixPassword: *matrixPassword,
47-
MatrixRoomID: *matrixRoomID,
49+
MatrixRoomID: *matrixRoomID,
4850
})
4951

5052
matrix := internal.CreateMatrixClient()

0 commit comments

Comments
 (0)