add admin script worker (#8491)
* admin: add plugin lock coordination * shell: allow bypassing lock checks * plugin worker: add admin script handler * mini: include admin_script in plugin defaults * admin script UI: drop name and enlarge text * admin script: add default script * admin_script: make run interval configurable * plugin: gate other jobs during admin_script runs * plugin: use last completed admin_script run * admin: backfill plugin config defaults * templ Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * comparable to default version Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * default to run Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * format Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * shell: respect pre-set noLock for fix.replication * shell: add force no-lock mode for admin scripts * volume balance worker already exists Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * admin: expose scheduler status JSON * shell: add sleep command * shell: restrict sleep syntax * Revert "shell: respect pre-set noLock for fix.replication" This reverts commit 2b14e8b82602a740d3a473c085e3b3a14f1ddbb3. * templ Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * fix import Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * less logs Co-Authored-By: Copilot <223556219+Copilot@users.noreply.github.com> * Reduce master client logs on canceled contexts * Update mini default job type count --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
43
weed/shell/command_sleep.go
Normal file
43
weed/shell/command_sleep.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Commands = append(Commands, &commandSleep{})
|
||||
}
|
||||
|
||||
// =========== Sleep ==============
|
||||
type commandSleep struct {
|
||||
}
|
||||
|
||||
func (c *commandSleep) Name() string {
|
||||
return "sleep"
|
||||
}
|
||||
|
||||
func (c *commandSleep) Help() string {
|
||||
return `sleep for N seconds (useful to simulate long running jobs)
|
||||
|
||||
sleep 5
|
||||
`
|
||||
}
|
||||
|
||||
func (c *commandSleep) HasTag(CommandTag) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *commandSleep) Do(args []string, _ *CommandEnv, _ io.Writer) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("sleep requires a seconds argument")
|
||||
}
|
||||
seconds, err := strconv.Atoi(args[0])
|
||||
if err != nil || seconds <= 0 {
|
||||
return fmt.Errorf("sleep duration must be a positive integer, got %q", args[0])
|
||||
}
|
||||
time.Sleep(time.Duration(seconds) * time.Second)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user