-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from iNecas/sub-plans-new
Fixes #9508 - use Dynflow sub-plans support for sub tasks and bulk actions
- Loading branch information
Showing
7 changed files
with
116 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Actions | ||
|
||
class Actions::ActionWithSubPlans < Actions::EntryAction | ||
|
||
middleware.use Actions::Middleware::KeepCurrentUser | ||
|
||
include Dynflow::Action::WithSubPlans | ||
|
||
def plan(*args) | ||
raise NotImplementedError | ||
end | ||
|
||
def humanized_output | ||
return unless counts_set? | ||
_("%{total} tasks, %{success} success, %{failed} fail") % | ||
{ total: output[:total_count], | ||
success: output[:success_count], | ||
failed: output[:failed_count] } | ||
end | ||
|
||
def run_progress | ||
if counts_set? && output[:total_count] > 0 | ||
(output[:success_count] + output[:failed_count]).to_f / output[:total_count] | ||
else | ||
0.1 | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "foreman_tasks_test_helper" | ||
|
||
module ForemanTasks | ||
class ActionWithSubPlansTest < ActiveSupport::TestCase | ||
self.use_transactional_fixtures = false | ||
|
||
before do | ||
User.current = User.where(:login => 'apiadmin').first | ||
end | ||
|
||
# to be able to use the locking | ||
class ::User < User.parent | ||
include ForemanTasks::Concerns::ActionSubject | ||
end | ||
|
||
class ParentAction < Actions::ActionWithSubPlans | ||
def plan(user) | ||
action_subject(user) | ||
plan_self(user_id: user.id) | ||
end | ||
|
||
def create_sub_plans | ||
user = User.find(input[:user_id]) | ||
trigger(ChildAction, user) | ||
end | ||
end | ||
|
||
class ChildAction < Actions::EntryAction | ||
def plan(user) | ||
action_subject(user) | ||
plan_self(user_id: user.id) | ||
end | ||
def run | ||
end | ||
end | ||
|
||
describe Actions::ActionWithSubPlans do | ||
let(:task) do | ||
user = FactoryGirl.create(:user) | ||
triggered = ForemanTasks.trigger(ParentAction, user) | ||
raise triggered.error if triggered.respond_to?(:error) | ||
triggered.finished.wait(2) | ||
ForemanTasks::Task.find_by_external_id(triggered.id) | ||
end | ||
|
||
specify "the sub-plan stores the information about its parent" do | ||
task.sub_tasks.size.must_equal 1 | ||
task.sub_tasks.first.label.must_equal ChildAction.name | ||
end | ||
|
||
specify "the locks of the sub-plan don't colide with the locks of its parent" do | ||
child_task = task.sub_tasks.first | ||
assert(child_task.locks.any? { |lock| lock.name == 'write' }, "it's locks don't conflict with parent's") | ||
end | ||
end | ||
|
||
end | ||
end |