8000 Add timeout to dock commands by Regrau · Pull Request #50 · geerlingguy/ansible-collection-mac · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Conversation

Regrau
Copy link
Contributor
@Regrau Regrau commented Jul 22, 2022

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

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.
@@ -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"
Copy link
Owner

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

Copy link
Contributor Author
@Regrau Regrau Jul 22, 2022

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.

Copy link
Owner

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.

@Regrau Regrau force-pushed the Introduce-timeout-between-dock-item-removals branch from eb5fa36 to 995b85b Compare July 22, 2022 22:15
@@ -12,5 +12,12 @@
- name: Ensure Dock item {{ item }} is removed.
ansible.builtin.command:
cmd: dockutil --remove '{{ item }}'
register: dockitem_removed
Copy link
Owner

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?

Copy link
Contributor Author

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

@geerlingguy geerlingguy merged commit 1e0888b into geerlingguy:master Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race-condition between dockutil screen update and next command
2 participants
0