summaryrefslogtreecommitdiff
path: root/internal/cli/jobs/subcommands.go
blob: a3d5d7a6dece94e653bdd1704cd4ec8503678b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jobs

import (
	"net/rpc"
	"os"

	jobsv1 "github.com/roadrunner-server/api/v4/build/jobs/v1"
)

func pause(client *rpc.Client, pause []string, silent *bool) error {
	pipes := &jobsv1.Pipelines{Pipelines: pause}
	er := &jobsv1.Empty{}

	err := client.Call(pauseRPC, pipes, er)
	if err != nil {
		return err
	}

	if !*silent {
		renderPipelines(os.Stdout, pause).Render()
	}

	return nil
}

func resume(client *rpc.Client, resume []string, silent *bool) error {
	pipes := &jobsv1.Pipelines{Pipelines: resume}
	er := &jobsv1.Empty{}

	err := client.Call(resumeRPC, pipes, er)
	if err != nil {
		return err
	}

	if !*silent {
		renderPipelines(os.Stdout, resume).Render()
	}

	return nil
}

func destroy(client *rpc.Client, destroy []string, silent *bool) error {
	pipes := &jobsv1.Pipelines{Pipelines: destroy}
	resp := &jobsv1.Pipelines{}

	err := client.Call(destroyRPC, pipes, resp)
	if err != nil {
		return err
	}

	if !*silent {
		renderPipelines(os.Stdout, resp.GetPipelines()).Render()
	}

	return nil
}

func list(client *rpc.Client) error {
	resp := &jobsv1.Pipelines{}
	er := &jobsv1.Empty{}

	err := client.Call(listRPC, er, resp)
	if err != nil {
		return err
	}

	renderPipelines(os.Stdout, resp.GetPipelines()).Render()

	return nil
}