Skip to content

Commit

Permalink
ADHOC feat async-import: make things faster through parallel run
Browse files Browse the repository at this point in the history
if task is imported asyncronously - playbook can proceed with other
tasks, in the use cases here, I don't think we need to check back if
task has finished successfully, if this is a concern - don't allow async
execution

see:
* https://www.treitos.com/blog/2020/improving-ansible-performance.html
* https://docs.ansible.com/ansible/2.9/user_guide/playbooks_async.html
* https://docs.ansible.com/ansible/latest/user_guide/playbooks_handlers.html
  • Loading branch information
Anton Boritskiy committed Jun 9, 2021
1 parent 53b4748 commit 63445e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 10 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,13 @@ magento_force_reindex_on_deploy: False
# and more
# and more
# and more

# allows to run deletion of old clones folders asynchronously,
# this allows pipeline to finish faster due to "parallel" execution of tasks
# when clones are cleaned up asynchronously, role is not checking successful execution
magento_allow_async_cleanup_old_clones: false

# allows to run magento reindexing asynchronously,
# this allows pipeline to finish faster due to "parallel" execution of tasks
# when reindexing is done asynchronously, role is not checking successful execution
magento_allow_async_reindex: false
13 changes: 11 additions & 2 deletions tasks/cleanup-old-clones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@
age_stamp: "ctime"
register: magento_clones_for_cleanup

- name: "Remove old clones/releases"
- name: "Remove old clones/releases asynchronously"
file:
path: "{{ item.path }}"
state: absent
when: magento_cleanup_old_clones == True
when: magento_cleanup_old_clones and magento_allow_async_cleanup_old_clones
with_items: "{{ (magento_clones_for_cleanup.files | sort(attribute='ctime', reverse=True))[magento_clones_to_keep:] | list }}"
async: 600
poll: 0

- name: "Remove old clones/releases synchronously"
file:
path: "{{ item.path }}"
state: absent
when: magento_cleanup_old_clones and (not magento_allow_async_cleanup_old_clones)
with_items: "{{ (magento_clones_for_cleanup.files | sort(attribute='ctime', reverse=True))[magento_clones_to_keep:] | list }}"
12 changes: 10 additions & 2 deletions tasks/installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,19 @@
become_user: "{{ magento_user }}"
command: "/usr/bin/php {{ magento_app_root }}/bin/magento cache:flush"

- name: "Let Magento indexer run"
- name: "Let Magento indexer run asynchronously"
become: "yes"
become_user: "{{ magento_user }}"
command: "/usr/bin/php {{ magento_app_root }}/bin/magento indexer:reindex"
when: magento_db_status.stdout_lines|length == 0 or magento_force_reindex_on_deploy == True
when: (magento_db_status.stdout_lines|length == 0 or magento_force_reindex_on_deploy == True) and magento_allow_async_reindex
async: 600
poll: 0

- name: "Let Magento indexer run synchronously"
become: "yes"
become_user: "{{ magento_user }}"
command: "/usr/bin/php {{ magento_app_root }}/bin/magento indexer:reindex"
when: (magento_db_status.stdout_lines|length == 0 or magento_force_reindex_on_deploy == True) and (not magento_allow_async_reindex)

- name: "Disable maintenance mode"
file:
Expand Down

0 comments on commit 63445e5

Please sign in to comment.