Skip to content

Commit

Permalink
Merge pull request #4 from sitewards/ADHOC-make-it-async
Browse files Browse the repository at this point in the history
ADHOC feat async-import: make things faster through parallel run
  • Loading branch information
aboritskiy authored Jun 4, 2021
2 parents d16cb8b + a1386eb commit 45cee89
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
10 changes: 10 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ import_db_post_import_sql_queries: []

## Tmp path to put downloaded files while preparing them for import
import_db_tmp_path: "/tmp/import_db"

## Allow async execution
## in case activated one *must* add a task like that to playbook
## - name: 'Import DB - check on async task'
# async_status:
# jid: "{{ import_db_sleeper.ansible_job_id }}"
# register: job_result
# until: job_result.finished
# retries: 30
import_db_allow_async: false
9 changes: 9 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: "Clean up tmp db files"
file:
path: "{{ item }}"
state: "absent"
with_items:
- "{{ import_db_tmp_path }}/db_dump.sql"
- "{{ import_db_tmp_path }}/db_dump.sql.gz"
- "{{ import_db_tmp_path }}"
24 changes: 15 additions & 9 deletions tasks/import.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@
login_user: "root"
when: "import_db_downloaded_archive.changed"

- name: "Restore the database"
- name: "Restore the database asyncronously"
mysql_db:
name: "{{ import_db_database_name }}"
state: "import"
target: "{{ import_db_tmp_path }}/db_dump.sql"
login_password: "{{ import_db_root_password }}"
login_user: "root"
async: 600
poll: 0
notify: "Clean up tmp db files"
register: import_db_sleeper
when: import_db_allow_async

- name: "Clean up the db from /tmp"
file:
path: "{{ item }}"
state: "absent"
with_items:
- "{{ import_db_tmp_path }}/db_dump.sql"
- "{{ import_db_tmp_path }}/db_dump.sql.gz"
- "{{ import_db_tmp_path }}"
- name: "Restore the database syncronously"
mysql_db:
name: "{{ import_db_database_name }}"
state: "import"
target: "{{ import_db_tmp_path }}/db_dump.sql"
login_password: "{{ import_db_root_password }}"
login_user: "root"
notify: "Clean up tmp db files"
when: not import_db_allow_async

0 comments on commit 45cee89

Please sign in to comment.