github.com/ThomasObenaus/nomad@v0.11.1/command/system_gc.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/posener/complete"
     8  )
     9  
    10  type SystemGCCommand struct {
    11  	Meta
    12  }
    13  
    14  func (c *SystemGCCommand) Help() string {
    15  	helpText := `
    16  Usage: nomad system gc [options]
    17  
    18    Initializes a garbage collection of jobs, evaluations, allocations, and nodes.
    19  
    20  General Options:
    21  
    22    ` + generalOptionsUsage()
    23  	return strings.TrimSpace(helpText)
    24  }
    25  
    26  func (c *SystemGCCommand) Synopsis() string {
    27  	return "Run the system garbage collection process"
    28  }
    29  
    30  func (c *SystemGCCommand) AutocompleteFlags() complete.Flags {
    31  	return c.Meta.AutocompleteFlags(FlagSetClient)
    32  }
    33  
    34  func (c *SystemGCCommand) AutocompleteArgs() complete.Predictor {
    35  	return complete.PredictNothing
    36  }
    37  
    38  func (c *SystemGCCommand) Name() string { return "system gc" }
    39  
    40  func (c *SystemGCCommand) Run(args []string) int {
    41  
    42  	// Get the HTTP client
    43  	client, err := c.Meta.Client()
    44  	if err != nil {
    45  		c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
    46  		return 1
    47  	}
    48  
    49  	if err := client.System().GarbageCollect(); err != nil {
    50  		c.Ui.Error(fmt.Sprintf("Error running system garbage-collection: %s", err))
    51  		return 1
    52  	}
    53  	return 0
    54  }