Cancel button on jobs & pipeline instances should cancel all child jobs too
Extend the Job#cancel method to accept a "cascade: true" parameter.
Extend the jobs.cancel API to accept a "cascade=true" parameter.
Add a PipelineInstance#cancel method that accepts a "cascade: true" parameter (change to state=Paused if state is RunningOnServer or RunningOnClient; no-op if state is Paused; otherwise fail).
Add a pipeline_instances.cancel API that accepts a "cascade: true" parameter.
Update workbench to use the cascade=true flag when calling the jobs.cancel API.
Add a confirmation dialog which includes text warning that all unfinished child jobs will be canceled as well, even if they're also being used in another job/pipeline.
Update Workbench to use the pipeline_instances.cancel API with cascade=true, instead of updating state to Paused. Add a confirmation dialog as with jobs.
In the model methods, if cascade: true is given, cancel any jobs listed in the pipeline instance's / job's components hash (subject to permissions), and propagate the
cascade:true flag so an arbitrary number of generations of descendants can be cancelled.
Ensure the code cannot fall into an infinite loop or recursion (for example, make a test case where job A has job B in its components hash, and job B has job A in its components hash).
This is crunch1 only. Crunch2 already takes care of this.
#7 Updated by Radhika Chippada about 3 years ago
Branch 10903-api-cancel-cascade @ 3f833687 addresses the API server updates: (1) enhance job.cancel method to support cascade parameter, (2) add cancel method with cascade to pipeline_instance.
#8 Updated by Radhika Chippada about 3 years ago
Tom: branch 10903-wb-cancel-cascade @ 210af1cc7ede88914026fde078e45ef84c187a0c has both API and workbench updates. Please review this branch if you prefer to review both together.
One question: Let's say I have a job with job and pipeline components and I cancel it in workbench. Now I see that the main job and the child job are "cancelled", but the pipeline status is shown as "paused". If I were to navigate to that child pipeline, I would be able to click on it's resume button. Just wondering if this might be confusing from UI perspective.
API and workbench tests passed @ https://ci.curoverse.com/job/developer-run-tests/161/
#9 Updated by Tom Clegg about 3 years ago
10903-api-cancel-cascade @ 3f83368
I think this needs to be protected by a transaction. Suggest new signature for cancel method:
def cancel(cascade: false, need_transaction: true) if need_transaction ActiveRecord::Base.transaction do cancel(cascade: cascade, need_transaction: false) end return end # ...
(ruby2 has native named params, so we should be using those instead of positional params...)
Can do more filtering in the database in these sections:
- Job.where(uuid: children).each do |job| - job.cancel cascade if job.state.in?([Queued, Running]) + Job.where(uuid: children, state: [Queued, Running]).each do |job| + job.cancel(cascade: cascade, need_transaction: false) end
#10 Updated by Radhika Chippada about 3 years ago
Branch 10903-wb-cancel-cascade at 2e9cb97 addresses the suggestions from note 9 (need_transaction added).