Skip to content

Commit 9ab8e95

Browse files
committed
Handle pause
1 parent 7489b43 commit 9ab8e95

File tree

10 files changed

+294
-16
lines changed

10 files changed

+294
-16
lines changed

app/contexts.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controllers.go

Lines changed: 45 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/test/manage_v1_testing.go

Lines changed: 123 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/agent/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ func main() {
3838
var (
3939
hibernate = flag.Bool("hibernate", false, "start hibernated")
4040
)
41+
42+
flag.Parse()
43+
4144
opts := agent.Opts{
4245
Hibernate: *hibernate,
4346
}
47+
4448
agent.Start(opts)
4549
}

design/manage.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,19 @@ var _ = Resource("manage_v1", func() {
3838

3939
Action("info", func() {
4040
Description("Returns the info about the agent")
41-
Routing(GET(""))
41+
Routing(GET("/info"))
4242
Response(OK, ManageInfoV1)
4343
})
44+
Action("pause", func() {
45+
Description("Restarts the agent in hibernation mode")
46+
Routing(POST("/pause"))
47+
Response(OK)
48+
})
49+
Action("update", func() {
50+
Description("Search for a new version, updates and restarts itself")
51+
Routing(POST("/update"))
52+
Response(OK)
53+
})
4454
})
4555

4656
var ManageInfoV1 = MediaType("application/vnd.arduino.agent.manage.info+json", func() {

main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ func Start(opts Opts) {
7777
monitor := discovery.New(1 * time.Second)
7878
monitor.Start(context.Background())
7979

80+
// Setup helper functions
81+
restart := restartFunc("", !opts.Hibernate)
82+
shutdown := func() {
83+
os.Exit(0)
84+
}
85+
8086
// Mount middleware
8187
service.Use(middleware.RequestID())
8288
service.Use(middleware.LogRequest(true))
@@ -92,7 +98,7 @@ func Start(opts Opts) {
9298
app.MountDiscoverV1Controller(service, d)
9399

94100
// Mount "manage" controller
95-
m := NewManageV1Controller(service, version, revision)
101+
m := NewManageV1Controller(service, version, revision, restart)
96102
app.MountManageV1Controller(service, m)
97103

98104
// Mount "tools" controller
@@ -107,12 +113,6 @@ func Start(opts Opts) {
107113
public := NewPublicController(service)
108114
app.MountPublicController(service, public)
109115

110-
// Mount systray
111-
restart := restartFunc("", !opts.Hibernate)
112-
shutdown := func() {
113-
os.Exit(0)
114-
}
115-
116116
// Find boards
117117
http, https := findPorts()
118118
if opts.HTTPPort != 0 {

manage.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ type ManageV1Controller struct {
3838
*goa.Controller
3939
Version string
4040
Revision string
41+
Restart func()
4142
}
4243

4344
// NewManageV1Controller creates a Manage_v1 controller.
44-
func NewManageV1Controller(service *goa.Service, version, revision string) *ManageV1Controller {
45+
func NewManageV1Controller(service *goa.Service, version, revision string, restart func()) *ManageV1Controller {
4546
return &ManageV1Controller{
4647
Controller: service.NewController("ManageV1Controller"),
4748
Version: version,
4849
Revision: revision,
50+
Restart: restart,
4951
}
5052
}
5153

@@ -56,3 +58,14 @@ func (c *ManageV1Controller) Info(ctx *app.InfoManageV1Context) error {
5658
Revision: c.Revision,
5759
})
5860
}
61+
62+
// Pause runs the Pause action.
63+
func (c *ManageV1Controller) Pause(ctx *app.PauseManageV1Context) error {
64+
c.Restart()
65+
return ctx.OK(nil)
66+
}
67+
68+
// Update runs the Update action.
69+
func (c *ManageV1Controller) Update(ctx *app.UpdateManageV1Context) error {
70+
return ctx.OK(nil)
71+
}

0 commit comments

Comments
 (0)