From 539ecdea46a80441185abdf361df01d1734e13db Mon Sep 17 00:00:00 2001 From: exu Date: Tue, 12 Nov 2024 17:01:55 +0100 Subject: [PATCH] Add async task for doom emacs sync --- roles/config/tasks/async.yml | 15 +++++++++++++++ roles/config/tasks/async_check.yml | 13 +++++++++++++ roles/config/tasks/main.yml | 24 ++++++++++++------------ 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 roles/config/tasks/async.yml create mode 100644 roles/config/tasks/async_check.yml diff --git a/roles/config/tasks/async.yml b/roles/config/tasks/async.yml new file mode 100644 index 00000000..80a12988 --- /dev/null +++ b/roles/config/tasks/async.yml @@ -0,0 +1,15 @@ +--- +- name: Doom Emacs | Check if installed + ansible.builtin.stat: + path: "~/.config/emacs/bin/doom" + register: doom_emacs + tags: config + +- name: Doom Emacs | Update if present - aync + ansible.builtin.shell: + cmd: "~/.config/emacs/bin/doom sync" + when: doom_emacs.stat.exists + async: 600 + poll: 0 + register: async_doom_emacs + tags: config diff --git a/roles/config/tasks/async_check.yml b/roles/config/tasks/async_check.yml new file mode 100644 index 00000000..888bc180 --- /dev/null +++ b/roles/config/tasks/async_check.yml @@ -0,0 +1,13 @@ +--- +- name: Doom Emacs | Check on async job + async_status: + jid: "{{ async_doom_emacs.ansible_job_id }}" + register: job_result + until: job_result.finished + retries: 60 + delay: 10 + +- name: Doom Emacs | Cleanup async job + async_status: + jid: "{{ async_doom_emacs.ansible_job_id }}" + mode: cleanup diff --git a/roles/config/tasks/main.yml b/roles/config/tasks/main.yml index b9f47fe0..fcb9b03d 100644 --- a/roles/config/tasks/main.yml +++ b/roles/config/tasks/main.yml @@ -112,6 +112,12 @@ mode: "0755" tags: config +# Start async tasks early +- name: Import Tasks from async.yml + ansible.builtin.import_tasks: + file: async.yml + tags: config + - name: Reload system systemd services ansible.builtin.systemd_service: daemon_reload: true @@ -303,19 +309,13 @@ cmd: "update-desktop-database ~/.local/share/applications/" tags: config -- name: Doom Emacs | Check if installed - ansible.builtin.stat: - path: "~/.config/emacs/bin/doom" - register: doom_emacs - tags: config - -- name: Doom Emacs | Update if present - ansible.builtin.shell: - cmd: "~/.config/emacs/bin/doom sync" - when: doom_emacs.stat.exists - tags: config - - name: Import Tasks from plasma.yml ansible.builtin.import_tasks: file: plasma.yml tags: config + +# Async task callbacks +- name: Import Tasks from async_check.yml + ansible.builtin.import_tasks: + file: async_check.yml + tags: config