Skip to content

Commit 821c6db

Browse files
committed
fix job updating
This fixes the update logic for scheduled jobs.
1 parent 3b48f1a commit 821c6db

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

update/application.go

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

5559
type gitConfig struct {
@@ -97,13 +101,21 @@ type workerJob struct {
97101
Size *string `help:"Size of the worker (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
98102
}
99103

104+
func (wj workerJob) changesGiven() bool {
105+
return wj.Command != nil || wj.Size != nil
106+
}
107+
100108
type scheduledJob struct {
101109
Command *string `help:"Command to execute to start the scheduled job." placeholder:"\"bundle exec rails runner\""`
102110
Name *string `help:"Name of the scheduled job job to add." placeholder:"scheduled-1"`
103111
Size *string `help:"Size (resources) of the scheduled job (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
104112
Schedule *string `help:"Cron notation string for the scheduled job (defaults to \"* * * * *\")." placeholder:"* * * * *"`
105113
}
106114

115+
func (sj scheduledJob) changesGiven() bool {
116+
return sj.Command != nil || sj.Size != nil || sj.Schedule != nil
117+
}
118+
107119
type dockerfileBuild struct {
108120
Path *string `name:"dockerfile-path" help:"${app_dockerfile_path_help}" placeholder:"."`
109121
BuildContext *string `name:"dockerfile-build-context" help:"${app_dockerfile_build_context_help}" placeholder:"."`
@@ -232,13 +244,13 @@ func (cmd *applicationCmd) applyUpdates(app *apps.Application) {
232244
if cmd.DeployJob != nil {
233245
cmd.DeployJob.applyUpdates(&app.Spec.ForProvider.Config)
234246
}
235-
if cmd.WorkerJob != nil {
247+
if cmd.WorkerJob != nil && cmd.WorkerJob.changesGiven() {
236248
cmd.WorkerJob.applyUpdates(&app.Spec.ForProvider.Config)
237249
}
238250
if cmd.DeleteWorkerJob != nil {
239251
deleteWorkerJob(*cmd.DeleteWorkerJob, &app.Spec.ForProvider.Config)
240252
}
241-
if cmd.ScheduledJob != nil {
253+
if cmd.ScheduledJob != nil && cmd.ScheduledJob.changesGiven() {
242254
cmd.ScheduledJob.applyUpdates(&app.Spec.ForProvider.Config)
243255
}
244256
if cmd.DeleteScheduledJob != nil {
@@ -319,10 +331,8 @@ func ensureDeployJob(cfg *apps.Config) *apps.Config {
319331
}
320332

321333
func (job workerJob) applyUpdates(cfg *apps.Config) {
322-
if (job.Command != nil || job.Size != nil) && job.Name == nil {
323-
format.PrintWarningf("you need to pass a job name to update the command or size\n")
324-
}
325334
if job.Name == nil {
335+
format.PrintWarningf("you need to pass a job name to update the command or size\n")
326336
return
327337
}
328338
for i := range cfg.WorkerJobs {

0 commit comments

Comments
 (0)