Added a main loop on a timed interval
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-09-01 00:17:29 -04:00
parent 02dfc7c291
commit cf854a91f0
2 changed files with 20 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package main
import (
"time"
"github.com/spf13/viper"
"git.metaunix.net/BitGoblin/adept/config"
@ -12,7 +14,10 @@ func main() {
r := transcoder.NewRepository(viper.GetString("transcoder.repository"))
// main program loop - runs infinitely until externally terminated
for {
ingestFiles := r.SearchIngest()
for _, i := range ingestFiles {
// archive file
r.ArchiveFile(i.Name())
@ -21,4 +26,9 @@ func main() {
// clean up source file
r.CleanupFile(i.Name())
}
// sleep for X minutes - specified in the adept.toml config file
interval := viper.GetInt("transcoder.interval")
time.Sleep(time.Duration(interval) * time.Minute)
}
}

View File

@ -30,6 +30,8 @@ func NewRepository(path string) *Repository {
func (r *Repository) SearchIngest() []os.FileInfo {
ingestPath := filepath.Join(r.basePath, "ingest")
log.Printf("Searching ingest directory for files to transcode...")
ingestDir, err := os.Open(ingestPath)
if err != nil {
log.Fatalf("Error opening ingest directory: %s", err)