-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
331 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package cmd | |
|
||
import ( | ||
"embed" | ||
_ "embed" | ||
"fmt" | ||
|
||
gtm "github.com/MichaelMure/go-term-markdown" | ||
|
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,52 @@ | ||
package cmd | ||
|
||
import ( | ||
_ "embed" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/gabrie30/ghorg/colorlog" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var recloneCronCmd = &cobra.Command{ | ||
Use: "reclone-cron", | ||
Short: "Simple cron that will trigger your reclone command at a specified minute intervals indefinitely", | ||
Long: `Read the documentation and examples in the Readme under Reclone Server heading`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if cmd.Flags().Changed("minutes") { | ||
os.Setenv("GHORG_CRON_TIMER_MINUTES", cmd.Flag("minutes").Value.String()) | ||
} | ||
|
||
startReCloneCron() | ||
}, | ||
} | ||
|
||
func startReCloneCron() { | ||
if os.Getenv("GHORG_CRON_TIMER_MINUTES") == "" { | ||
return | ||
} | ||
colorlog.PrintInfo("Cron activated and will first run after " + os.Getenv("GHORG_CRON_TIMER_MINUTES") + " minutes ") | ||
|
||
minutes, err := strconv.Atoi(os.Getenv("GHORG_CRON_TIMER_MINUTES")) | ||
if err != nil { | ||
log.Fatalf("Invalid GHORG_CRON_TIMER_MINUTES: %v", err) | ||
} | ||
|
||
ticker := time.NewTicker(time.Duration(minutes) * time.Minute) | ||
defer ticker.Stop() | ||
|
||
for range ticker.C { | ||
colorlog.PrintInfo("starting reclone cron, time: " + time.Now().Format(time.RFC1123)) | ||
cmd := exec.Command("ghorg", "reclone") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
|
||
if err := cmd.Run(); err != nil { | ||
log.Printf("Failed to run ghorg reclone: %v", err) | ||
} | ||
} | ||
} |
Oops, something went wrong.