Skip to content

Commit 2c9b06e

Browse files
committed
fix job updating
This fixes the update logic for scheduled jobs.
1 parent 0905c14 commit 2c9b06e

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

update/application.go

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,32 @@ const BuildTrigger = "BUILD_TRIGGER"
2424
// the user.
2525
type applicationCmd struct {
2626
resourceCmd
27-
Git *gitConfig `embed:"" prefix:"git-"`
28-
Size *string `help:"Size of the app."`
29-
Port *int32 `help:"Port the app is listening on."`
30-
Replicas *int32 `help:"Amount of replicas of the running app."`
31-
Hosts *[]string `help:"Host names where the application can be accessed. If empty, the application will just be accessible on a generated host name on the deploio.app domain."`
32-
BasicAuth *bool `help:"Enable/Disable basic authentication for the application."`
33-
ChangeBasicAuthPassword *bool `help:"Generate a new basic auth password."`
34-
Env map[string]string `help:"Environment variables which are passed to the app at runtime."`
35-
DeleteEnv *[]string `help:"Runtime environment variables names which are to be deleted."`
36-
BuildEnv map[string]string `help:"Environment variables names which are passed to the app build process."`
37-
DeleteBuildEnv *[]string `help:"Build environment variables which are to be deleted."`
38-
DeployJob *deployJob `embed:"" prefix:"deploy-job-"`
39-
WorkerJob *workerJob `embed:"" prefix:"worker-job-"`
40-
ScheduledJob *scheduledJob `embed:"" prefix:"scheduled-job-"`
41-
DeleteWorkerJob *string `help:"Delete a worker job by name"`
42-
DeleteScheduledJob *string `help:"Delete a scheduled job by name"`
43-
RetryBuild *bool `help:"Retries build for the application if set to true." placeholder:"false"`
44-
GitInformationServiceURL string `help:"URL of the git information service." default:"https://git-info.deplo.io" env:"GIT_INFORMATION_SERVICE_URL" hidden:""`
45-
SkipRepoAccessCheck bool `help:"Skip the git repository access check" default:"false"`
46-
Debug bool `help:"Enable debug messages" default:"false"`
47-
Language *string `help:"${app_language_help} Possible values: ${enum}" enum:"ruby,php,python,golang,nodejs,static,"`
48-
DockerfileBuild dockerfileBuild `embed:""`
27+
Git *gitConfig `embed:"" prefix:"git-"`
28+
Size *string `help:"Size of the app."`
29+
Port *int32 `help:"Port the app is listening on."`
30+
Replicas *int32 `help:"Amount of replicas of the running app."`
31+
Hosts *[]string `help:"Host names where the application can be accessed. If empty, the application will just be accessible on a generated host name on the deploio.app domain."`
32+
BasicAuth *bool `help:"Enable/Disable basic authentication for the application."`
33+
ChangeBasicAuthPassword *bool `help:"Generate a new basic auth password."`
34+
Env map[string]string `help:"Environment variables which are passed to the app at runtime."`
35+
DeleteEnv *[]string `help:"Runtime environment variables names which are to be deleted."`
36+
BuildEnv map[string]string `help:"Environment variables names which are passed to the app build process."`
37+
DeleteBuildEnv *[]string `help:"Build environment variables which are to be deleted."`
38+
// DeployJob, ScheduledJob and WorkerJob are embedded pointers to
39+
// structs. Due to the usage of kong these pointers will never be `nil`.
40+
// So checking for `nil` values can not be used to find out if some of
41+
// the struct fields have been set.
42+
DeployJob *deployJob `embed:"" prefix:"deploy-job-"`
43+
WorkerJob *workerJob `embed:"" prefix:"worker-job-"`
44+
ScheduledJob *scheduledJob `embed:"" prefix:"scheduled-job-"`
45+
DeleteWorkerJob *string `help:"Delete a worker job by name"`
46+
DeleteScheduledJob *string `help:"Delete a scheduled job by name"`
47+
RetryBuild *bool `help:"Retries build for the application if set to true." placeholder:"false"`
48+
GitInformationServiceURL string `help:"URL of the git information service." default:"https://git-info.deplo.io" env:"GIT_INFORMATION_SERVICE_URL" hidden:""`
49+
SkipRepoAccessCheck bool `help:"Skip the git repository access check" default:"false"`
50+
Debug bool `help:"Enable debug messages" default:"false"`
51+
Language *string `help:"${app_language_help} Possible values: ${enum}" enum:"ruby,php,python,golang,nodejs,static,"`
52+
DockerfileBuild dockerfileBuild `embed:""`
4953
}
5054

5155
type gitConfig struct {
@@ -93,13 +97,21 @@ type workerJob struct {
9397
Size *string `help:"Size of the worker (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
9498
}
9599

100+
func (wj workerJob) changesGiven() bool {
101+
return wj.Command != nil || wj.Size != nil
102+
}
103+
96104
type scheduledJob struct {
97105
Command *string `help:"Command to execute to start the scheduled job." placeholder:"\"bundle exec rails runner\""`
98106
Name *string `help:"Name of the scheduled job job to add." placeholder:"scheduled-1"`
99107
Size *string `help:"Size (resources) of the scheduled job (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
100108
Schedule *string `help:"Cron notation string for the scheduled job (defaults to \"* * * * *\")." placeholder:"* * * * *"`
101109
}
102110

111+
func (sj scheduledJob) changesGiven() bool {
112+
return sj.Command != nil || sj.Size != nil || sj.Schedule != nil
113+
}
114+
103115
type dockerfileBuild struct {
104116
Path *string `name:"dockerfile-path" help:"${app_dockerfile_path_help}" placeholder:"."`
105117
BuildContext *string `name:"dockerfile-build-context" help:"${app_dockerfile_build_context_help}" placeholder:"."`
@@ -228,13 +240,13 @@ func (cmd *applicationCmd) applyUpdates(app *apps.Application) {
228240
if cmd.DeployJob != nil {
229241
cmd.DeployJob.applyUpdates(&app.Spec.ForProvider.Config)
230242
}
231-
if cmd.WorkerJob != nil {
243+
if cmd.WorkerJob != nil && cmd.WorkerJob.changesGiven() {
232244
cmd.WorkerJob.applyUpdates(&app.Spec.ForProvider.Config)
233245
}
234246
if cmd.DeleteWorkerJob != nil {
235247
deleteWorkerJob(*cmd.DeleteWorkerJob, &app.Spec.ForProvider.Config)
236248
}
237-
if cmd.ScheduledJob != nil {
249+
if cmd.ScheduledJob != nil && cmd.ScheduledJob.changesGiven() {
238250
cmd.ScheduledJob.applyUpdates(&app.Spec.ForProvider.Config)
239251
}
240252
if cmd.DeleteScheduledJob != nil {
@@ -306,10 +318,8 @@ func ensureDeployJob(cfg *apps.Config) *apps.Config {
306318
}
307319

308320
func (job workerJob) applyUpdates(cfg *apps.Config) {
309-
if (job.Command != nil || job.Size != nil) && job.Name == nil {
310-
format.PrintWarningf("you need to pass a job name to update the command or size\n")
311-
}
312321
if job.Name == nil {
322+
format.PrintWarningf("you need to pass a job name to update the command or size\n")
313323
return
314324
}
315325
for i := range cfg.WorkerJobs {

0 commit comments

Comments
 (0)