Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit d647790

Browse files
authored
Enable configuration of scheduled automation jobs for instrument controllers (#230)
* Make the instrument module "enabled" columns NOT NULL * Only start Planktoscope MQTT clients for enabled controllers * Persist automation jobs in database * Parse automation job config with HCL * Allow setting name and desc for cameras, controllers, & automation jobs * Start and cancel automation jobs with the gocron scheduler * Upgrade dependencies * Downgrade OPA to v0.49.2 because of OPA issue 5758 * Allow multiple action types and multiple actions in a job * Make controller pump actions trigger MQTT commands for Planktoscopes
1 parent 0d31d87 commit d647790

File tree

69 files changed

+2647
-960
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2647
-960
lines changed

db/embeds.go

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ var MigrationFiles []database.MigrationFile = []database.MigrationFile{
3232
{Domain: "instruments", File: instruments.MigrationFiles[2]},
3333
{Domain: "sessions", File: sessions.MigrationFiles[0]},
3434
{Domain: "instruments", File: instruments.MigrationFiles[3]},
35+
{Domain: "instruments", File: instruments.MigrationFiles[4]},
36+
{Domain: "instruments", File: instruments.MigrationFiles[5]},
37+
{Domain: "instruments", File: instruments.MigrationFiles[6]},
3538
}
3639

3740
// Queries

go.mod

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ require (
88
github.com/benbjohnson/hashfs v0.2.1
99
github.com/dgraph-io/ristretto v0.1.1
1010
github.com/eclipse/paho.mqtt.golang v1.4.2
11+
github.com/go-co-op/gocron v1.18.1
1112
github.com/gorilla/csrf v1.7.1
1213
github.com/gorilla/sessions v1.2.1
1314
github.com/gorilla/websocket v1.5.0
15+
github.com/hashicorp/hcl/v2 v2.16.2
1416
github.com/labstack/echo/v4 v4.10.2
1517
github.com/labstack/gommon v0.4.0
1618
github.com/open-policy-agent/opa v0.49.2
@@ -28,25 +30,30 @@ require (
2830
github.com/Masterminds/goutils v1.1.1 // indirect
2931
github.com/Masterminds/semver/v3 v3.2.0 // indirect
3032
github.com/OneOfOne/xxhash v1.2.8 // indirect
33+
github.com/agext/levenshtein v1.2.1 // indirect
3134
github.com/agnivade/levenshtein v1.1.1 // indirect
35+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
3236
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
3337
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3438
github.com/dustin/go-humanize v1.0.1 // indirect
3539
github.com/ghodss/yaml v1.0.0 // indirect
3640
github.com/gobwas/glob v0.2.3 // indirect
3741
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
3842
github.com/golang/glog v1.0.0 // indirect
39-
github.com/golang/protobuf v1.5.2 // indirect
43+
github.com/golang/protobuf v1.5.3 // indirect
44+
github.com/google/go-cmp v0.5.9 // indirect
4045
github.com/google/uuid v1.3.0 // indirect
4146
github.com/gorilla/securecookie v1.1.1 // indirect
4247
github.com/huandu/xstrings v1.3.3 // indirect
4348
github.com/imdario/mergo v0.3.13 // indirect
4449
github.com/mattn/go-colorable v0.1.13 // indirect
4550
github.com/mattn/go-isatty v0.0.17 // indirect
4651
github.com/mitchellh/copystructure v1.2.0 // indirect
52+
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
4753
github.com/mitchellh/reflectwalk v1.0.2 // indirect
4854
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
4955
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
56+
github.com/robfig/cron/v3 v3.0.1 // indirect
5057
github.com/rogpeppe/go-internal v1.8.0 // indirect
5158
github.com/shopspring/decimal v1.3.1 // indirect
5259
github.com/spf13/cast v1.5.0 // indirect
@@ -59,10 +66,11 @@ require (
5966
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
6067
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
6168
github.com/yashtewari/glob-intersection v0.1.0 // indirect
69+
github.com/zclconf/go-cty v1.12.1 // indirect
6270
golang.org/x/crypto v0.6.0 // indirect
63-
golang.org/x/net v0.7.0 // indirect
64-
golang.org/x/oauth2 v0.2.0 // indirect
65-
golang.org/x/sys v0.5.0 // indirect
71+
golang.org/x/net v0.8.0 // indirect
72+
golang.org/x/oauth2 v0.4.0 // indirect
73+
golang.org/x/sys v0.6.0 // indirect
6674
golang.org/x/text v0.8.0 // indirect
6775
golang.org/x/time v0.3.0 // indirect
6876
google.golang.org/appengine v1.6.7 // indirect

go.sum

+27-8
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj
4242
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
4343
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
4444
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
45+
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
46+
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
4547
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
4648
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
49+
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
50+
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
4751
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
4852
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
4953
github.com/atrox/haikunatorgo v2.0.0+incompatible h1:ZSMT/63RgDmkfUDwL4G42n7eOzGQYKJLOcPerT7rxJw=
@@ -91,9 +95,12 @@ github.com/foxcpp/go-mockdns v0.0.0-20210729171921-fb145fc6f897 h1:E52jfcE64UG42
9195
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
9296
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
9397
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
98+
github.com/go-co-op/gocron v1.18.1 h1:erHHbIIav46xAV54lnyKKjrKLP+2RgjuDsbwGamBEvI=
99+
github.com/go-co-op/gocron v1.18.1/go.mod h1:UqVyvM90I1q/R1qGEX6cBORI6WArLuEgYlbncLMvzRM=
94100
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
95101
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
96102
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
103+
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
97104
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
98105
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
99106
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
@@ -127,8 +134,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
127134
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
128135
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
129136
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
130-
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
131-
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
137+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
138+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
132139
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
133140
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
134141
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -171,6 +178,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
171178
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
172179
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
173180
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
181+
github.com/hashicorp/hcl/v2 v2.16.2 h1:mpkHZh/Tv+xet3sy3F9Ld4FyI2tUpWe9x3XtPx9f1a0=
182+
github.com/hashicorp/hcl/v2 v2.16.2/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng=
174183
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
175184
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
176185
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
@@ -188,6 +197,7 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
188197
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
189198
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
190199
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
200+
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
191201
github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M=
192202
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
193203
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
@@ -205,6 +215,8 @@ github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
205215
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
206216
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
207217
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
218+
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
219+
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
208220
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
209221
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
210222
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
@@ -228,11 +240,14 @@ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5X
228240
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
229241
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
230242
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
243+
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
244+
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
231245
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
232246
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
233247
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
234248
github.com/sargassum-world/godest v0.5.1 h1:twu4bmrAxC+CKkC7GJiJLNSGrQD39WIJkMk/WWCZyb8=
235249
github.com/sargassum-world/godest v0.5.1/go.mod h1:OVmFA0akxcZDXppUq+Ts3PjAnP5ux3+mbyboGpTztMM=
250+
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
236251
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
237252
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
238253
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
@@ -246,7 +261,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
246261
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
247262
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
248263
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
249-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
264+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
250265
github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
251266
github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k=
252267
github.com/twmb/murmur3 v1.1.6 h1:mqrRot1BRxm+Yct+vavLMou2/iJt0tNVTTC0QoIjaZg=
@@ -273,12 +288,15 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
273288
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
274289
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
275290
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
291+
github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY=
292+
github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
276293
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
277294
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
278295
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
279296
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
280297
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
281298
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
299+
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
282300
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
283301
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
284302
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -354,16 +372,16 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
354372
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
355373
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
356374
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
357-
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
358-
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
375+
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
376+
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
359377
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
360378
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
361379
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
362380
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
363381
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
364382
golang.org/x/oauth2 v0.0.0-20210323180902-22b0adad7558/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
365-
golang.org/x/oauth2 v0.2.0 h1:GtQkldQ9m7yvzCL1V+LrYow3Khe0eJH0w7RbX/VbaIU=
366-
golang.org/x/oauth2 v0.2.0/go.mod h1:Cwn6afJ8jrQwYMxQDTpISoXmXW9I6qF6vDeuuoX3Ibs=
383+
golang.org/x/oauth2 v0.4.0 h1:NF0gk8LVPg1Ml7SSbGyySuoxdsXitj7TvgvuRxIMc/M=
384+
golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec=
367385
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
368386
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
369387
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -414,8 +432,9 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
414432
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
415433
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
416434
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
417-
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
418435
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
436+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
437+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
419438
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
420439
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
421440
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package client
2+
3+
import (
4+
"github.com/sargassum-world/pslive/internal/clients/instruments"
5+
"github.com/sargassum-world/pslive/internal/clients/planktoscope"
6+
)
7+
8+
func NewPlanktoScopeControllerActionRunnerGetter(
9+
o *planktoscope.Orchestrator,
10+
) instruments.ControllerActionRunnerGetter {
11+
return func(id instruments.ControllerID) (a instruments.ControllerActionRunner, ok bool) {
12+
return o.Get(planktoscope.ClientID(id))
13+
}
14+
}

internal/app/pslive/client/globals.go

+43-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/sargassum-world/pslive/internal/clients/videostreams"
2323
)
2424

25-
type Globals struct {
25+
type BaseGlobals struct {
2626
Config conf.Config
2727
Cache clientcache.Cache
2828
DB *database.DB
@@ -37,20 +37,26 @@ type Globals struct {
3737
ACSigner actioncable.Signer
3838
TSBroker *turbostreams.Broker
3939

40-
Instruments *instruments.Store
41-
Planktoscopes *planktoscope.Orchestrator
42-
Presence *presence.Store
43-
Chat *chat.Store
44-
VSBroker *videostreams.Broker
45-
4640
Logger godest.Logger
4741
}
4842

49-
func NewGlobals(
43+
type Globals struct {
44+
Base *BaseGlobals
45+
46+
Instruments *instruments.Store
47+
Planktoscopes *planktoscope.Orchestrator
48+
InstrumentJobs *instruments.JobOrchestrator
49+
50+
Presence *presence.Store
51+
Chat *chat.Store
52+
VSBroker *videostreams.Broker
53+
}
54+
55+
func NewBaseGlobals(
5056
persistenceEmbeds database.Embeds, regoRoutesPackage string, regoModules []opa.Module,
5157
l godest.Logger,
52-
) (g *Globals, err error) {
53-
g = &Globals{}
58+
) (g *BaseGlobals, err error) {
59+
g = &BaseGlobals{}
5460
g.Config, err = conf.GetConfig()
5561
if err != nil {
5662
return nil, errors.Wrap(err, "couldn't set up application config")
@@ -92,12 +98,36 @@ func NewGlobals(
9298
g.ACSigner = actioncable.NewSigner(acsConfig)
9399
g.TSBroker = turbostreams.NewBroker(l)
94100

95-
g.Instruments = instruments.NewStore(g.DB)
101+
g.Logger = l
102+
return g, nil
103+
}
104+
105+
func NewGlobals(
106+
persistenceEmbeds database.Embeds, regoRoutesPackage string, regoModules []opa.Module,
107+
l godest.Logger,
108+
) (g *Globals, err error) {
109+
g = &Globals{}
110+
g.Base, err = NewBaseGlobals(persistenceEmbeds, regoRoutesPackage, regoModules, l)
111+
if err != nil {
112+
return nil, errors.Wrap(err, "couldn't set up base globals")
113+
}
114+
115+
g.Instruments = instruments.NewStore(g.Base.DB)
96116
g.Planktoscopes = planktoscope.NewOrchestrator(l)
117+
instrumentControllerActionRunners := instruments.NewControllerActionRunnerStore(
118+
g.Instruments,
119+
map[string]instruments.ControllerActionRunnerGetter{
120+
"planktoscope-v2.3": NewPlanktoScopeControllerActionRunnerGetter(g.Planktoscopes),
121+
},
122+
)
123+
g.InstrumentJobs = instruments.NewJobOrchestrator(map[string]instruments.ActionHandler{
124+
"sleep": instruments.HandleSleepAction,
125+
"controller": instrumentControllerActionRunners.HandleControllerAction,
126+
}, l)
127+
97128
g.Presence = presence.NewStore()
98-
g.Chat = chat.NewStore(g.DB)
129+
g.Chat = chat.NewStore(g.Base.DB)
99130
g.VSBroker = videostreams.NewBroker(l)
100131

101-
g.Logger = l
102132
return g, nil
103133
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package instruments
2+
3+
import (
4+
"context"
5+
"net/url"
6+
7+
"github.com/sargassum-world/pslive/internal/app/pslive/auth"
8+
"github.com/sargassum-world/pslive/internal/clients/instruments"
9+
)
10+
11+
func (h *Handlers) HandleInstrumentAutomationJobPost() auth.HTTPHandlerFunc {
12+
return handleInstrumentComponentPost(
13+
"automationJob",
14+
func(
15+
ctx context.Context, id instruments.AutomationJobID, iid instruments.InstrumentID,
16+
enabled bool, name, description string, params url.Values,
17+
) error {
18+
specType := params.Get("type")
19+
specification := params.Get("specification")
20+
if err := h.is.UpdateAutomationJob(ctx, instruments.AutomationJob{
21+
ID: id,
22+
Enabled: enabled,
23+
Name: name,
24+
Description: description,
25+
Type: specType,
26+
Specification: specification,
27+
}); err != nil {
28+
return err
29+
}
30+
// Note: when we have other automation job types, we'll need to generalize this
31+
if !enabled {
32+
h.ijo.Remove(id)
33+
return nil
34+
}
35+
return h.ijo.Update(id, iid, name, specType, specification)
36+
},
37+
func(ctx context.Context, id instruments.AutomationJobID) error {
38+
if err := h.is.DeleteAutomationJob(ctx, id); err != nil {
39+
return err
40+
}
41+
h.ijo.Remove(id)
42+
return nil
43+
},
44+
)
45+
}

0 commit comments

Comments
 (0)