add possibility to update models

This commit is contained in:
meaz 2023-12-05 21:58:20 +01:00
parent e16d9f9471
commit bdb1870954
Signed by: meaz
GPG key ID: CD7A47B2F1ED43B4
2 changed files with 53 additions and 0 deletions

View file

@ -12,3 +12,7 @@
- name: Deploy systemd
include_tasks: systemd.yml
tags: systemd
- name: Update language models
include_tasks: models.yml
tags: models

49
tasks/models.yml Normal file
View file

@ -0,0 +1,49 @@
---
- name: "[SYSTEMD] - Stop systemd"
service:
name: libretranslate
state: stopped
tags: models
- name: "[MODELS] - Update models"
shell: ". /etc/profile.d/libretranslate.sh && {{ libretranslate_venv_path }}/bin/python3 {{ libretranslate_venv_path }}/bin/libretranslate --update-models --host {{ libretranslate_host }} > {{ libretranslate_venv_path }}/update_models.log"
args:
chdir: "{{ libretranslate_venv_path }}"
become: yes
become_user: '{{ libretranslate_user }}'
async: 300
poll: 0
register: updating_models
tags: models
- name: "[MODELS] - Wait for the 'Running on' message that we get when updating models is done"
command: "grep 'Running on' {{ libretranslate_venv_path }}/update_models.log"
register: grep_running
until: "'Running on' in grep_running.stdout"
retries: 20 # it means retry 20 times.
delay: 10 # it means retry every 10 seconds
ignore_errors: true
tags: models
- name: Handle result
debug:
msg: "{{ updating_models.ansible_job_id }}"
tags: models
- name: Find the process ID (PID) of the asynchronous task
command: pgrep -f "libretranslate"
register: pid_result
ignore_errors: true
tags: models
- name: Kill the process if it is still running
command: "kill -9 {{ pid_result.stdout }}"
when: pid_result.rc == 0
tags: models
- name: "[SYSTEMD] - Start systemd"
service:
name: libretranslate
state: started
tags: models