Skip to content

Commit cb9b2d9

Browse files
authored
Merge pull request #71 from philips-software/feature/function-updates
Refactor hsdp_function for improved update mechanism
2 parents ae7d4c5 + 700a003 commit cb9b2d9

File tree

6 files changed

+193
-167
lines changed

6 files changed

+193
-167
lines changed

docs/guides/functions.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,34 @@ option. To achieve this the gateway runs an internal CRON scheduler which is dri
121121
in the Iron.io backend, syncing the config every few seconds.
122122

123123
```hcl
124-
schedule {
125-
cron = "14 15 * * *"
126-
timeout = 900
124+
resource "hsdp_function" "cuda_test" {
125+
name = "cuda-test"
126+
docker_image = "philipslabs/hsdp-task-cuda-test:v0.0.5"
127+
command = ["/app/cudatest"]
128+
129+
schedule = "14 15 * * * *"
130+
timeout = 120
131+
132+
backend {
133+
credentials = module.siderite_backend.credentials
127134
}
135+
}
128136
```
129137
The above example would queue your `hsdp_function` every day at exactly 3.14pm.
130138
The following one would queue your function every Sunday morning at 5am:
131139

132140
```hcl
133-
schedule {
134-
cron = "0 5 * * 0"
135-
timeout = 1800
141+
resource "hsdp_function" "cuda_test" {
142+
name = "cuda-test"
143+
docker_image = "philipslabs/hsdp-task-cuda-test:v0.0.4"
144+
command = ["/app/cudatest"]
145+
146+
schedule = "0 5 * * * 0"
147+
timeout = 120
148+
149+
backend {
150+
credentials = module.siderite_backend.credentials
151+
}
136152
}
137153
```
138154

@@ -142,12 +158,20 @@ Iron cluster, so the exact start time is always determined by how busy the clust
142158
Finally, an example of using the Iron.io native scheduler:
143159

144160
```hcl
145-
schedule {
146-
run_every = "1d"
161+
resource "hsdp_function" "cuda_test" {
162+
name = "cuda-test"
163+
docker_image = "philipslabs/hsdp-task-cuda-test:v0.0.5"
164+
command = ["/app/cudatest"]
165+
166+
run_every = "20m"
167+
timeout = 120
168+
169+
backend {
170+
credentials = module.siderite_backend.credentials
171+
}
147172
}
148173
```
149-
This will run your function once every day, the time of day however depends on when Terraform deployed
150-
your function.
174+
This will run your function every 20 minutes.
151175

152176
-> Always set a timeout value for your scheduled function. This sets a limit on the runtime for each invocation.
153177

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The following arguments are supported:
5151

5252
* `secret_key` - (Optional) The secret key as provided by HSDP. Actions which require API signing will not work if this value is missing.
5353

54-
* `cartel_host` - (Optional) The cartel host as provided by HSDP. Auto-discovered when region and environment are specified.
54+
* `cartel_host` - (Optional) The cartel host as provided by HSDP. Auto-discovered when region is specified.
5555

5656
* `cartel_token` - (Optional) The cartel token as provided by HSDP.
5757

docs/resources/function.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# hsdp_function
22

3-
Define function-as-a-service using various backends. Currently
3+
Define function-as-a-service using various backends. Currently,
44
only `siderite` (HSDP Iron) is supported.
55

66
## Example usage
@@ -11,7 +11,7 @@ resource "hsdp_function" "rds_backup" {
1111
1212
# The docker packaged function business logic
1313
docker_image = var.streaming_backup_image
14-
docker_credentails = {
14+
docker_credentials = {
1515
username = var.docker_username
1616
password = var.docker_password
1717
}
@@ -51,22 +51,19 @@ The following arguments are supported:
5151
* `password` - (Required) The registry password
5252
* `command` - (Optional) The command to execute in the container. Default is `/app/server`
5353
* `environment` - (Optional, map) The environment variables to set in the docker container before executing the function
54-
* `schedule` - (Optional) Schedule the function. When not set, the function becomes a task.
55-
* `start` - (Optional, RFC3339) When to start the schedule. Example: `2021-01-01T04:00:00Z`. Default is a date in the past.
56-
Setting the start argument allows you to control the specific time within the day when your task will be scheduled.
57-
* `run_every` - (Optional) Run the function every `{value}{unit}` period. Supported units are `s`, `m`, `h`, `d` for second, minute, hours, days respectively. Conflicts with `cron`
58-
Example: a value of `"20m"` would run the function every 20 minutes.
59-
* `cron` - (Optional) set schedule using cron format. This requires a backend with activated gateway. Conflicts with `run_every`
60-
* `timeout` - (Optional, int) When set, limits the execution time (seconds) to this value. Default: `1800` (30 minutes)
54+
* `schedule` - (Optional) set schedule using cron format. This requires a backend with activated gateway. Conflicts with `run_every`
55+
* `run_every` - (Optional) Run the function every `{value}{unit}` period. Supported units are `s`, `m`, `h`, `d` for second, minute, hours, days respectively. Conflicts with `cron`
56+
Example: a value of `"20m"` would run the function every 20 minutes.
57+
* `timeout` - (Optional, int) When set, limits the execution time (seconds) to this value. Default: `1800` (30 minutes)
6158
* `backend` - (Required) The backend to use for scheduling your functions.
62-
* `type` - (Required) The backend type. Only `siderite` is supported at this time.
59+
* `type` - (Optional) The backend type. Only `siderite` is supported at this time. Defaults to: `siderite`
6360
* `credentials` - (Required, map) The backend credentials. Must be iron configuration details at this time.
6461

6562
## Attribute reference
6663

6764
The following attributes are exported:
6865

6966
* `endpoint` - The gateway endpoint where you can trigger this function
70-
* `async_endpoint` - The gateway endpoint where eyou can schedule the function asychnronously
71-
* `token` - The token to use in case `auth_type` is set to `token`. This token must be pased in the HTTP `Authorization` header as `Token TOKENHERE`
67+
* `async_endpoint` - The gateway endpoint where you can schedule the function asynchronously
68+
* `token` - The token to use in case `auth_type` is set to `token`. This token must be pasted in the HTTP `Authorization` header as `Token TOKENHERE`
7269
* `auth_type` - The authentication type. Possible values [`none`, `token`, `iam`]

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
1919
github.com/opencontainers/go-digest v1.0.0 // indirect
2020
github.com/philips-labs/siderite v0.7.0
21-
github.com/philips-software/go-hsdp-api v0.38.0
21+
github.com/philips-software/go-hsdp-api v0.38.1
2222
github.com/pkg/errors v0.9.1
2323
github.com/robfig/cron/v3 v3.0.1
2424
github.com/stretchr/testify v1.7.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,8 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR
642642
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
643643
github.com/philips-labs/siderite v0.7.0 h1:Q26TwM3Er6zseFd/SwqJaay+kmGNq8b4A8DTYr1SFqE=
644644
github.com/philips-labs/siderite v0.7.0/go.mod h1:vELGuq6uWTRqLci6Z22kjdn+b12eJPtss+tV6/PIlSk=
645-
github.com/philips-software/go-hsdp-api v0.38.0 h1:rubuy15X8cXcmz8J1wkQFPsgh4ziwULjUXmZnsZuq44=
646-
github.com/philips-software/go-hsdp-api v0.38.0/go.mod h1:vzZX4kCmgVwuJcAmd75Yeh/tNu1dNnBRbyau7CFWsuQ=
645+
github.com/philips-software/go-hsdp-api v0.38.1 h1:lieY98eUNu6QbEpq9LtozFfLr0P1bAVYzOnIX2loqj4=
646+
github.com/philips-software/go-hsdp-api v0.38.1/go.mod h1:vzZX4kCmgVwuJcAmd75Yeh/tNu1dNnBRbyau7CFWsuQ=
647647
github.com/philips-software/go-hsdp-signer v1.3.0 h1:Si1voDE/GHzthmxpasPdntbu8aUW6EYJfI6gHVf7BCc=
648648
github.com/philips-software/go-hsdp-signer v1.3.0/go.mod h1:/QehZ/+Aks2t1TFpjhF/7ZSB8PJIIJHzLc03rOqwLw0=
649649
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=

0 commit comments

Comments
 (0)