About recorder.purge in a script

i’m writing a simple script to clean the system after tests…

    - service: recorder.disable

    - service: recorder.purge
      data:
        keep_days: 0
        repack: true

    - service: recorder.enable

    - service: homeassistant.restart

the problem is that the system restarts before the repack is completed. any idea to wait for the purge/repack completed?!

thanks

added a wait_template to check the database size… makes the job