Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #30870 - Option to delete paused task. #407

Merged
merged 8 commits into from Jan 8, 2021

Conversation

patilsuraj767
Copy link
Contributor

No description provided.

@theforeman-bot
Copy link
Member

Issues: #30870

Copy link
Contributor

@upadhyeammit upadhyeammit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality wise it works as expected. Code wise I am requesting Kavita for more views.

definitions/procedures/foreman_tasks/resume.rb Outdated Show resolved Hide resolved
definitions/procedures/foreman_tasks/resume.rb Outdated Show resolved Hide resolved
@upadhyeammit
Copy link
Contributor

@kgaikwad request to review as changes are in core.

Copy link
Member

@kgaikwad kgaikwad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few inline comments.

lib/foreman_maintain/runner.rb Show resolved Hide resolved
@@ -8,6 +8,8 @@ class Resume < ForemanMaintain::Procedure

def run
output << feature(:foreman_tasks).resume_task_using_hammer
puts '[ Waiting 30 seconds for resumed tasks to start. ]'
sleep 30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be good to define constant at either procedure level or feature level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do that.

@@ -176,6 +178,10 @@ def old_tasks_condition(state = "'stopped', 'paused'")
"foreman_tasks_tasks.started_at < CURRENT_DATE - INTERVAL '#{MIN_AGE} days'"
end

def paused_tasks_condition(state = "'paused'")
"foreman_tasks_tasks.state IN (#{state})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you have taken state of tasks into consideration.
not_paused check calls feature(:foreman_tasks).paused_tasks_count(ignored_tasks) to find specific paused tasks.
I think, deleting only such paused tasks where result=error and not having label from ignored_tasks is expected here. Could you confirm this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgaikwad Yes it is expected that we should not delete ignored_tasks
These tasks are meant to be running always.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgaikwad @patilsuraj767 Currently we delete tasks where result=error, what about the tasks where result is pending or delayed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jameerpathan111 There is another check in foreman-maintain. Check not_running task which is run after the check not_paused in upgrade workflow, it will take care of running/pending tasks.

@kgaikwad
Copy link
Member

kgaikwad commented Oct 9, 2020

@patilsuraj767, @upadhyeammit
As I mentioned, changes were added to the core functionality which will change behaviour for all checks so it would be good to confirm this behaviour.

@jameerpathan111
Copy link
Contributor

jameerpathan111 commented Nov 4, 2020

@patilsuraj767 I have tried this pr and it looks good to me:

Test steps:

  • have tasks with state=paused and result=error
  • foreman-maintain health check --label foreman-tasks-not-paused --assumeyes

Observation:

  • foreman-tasks-not-paused check offers new option i.e "Delete paused tasks"
  • When check is run with --assumeyes option it will first try to resume paused tasks(state=paused and result=error) and if it fails to do so it deletes them.

Workaround for creating paused tasks:

[root@dhcp-2-22 ~]# foreman-rake console
Loading production environment (Rails 5.2.1)          
irb(main):018:0> t = ForemanTasks::Task.where(id: ["1575bec3-c4be-44bb-8920-22fab7a917ba"]).first
=> #<ForemanTasks::Task::DynflowTask id: "12481c54-65f2-4fa5-9e98-38f0e4b158dd", type: "ForemanTasks::Task::DynflowTask", label: "Actions::Katello::ContentView::Publish", started_at: "2020-10-28 06:36:00", ended_at: "2020-10-28 06:36:05", state: "stopped", result: "success", external_id: "9ad9ff45-7558-49b9-8e84-d486c78abc2b", parent_task_id: nil, start_at: "2020-10-28 06:36:00", start_before: nil, action: "Publish content view 'dev'; organization 'Default ...", user_id: 4, state_updated_at: "2020-10-28 06:36:05">
irb(main):019:0> t.result = "error"
=> "error"
irb(main):020:0> t.state = "paused"
=> "paused"
irb(main):021:0> t.save(:validate => false)
=> true

FM command output:

--------------------------------------------------------------------------------
Check for paused tasks:                                               [FAIL]
There are currently 2 paused tasks in the system
--------------------------------------------------------------------------------
There are multiple steps to proceed:
1) Resume paused tasks
2) Delete paused tasks
3) Investigate the tasks via UI
(assuming option 1)
Resume paused tasks:                                                            
[ Waiting 30 seconds for resumed tasks to start. ]                    [OK]
Total tasks found paused in error state: 2
Total tasks resumed:                     0
Resumed tasks:                           

Total tasks failed to resume:            0
Failed tasks:                            

Total tasks skipped:                     2
Skipped tasks:                           
 1) Task identifier: 1575bec3-c4be-44bb-8920-22fab7a917ba
    Task action:     Publish
    Task errors:     Required lock is already taken by other running tasks.
    Please inspect their state, fix their errors and resume them.
    
    Required lock: read
    Conflicts with tasks:
    - https://satellite.example.com/foreman_tasks/tasks/89b39a65-ba0d-45aa-af4e-ad8201f2ad48
 2) Task identifier: 8cd065ba-9d99-4436-aa97-b788919dbe83
    Task action:     Publish
    Task errors:     Required lock is already taken by other running tasks.
    Please inspect their state, fix their errors and resume them.
    
    Required lock: read
    Conflicts with tasks:
    - https://satellite.example.com/foreman_tasks/tasks/89b39a65-ba0d-45aa-af4e-ad8201f2ad48
--------------------------------------------------------------------------------
Rerunning the check after fix procedure
Check for paused tasks:                                               [FAIL]
There are currently 2 paused tasks in the system
--------------------------------------------------------------------------------
There are multiple steps to proceed:
1) Resume paused tasks
2) Delete paused tasks
3) Investigate the tasks via UI
(assuming option 2)
Delete tasks:                                                                   
| Deleted paused stopped and paused tasks: 2                          [OK]      
--------------------------------------------------------------------------------
Rerunning the check after fix procedure
Check for paused tasks:                                               [OK]

@jameerpathan111
Copy link
Contributor

There was an issue I faced while trying this pr on 6.9. I am still looking into it, so for sometime would request to hold this pr from getting merged.

@upadhyeammit
Copy link
Contributor

@jameerpathan111 do you have any thoughts on latest changes ?

@@ -12,9 +12,17 @@ def run
paused_tasks_count = feature(:foreman_tasks).paused_tasks_count(ignored_tasks)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@upadhyeammit According to me we should also remove ignored_tasks parameter from here. Because even though we can ignore these tasks they should not be in the Paused state ever, especially while satellite upgrade.
Let me know your thoughts on above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, however I have these thoughts,

  • This check is tagged as default which means it runs for health checks and at the time of upgrade checks and runs. So should we only skip ignored_task when we will actually do the upgrade check and upgrade run ?
  • We do this check after restarting the services and as per my limited knowledge if we restart all services these ignored tasks should not be in paused state ? So here if we delete those while doing the health check they wont be created again ? Because after deletion we are not restarting services ? However at the time of upgrade, at very end of scenario we start the services.

What you think @patilsuraj767 and @kgaikwad ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates on above query:

Currently, this check is tagged as default so it is running as part of health as well as upgrade.
As per offline discussion with @upadhyeammit & @patilsuraj767, it is worth verifying few things before any solution:

  • What will be the impact when it deletes paused tasks including labels "Actions::Candlepin::ListenOnCandlepinEvents", "Actions::Katello::EventQueue::Monitor" because currently it is ignoring paused tasks with those labels?
  • Would it be safe to run this deletion procedure when it won't perform service restart?
    Example - foreman-maintain health check command.
  • Do we really need this check as part of health command? Other tasks related checks are tagged as "pre-upgrade"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* What will be the impact when it deletes paused tasks including labels "Actions::Candlepin::ListenOnCandlepinEvents", "Actions::Katello::EventQueue::Monitor" because currently it is ignoring paused tasks with those labels?

delete all of these, these tasks were removed from Foreman Tasks in 6.7 and are no longer processed as a task. Definitely delete them..

* Would it be safe to run this deletion procedure when it won't perform service restart?
  Example - foreman-maintain health check command.

yes, any time you delete a paused task, you do not need to restart services.

* Do we really need this check as part of health command? Other tasks related checks are tagged as "pre-upgrade"

I'd keep this with the health check as it is now as well as during the upgrade.

@upadhyeammit
Copy link
Contributor

@patilsuraj767 request to do necessary changes, thank you !

@upadhyeammit
Copy link
Contributor

@kgaikwad any final thoughts before merging ?

@upadhyeammit
Copy link
Contributor

I tested this and what I can see is we are printing sort of confusing message as below. I think we should only keep 'Deleted paused tasks' as message ? its coming from Procedures::ForemanTasks::Delete procedure.

There are multiple steps to proceed:
1) Resume paused tasks
2) Delete paused tasks
3) Investigate the tasks via UI
Select step to continue, [n(next)] 2
Delete tasks:                                                                   
\ Deleted paused stopped and paused tasks: 1                          [OK]      
--------------------------------------------------------------------------------
Rerunning the check after fix procedure
Check for paused tasks:                                               [OK]
--------------------------------------------------------------------------------
Check to verify no empty CA cert requests exist:                      [OK]
--------------------------------------------------------------------------------
Check whether system is self-registered or not:                       [OK]
--------------------------------------------------------------------------------


def next_procedures
if assumeyes?
[Procedures::ForemanTasks::Resume.new,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explicitly return the array inside if block ? now even when we have assumeyes? true it returns three next steps.

@upadhyeammit upadhyeammit merged commit 616c23c into theforeman:master Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants