Skip to content

Commit

Permalink
Refs #10755 - Use recurring logic middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Oct 19, 2015
1 parent 4497463 commit 2ec2fb6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app/helpers/remote_execution_helper.rb
Expand Up @@ -87,15 +87,16 @@ def remote_execution_provider_for(task)
end

def job_invocation_task_buttons(task)
job_invocation = task.task_groups.find { |group| group.class == JobInvocationTaskGroup }.job_invocation
buttons = []
buttons << link_to(_('Refresh'), {}, :class => 'btn btn-default', :title => _('Refresh this page'))
if authorized_for(:permission => :create_job_invocations)
buttons << link_to(_("Rerun"), rerun_job_invocation_path(:id => task.locks.where(:resource_type => 'JobInvocation').first.resource),
buttons << link_to(_("Rerun"), rerun_job_invocation_path(:id => job_invocation.id),
:class => "btn btn-default",
:title => _('Rerun the job'))
end
if authorized_for(:permission => :create_job_invocations)
buttons << link_to(_("Rerun failed"), rerun_job_invocation_path(:id => task.locks.where(:resource_type => 'JobInvocation').first.resource, :failed_only => 1),
buttons << link_to(_("Rerun failed"), rerun_job_invocation_path(:id => job_invocation.id, :failed_only => 1),
:class => "btn btn-default",
:title => _('Rerun on failed hosts'))
end
Expand Down
2 changes: 0 additions & 2 deletions app/lib/actions/remote_execution/run_host_job.rb
Expand Up @@ -2,8 +2,6 @@ module Actions
module RemoteExecution
class RunHostJob < Actions::EntryAction

middleware.use Actions::Middleware::InheritTaskGroups

def resource_locks
:link
end
Expand Down
8 changes: 4 additions & 4 deletions app/lib/actions/remote_execution/run_hosts_job.rb
Expand Up @@ -3,17 +3,17 @@ module RemoteExecution
class RunHostsJob < Actions::ActionWithSubPlans

middleware.use Actions::Middleware::BindJobInvocation
middleware.use Actions::Middleware::InheritTaskGroups
middleware.use Actions::Middleware::RecurringLogic

def delay(_delay_options, job_invocation, locked = false)
def delay(delay_options, job_invocation, locked = false)
task.add_missing_task_groups(job_invocation.task_group)
job_invocation.targeting.resolve_hosts! if job_invocation.targeting.static?
super job_invocation, locked
super delay_options, job_invocation, locked
end

def plan(job_invocation, locked = false, connection_options = {})
job_invocation.task_group.save! if job_invocation.task_group.try(:new_record?)
task.add_missing_task_groups(job_invocation.task_group)
task.add_missing_task_groups(job_invocation.task_group) if job_invocation.task_group
action_subject(job_invocation) unless locked
job_invocation.targeting.resolve_hosts! if job_invocation.targeting.dynamic? || !locked
input.update(:job_name => job_invocation.job_name)
Expand Down
2 changes: 1 addition & 1 deletion app/models/job_invocation_task_group.rb
@@ -1,5 +1,5 @@
class JobInvocationTaskGroup < ::ForemanTasks::TaskGroup

has_one :job_invocation
has_one :job_invocation, :foreign_key => :task_group_id

end
4 changes: 2 additions & 2 deletions test/functional/api/v2/job_invocations_controller_test.rb
Expand Up @@ -29,7 +29,7 @@ class JobInvocationsControllerTest < ActionController::TestCase

invocation = ActiveSupport::JSON.decode(@response.body)
assert_equal attrs[:job_name], invocation['job_name']
assert_response 200
assert_response 201
end

test "should create valid with template_id" do
Expand All @@ -38,7 +38,7 @@ class JobInvocationsControllerTest < ActionController::TestCase

invocation = ActiveSupport::JSON.decode(@response.body)
assert_equal attrs[:job_name], invocation['job_name']
assert_response 200
assert_response 201
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/actions/run_hosts_job_test.rb
Expand Up @@ -16,7 +16,7 @@ class RunHostsJobTest < ActiveSupport::TestCase
end

let(:host) { FactoryGirl.create(:host) }
let(:task) { OpenStruct.new(:id => '123').tap { |o| o.stubs(:add_missing_task_groups) } }
let(:task) { OpenStruct.new(:id => '123').tap { |o| o.stubs(:add_missing_task_groups); o.stubs(:task_groups).returns([]) } }
let(:action) do
action = create_action(Actions::RemoteExecution::RunHostsJob)
action.expects(:action_subject).with(job_invocation)
Expand Down

0 comments on commit 2ec2fb6

Please sign in to comment.