mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2024-11-16 17:07:36 +00:00
4c7d53547b
This make me easier to test the module with external services.
45 lines
976 B
Go
45 lines
976 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"text/tabwriter"
|
|
"time"
|
|
|
|
"github.com/ditatompel/xmr-remote-nodes/internal/cron"
|
|
"github.com/ditatompel/xmr-remote-nodes/internal/database"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var cronCmd = &cobra.Command{
|
|
Use: "cron",
|
|
Short: "Print cron tasks",
|
|
Long: `Print list of regular cron tasks running on the server.`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if err := database.ConnectDB(); err != nil {
|
|
panic(err)
|
|
}
|
|
crons, err := cron.New().Crons()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
if len(crons) == 0 {
|
|
fmt.Println("No crons found")
|
|
return
|
|
}
|
|
w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
|
|
fmt.Fprintf(w, "ID\t| Name\t| Run Every\t| Last Run\t| Took Time\n")
|
|
for _, cron := range crons {
|
|
fmt.Fprintf(w, "%d\t| %s\t| %ds\t| %s\t| %f\n",
|
|
cron.ID,
|
|
cron.Title,
|
|
cron.RunEvery,
|
|
time.Unix(cron.LastRun, 0).Format(time.RFC3339),
|
|
cron.RunTime,
|
|
)
|
|
}
|
|
w.Flush()
|
|
},
|
|
}
|