Add job.executionType context variable #1835

Merged
merged 7 commits into from Nov 30, 2016

Projects

None yet

2 participants

@ctrlrsf
Contributor
ctrlrsf commented Apr 29, 2016

Currently there's no way to differentiate whether a job was ran by a user
and a job ran by the scheduler by looking at the job context variables.

With this change, we'll have a job.executionType context variable that will
indicate what invoked the job.

Possible values of job.executionType:
adhoc = adhoc command
user = job initiated by a user
scheduled = job triggered by the scheduler

This is a first stab at this problem to get the ball rolling.

Please review for correctness and let me know if anything
else is needed.

Addresses issue #1811

Signed-off-by: Rene Fragoso ctrlrsf@gmail.com

@ctrlrsf ctrlrsf Add job.executionType context variable
Currently there's no way to differentiate whether a job was ran by a user
and a job ran by the scheduler by looking at the job context variables.

With this change, we'll have a job.executionType context variable that will
indicate what invoked the job.

Possible values of job.executionType:
  adhoc = adhoc command
  user = job initiated by a user
  scheduled = job triggered by the scheduler

This is a first stab at this problem to get the ball rolling.

Please review for correctness and let me know if anything
else is needed.

Addresses issue rundeck#1811

Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
b8850c6
@gschueler gschueler added this to the 2.7.0 milestone Apr 29, 2016
@gschueler
Contributor

thanks, looks like a good start! setting the execution.executionType in ExecutionJob.groovy may need to be changed, ideally it should be set when the Execution is created, just so there is no need to do another .save() to the db. I think it will be easy, the executions are created by ExecutionJob for scheduled jobs only, for all other cases, the executions are created ahead of time, and so it should be easy to tell what value to use when.

ctrlrsf added some commits May 2, 2016
@ctrlrsf ctrlrsf Whitespace fix
Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
a1fbb01
@ctrlrsf ctrlrsf Don't set executionType explicitly from ExecutionJob
Feedback from PR suggested that executionType be set at
time that Execution object is created.

Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
0977965
@ctrlrsf ctrlrsf Set executionType when Execution is first created
With this change we set executionType to "user" when it is first
created. If we're creating a scheduled execution, set executionType
to "scheduled".

Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
5762d0c
@ctrlrsf
Contributor
ctrlrsf commented May 6, 2016

Hi @gschueler. I've updated my PR to set the executionType when Execution is created. Can you confirm it's on the right track? Thanks!

@gschueler
Contributor

@ctrlrsf looks good so far. the other place that createExecution is called is when an execution is retried here: https://github.com/rundeck/rundeck/blob/development/rundeckapp/grails-app/services/rundeck/services/ExecutionService.groovy#L1595

however, retried executions are already marked as retried from previous executions, so not sure if executionType is necessary to set

@ctrlrsf ctrlrsf Pass through executionType parameter if job is retried
If a job is retried, a new Execution is created. We need to pass through
the executionType parameter of the previous Execution object.

Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
ebfa83d
@ctrlrsf
Contributor
ctrlrsf commented May 9, 2016

@gschueler thanks for the additional comments. I updated PR to pass through the executionType when a job is retried.

@gschueler
Contributor

@ctrlrsf great, the only other thing I would request is if you could add some unit tests, but otherwise i think it looks good

ctrlrsf added some commits May 13, 2016
@ctrlrsf ctrlrsf Set executionType to "user" when Run Now button is used to run job
With this change we're defaulting the Execution.executionType variable
to "scheduled" whenever an Execution object is created.

If a job is ran by a user from the web UI using the Run Now button,
Execution.executionType will be set to "user" instead.

Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
ad4249f
@ctrlrsf ctrlrsf Add tests for Execution.executionType property
- Modifies testCreateExecutionSimple to confirm default "scheduled"
  executionType is set
- Adds testCreateExecutionSimpleUserExecutionType to confirm
  Execution can be created with executionType set to "user"

Signed-off-by: Rene Fragoso <ctrlrsf@gmail.com>
44ffebf
@ctrlrsf
Contributor
ctrlrsf commented May 13, 2016

@gschueler I've added two tests to confirm executionType is being set properly.

I also modified the code to be more straight forward. Now executionType is set to "scheduled" by default when an Execution object is created.

When a user runs a job from the web using Run Now button, ScheduledExecutionController.runJob() function will set an executionType input option to "user", which will eventually get passed as the executionType property when Execution object is later created.

Let me know if you have any further comments.

@gschueler gschueler changed the base branch to rundeck:master from rundeck:development Nov 11, 2016
@gschueler gschueler referenced this pull request Nov 30, 2016
Merged

Add executionType #2210

@gschueler gschueler merged commit 44ffebf into rundeck:master Nov 30, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment