diff --git a/app/concerns/agent_controller_concern.rb b/app/concerns/agent_controller_concern.rb index 4e6e7b53..b6640e9c 100644 --- a/app/concerns/agent_controller_concern.rb +++ b/app/concerns/agent_controller_concern.rb @@ -12,7 +12,7 @@ module AgentControllerConcern end def control_action - options['action'].presence || 'run' + options['action'] end def validate_control_action diff --git a/app/models/agents/scheduler_agent.rb b/app/models/agents/scheduler_agent.rb index 0b7de12a..85b10499 100644 --- a/app/models/agents/scheduler_agent.rb +++ b/app/models/agents/scheduler_agent.rb @@ -19,7 +19,7 @@ module Agents Set `action` to one of the action types below: - * `run`: This is the default. Target Agents are run at intervals. + * `run`: Target Agents are run at intervals, except for those disabled. * `disable`: Target Agents are disabled (if not) at intervals. diff --git a/spec/lib/huginn_scheduler_spec.rb b/spec/lib/huginn_scheduler_spec.rb index e5bbe1e9..04a691f5 100644 --- a/spec/lib/huginn_scheduler_spec.rb +++ b/spec/lib/huginn_scheduler_spec.rb @@ -86,11 +86,11 @@ describe Rufus::Scheduler do stub.any_instance_of(Agents::SchedulerAgent).second_precision_enabled { true } - @agent1 = Agents::SchedulerAgent.new(name: 'Scheduler 1', options: { schedule: '*/1 * * * * *' }).tap { |a| + @agent1 = Agents::SchedulerAgent.new(name: 'Scheduler 1', options: { action: 'run', schedule: '*/1 * * * * *' }).tap { |a| a.user = users(:bob) a.save! } - @agent2 = Agents::SchedulerAgent.new(name: 'Scheduler 2', options: { schedule: '*/1 * * * * *' }).tap { |a| + @agent2 = Agents::SchedulerAgent.new(name: 'Scheduler 2', options: { action: 'run', schedule: '*/1 * * * * *' }).tap { |a| a.user = users(:bob) a.save! } diff --git a/spec/models/agents/scheduler_agent_spec.rb b/spec/models/agents/scheduler_agent_spec.rb index c093170d..3a910a83 100644 --- a/spec/models/agents/scheduler_agent_spec.rb +++ b/spec/models/agents/scheduler_agent_spec.rb @@ -4,7 +4,10 @@ describe Agents::SchedulerAgent do let(:valid_params) { { name: 'Example', - options: { 'schedule' => '0 * * * *' }, + options: { + 'action' => 'run', + 'schedule' => '0 * * * *' + }, } } @@ -73,7 +76,10 @@ describe Agents::SchedulerAgent do agent.memory['scheduled_at'] = time # Currently agent.options[]= is not detected - agent.options = { 'schedule' => '*/5 * * * *' } + agent.options = { + 'action' => 'run', + 'schedule' => '*/5 * * * *' + } agent.save expect(agent.memory['scheduled_at']).to be_nil end diff --git a/spec/support/shared_examples/agent_controller_concern.rb b/spec/support/shared_examples/agent_controller_concern.rb index 18214cd7..fe63d654 100644 --- a/spec/support/shared_examples/agent_controller_concern.rb +++ b/spec/support/shared_examples/agent_controller_concern.rb @@ -10,12 +10,12 @@ shared_examples_for AgentControllerConcern do describe "validation" do it "should validate action" do - ['run', 'enable', 'disable', '', nil].each { |action| + ['run', 'enable', 'disable'].each { |action| agent.options['action'] = action expect(agent).to be_valid } - ['delete', 1, true].each { |action| + ['delete', '', nil, 1, true].each { |action| agent.options['action'] = action expect(agent).not_to be_valid } @@ -23,18 +23,6 @@ shared_examples_for AgentControllerConcern do end describe 'control_action' do - it "should be one of the supported values" do - ['run', '', nil].each { |action| - agent.options['action'] = action - expect(agent.control_action).to eq('run') - } - - ['enable', 'disable'].each { |action| - agent.options['action'] = action - expect(agent.control_action).to eq(action) - } - end - it "cannot be 'run' if any of the control targets cannot be scheduled" do expect(agent.control_action).to eq('run') agent.control_targets = [agents(:bob_rain_notifier_agent)]