Skip to content

Commit

Permalink
Remake cancelled operations when continuing a process. Just another try.
Browse files Browse the repository at this point in the history
  • Loading branch information
emrojo committed Sep 22, 2019
1 parent 70d9e8e commit c46bc05
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
4 changes: 0 additions & 4 deletions app/javascript/packs/activity_pack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Run this example by adding <%= javascript_pack_tag 'activity' %> to the head of your layout file,
// like app/views/layouts/application.html.erb. All it does is render <div>Hello React</div> at the bottom
// of the page.

import React from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
Expand Down
6 changes: 0 additions & 6 deletions app/javascript/packs/hello_erb.js.erb

This file was deleted.

26 changes: 0 additions & 26 deletions app/javascript/packs/hello_react.jsx

This file was deleted.

12 changes: 12 additions & 0 deletions app/models/steps/cancellable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def cancel_me
save_job(delay(queue: 'steps')._cancel_me)
end

def remake_me
save_job(delay(queue: 'steps')._remake_me)
end

def cancellable?
true
end
Expand All @@ -39,6 +43,14 @@ def _cancel_me
end
end

def _remake_me
ActiveRecord::Base.transaction do
fact_changes_for_option(:remake).apply(self, false)
operations.update_all(cancelled?: false)
end
end


def _cancel_me_and_any_newer_completed_steps(change_state=true)
changes = [
fact_changes_for_option(:cancel),
Expand Down
12 changes: 9 additions & 3 deletions app/models/steps/task.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
require 'inference_engines/runner/step_execution'
module Steps::Task
def process
step_execution = StepExecution.new(step: self, asset_group: asset_group)
updates = step_execution.plan
return stop! unless apply_changes(updates)
if operations.count > 0
remake_me
updates = FactChanges.new
else
step_execution = StepExecution.new(step: self, asset_group: asset_group)
updates = step_execution.plan
return stop! unless apply_changes(updates)
end

assets_for_printing = updates.assets_for_printing

unless step_type.step_action.nil? || step_type.step_action.empty?
Expand Down
9 changes: 9 additions & 0 deletions spec/models/steps/cancellable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
end
end

context '#remake_me' do
it 'remakes cancelled operations' do
@steps[0].operations.first.update(cancelled?: true)
@steps[0].remake_me
@steps[0].operations.reload
expect(@steps[0].operations.all?(&:cancelled?)).to eq(false)
end
end

it 'cancels all the operations of the step when cancelling the step' do
expect(@steps[0].operations.any?(&:cancelled?)).to eq(false)
@steps[0].cancel
Expand Down
8 changes: 8 additions & 0 deletions spec/models/steps/stoppable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,20 @@
context 'when the step was stopped before' do
let(:previous_state) { Step::STATE_STOPPED }
before do
asset = create :asset
step.operations << create(:operation, action_type: 'create_assets', object: asset.uuid, :cancelled? => false)

do_action
end

it 'continues this step' do
expect(step.complete?).to eq(true)
end
it 'performs remaking of the operations for this step' do
step.operations.reload

expect(step.operations.all?(&:cancelled?)).to eq(false)
end
it 'continues with any other stopped steps after this step' do
expect(next_steps_stopped.all?(&:complete?)).to eq(true)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/models/steps/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ def create_instance(step_type, activity, group)
}.to change{Asset.all.count}.by(2).and change{Fact.count}
end
end
context 'when it has cancelled operations from previous failed executions' do
let(:step) { create_instance(step_type, activity, group) }
before do
step.operations << create(:operation, action_type: 'add_facts', asset: asset, predicate: 'a', object: 'tube', cancelled?: true)
end
it 'does not run the default step execution' do
allow(InferenceEngines::Default::StepExecution).to receive(:new)
step.run!
expect(InferenceEngines::Default::StepExecution).not_to have_received(:new)
end
it 'remakes the operations' do
expect(step).to receive(:remake_me)
step.run!
end
end
context 'when the step works fine but the step action fails' do
let(:failable_execution) {
execution = double('step_execution')
Expand Down

0 comments on commit c46bc05

Please sign in to comment.