Skip to content

Commit 495c78f

Browse files
authored
Implement FREQUENCY (#9)
1 parent 671eccc commit 495c78f

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ docker run -e METABASE_HOSTNAME="" -e METABASE_USE_API_KEY="" -e METABASE_API_KE
2626
- ```FORMAL_API_KEY```: The API key of the formal instance
2727
- ```FORMAL_APP_ID```: The app id of the Formal Metabase integration
2828
- ```VERIFY_TLS```: Whether or not to verify the TLS certificate of the Metabase instance. Set to `true` or `false`
29-
- ```LOG_LEVEL``` (optional): Set the Global logging level to any of these options: `debug`, `info`, `warn`, `error`, `fatal`, `panic`, `disabled`. Default value is `info`.
29+
- ```LOG_LEVEL``` (optional): Set the Global logging level to any of these options: `debug`, `info`, `warn`, `error`, `fatal`, `panic`, `disabled`. Default value is `info`.
30+
- ```FREQUENCY``` (optional): The frequency at which to run the sync. Expected format: `1h`, `30m`, etc. If not provided, the sync will run once and then exit.

main.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55
"strconv"
6+
"time"
67

78
"github.com/rs/zerolog"
89
"github.com/rs/zerolog/log"
@@ -52,8 +53,23 @@ func main() {
5253
logLevel = "info"
5354
}
5455

55-
err = MetabaseWorkflow(metabaseIntegration, formalAPIKey, integrationID, verifyTLS)
56-
if err != nil {
57-
log.Fatal().Err(err).Msg("Error in MetabaseWorkflow")
56+
frequency := os.Getenv("FREQUENCY")
57+
var duration time.Duration
58+
if frequency != "" {
59+
duration, err = time.ParseDuration(frequency)
60+
if err != nil {
61+
log.Fatal().Err(err).Msg("Invalid FREQUENCY format. Expected format: '1h', '30m', etc.")
62+
}
63+
}
64+
65+
for {
66+
err = MetabaseWorkflow(metabaseIntegration, formalAPIKey, integrationID, verifyTLS)
67+
if err != nil {
68+
log.Error().Err(err).Msg("Error in MetabaseWorkflow")
69+
}
70+
if frequency == "" {
71+
break
72+
}
73+
time.Sleep(duration)
5874
}
5975
}

0 commit comments

Comments
 (0)