-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support run REAPER as daemon and handle cron internally
- Loading branch information
1 parent
b235e69
commit 91bc13f
Showing
8 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea | ||
build | ||
|
||
.reaper | ||
.reaper | ||
repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package daemon | ||
|
||
import ( | ||
"github.com/go-co-op/gocron" | ||
"github.com/leslieleung/reaper/internal/config" | ||
"github.com/leslieleung/reaper/internal/rip" | ||
"github.com/leslieleung/reaper/internal/ui" | ||
"github.com/spf13/cobra" | ||
"time" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "daemon", | ||
Short: "daemon runs as a daemon to monitor git repositories", | ||
Run: runDaemon, | ||
} | ||
|
||
func runDaemon(cmd *cobra.Command, args []string) { | ||
storageMap := config.GetStorageMap() | ||
|
||
s := gocron.NewScheduler(time.Local) | ||
s.SetMaxConcurrentJobs(3, gocron.WaitMode) | ||
|
||
for _, repo := range config.GetRepositories() { | ||
if repo.Cron == "" { | ||
continue | ||
} | ||
storages := make([]config.MultiStorage, 0) | ||
for _, storage := range repo.Storage { | ||
if s, ok := storageMap[storage]; !ok { | ||
continue | ||
} else { | ||
storages = append(storages, s) | ||
} | ||
} | ||
_, err := s.Cron(repo.Cron).Do(rip.Rip, repo, storages) | ||
if err != nil { | ||
ui.Errorf("Error scheduling %s, %s", repo.Name, err) | ||
} | ||
ui.Printf("Scheduled %s, cron: %s", repo.Name, repo.Cron) | ||
} | ||
ui.Printf("Starting daemon") | ||
s.StartBlocking() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters