MCPcopy
hub / github.com/tuna/tunasync / removeWorker

Function removeWorker

cmd/tunasynctl/tunasynctl.go:316–360  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

314}
315
316func removeWorker(c *cli.Context) error {
317 args := c.Args().Slice()
318 if len(args) != 0 {
319 return cli.Exit("Usage: tunasynctl -w <worker-id>", 1)
320 }
321 workerID := c.String("worker")
322 if len(workerID) == 0 {
323 return cli.Exit("Please specify the <worker-id>", 1)
324 }
325 url := fmt.Sprintf("%s/workers/%s", baseURL, workerID)
326
327 req, err := http.NewRequest("DELETE", url, nil)
328 if err != nil {
329 logger.Panicf("Invalid HTTP Request: %s", err.Error())
330 }
331 resp, err := client.Do(req)
332
333 if err != nil {
334 return cli.Exit(
335 fmt.Sprintf("Failed to send request to manager: %s", err.Error()), 1)
336 }
337 defer resp.Body.Close()
338
339 if resp.StatusCode != http.StatusOK {
340 body, err := io.ReadAll(resp.Body)
341 if err != nil {
342 return cli.Exit(
343 fmt.Sprintf("Failed to parse response: %s", err.Error()),
344 1)
345 }
346
347 return cli.Exit(fmt.Sprintf("Failed to correctly send"+
348 " command: HTTP status code is not 200: %s", body),
349 1)
350 }
351
352 res := map[string]string{}
353 _ = json.NewDecoder(resp.Body).Decode(&res)
354 if res["message"] == "deleted" {
355 fmt.Println("Successfully removed the worker")
356 } else {
357 return cli.Exit("Failed to remove the worker", 1)
358 }
359 return nil
360}
361
362func flushDisabledJobs(c *cli.Context) error {
363 req, err := http.NewRequest("DELETE", baseURL+flushDisabledPath, nil)

Callers

nothing calls this directly

Calls 6

ExitMethod · 0.80
PanicfMethod · 0.80
ErrorMethod · 0.80
DoMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected