-
-
Notifications
You must be signed in to change notification settings - Fork 116
Add timeout to dock commands #50
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
Add timeout to dock commands #50
Conversation
It seems that dockutil is to fast for the ui to keep up with the updates. Hence every playbook run removed/added only the first item in the dock. Through trial an error I came to the magic number of 7 seconds between each dockutil remove or add commands. With such a timeout it seems to work fine.
roles/dock/tasks/dock-add.yml
Outdated
@@ -9,6 +9,6 @@ | |||
tags: ['dock'] | |||
|
|||
- name: Ensure Dock item {{ item.name | default(item) }} exists. | |||
ansible.builtin.command: "dockutil --add '{{ item.path }}'" | |||
ansible.builtin.shell: "dockutil --add '{{ item.path }}' && sleep 7" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding sleep and using shell
, you could add a task like:
- name: Pause for 7 seconds between dock changes.
ansible.builtin.pause:
seconds: 7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip. But would that actually pause between each iteration of the loop? I looked into pause and assumed that such a task would be executed only once after the whole loop is done.
But now that you mentioned the pause. I looked it up again and stumbled on a, to me, much more elegant solution!
loop_control:
pause: 7
I'll test that and will report back with a new commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, if you can use loop_control with the include, that might be the best way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh now I see, it somehow didn't occur to me that we are looping over the whole file! Your change suggestion makes much more sense now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, if you can use loop_control with the include, that might be the best way.
Unfortunately that would have required the pause to always be executed. So I used the pause module like you suggested and made it conditional.
eb5fa36
to
995b85b
Compare
roles/dock/tasks/dock-remove.yml
Outdated
@@ -12,5 +12,12 @@ | |||
- name: Ensure Dock item {{ item }} is removed. | |||
ansible.builtin.command: | |||
cmd: dockutil --remove '{{ item }}' | |||
register: dockitem_removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this variable being used? Or was this meant to be used in the next pause task?
I see the linter failing on an unnamed task somewhere. Is that in a different part of the role?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable wasn't used. It was quite late and I was sure that I did remove both variables in the commit. It is gone now.
And yes it was supposed to be used in the next task. I did scrap that idea though.
As for the linter, I have no idea why it fails. I didn't touch the file it is complaining about in my commits.
It doesn't like this file and this part in it.
# roles/homebrew/tasks/main.yml:99 Task/Handler: block/always/rescue
- block:
- name: Force update brew after installation.
command: "{{ homebrew_brew_bin_path }}/brew update --force"
when: not homebrew_binary.stat.exists
Hi Jeff,
It seems that dockutil is too fast for the ui to keep up with the
updates. Hence every playbook run removed/added only the first item
in the dock item lists.
Through trial an error I came to the magic number of 7 seconds
between each dockutil remove or add commands. With such a timeout
it seems to work fine.
This will close #43