From 6694e0682d644d074b4ab2e454e009af29bcbed0 Mon Sep 17 00:00:00 2001 From: igor04091968 Date: Mon, 27 Apr 2026 01:49:27 +0300 Subject: [PATCH] feat(worktime): add from/to worktime window --- ansible/deploy_aw_server.yml | 37 +++++++++++++++++++++++++++++- ansible/group_vars/all.example.yml | 7 ++++-- docs/runbook.md | 8 +++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ansible/deploy_aw_server.yml b/ansible/deploy_aw_server.yml index 2b75e61..bb558e3 100644 --- a/ansible/deploy_aw_server.yml +++ b/ansible/deploy_aw_server.yml @@ -163,6 +163,41 @@ status_code: 201 when: aw_apply_worktime_settings | default(false) | bool + - name: Derive worktime durationDefault from aw_worktime_from/to + ansible.builtin.set_fact: + aw_worktime_from_h: "{{ (aw_worktime_from | default('08:00')).split(':')[0] | int }}" + aw_worktime_from_m: "{{ (aw_worktime_from | default('08:00')).split(':')[1] | int }}" + aw_worktime_to_h: "{{ (aw_worktime_to | default('17:00')).split(':')[0] | int }}" + aw_worktime_to_m: "{{ (aw_worktime_to | default('17:00')).split(':')[1] | int }}" + aw_worktime_duration_default_derived: >- + {{ + ( + ( + ((aw_worktime_to_h | int) * 60 + (aw_worktime_to_m | int)) - + ((aw_worktime_from_h | int) * 60 + (aw_worktime_from_m | int)) + ) * 60 + ) + }} + when: aw_apply_worktime_settings | default(false) | bool + + - name: Normalize derived durationDefault for overnight shifts + ansible.builtin.set_fact: + aw_worktime_duration_default_effective: >- + {{ + (aw_worktime_duration_default_derived | int) + if (aw_worktime_duration_default_derived | int) > 0 + else ((aw_worktime_duration_default_derived | int) + 86400) + }} + when: aw_apply_worktime_settings | default(false) | bool + + - name: Validate derived durationDefault is sane + ansible.builtin.assert: + that: + - aw_worktime_duration_default_effective | int > 0 + - aw_worktime_duration_default_effective | int <= 86400 + fail_msg: "Invalid worktime window: {{ aw_worktime_from }}..{{ aw_worktime_to }}" + when: aw_apply_worktime_settings | default(false) | bool + - name: Apply baseline worktime period (startOfDay) ansible.builtin.uri: url: "http://127.0.0.1:{{ aw_server_port }}/api/0/settings/startOfDay" @@ -176,7 +211,7 @@ ansible.builtin.uri: url: "http://127.0.0.1:{{ aw_server_port }}/api/0/settings/durationDefault" method: POST - body: "{{ aw_worktime_duration_default }}" + body: "{{ aw_worktime_duration_default_effective }}" body_format: json status_code: 200 when: aw_apply_worktime_settings | default(false) | bool diff --git a/ansible/group_vars/all.example.yml b/ansible/group_vars/all.example.yml index 398109a..8a41775 100644 --- a/ansible/group_vars/all.example.yml +++ b/ansible/group_vars/all.example.yml @@ -17,5 +17,8 @@ aw_apply_worktime_settings: false # Optional defaults for the worktime period in Web UI. # startOfDay controls day-boundary and default report window start. # durationDefault controls default time range (seconds) shown in UI. -aw_worktime_start_of_day: "08:00" -aw_worktime_duration_default: 32400 +# +# Recommended: set worktime window explicitly and let the playbook derive duration. +aw_worktime_from: "08:00" +aw_worktime_to: "17:00" +aw_worktime_start_of_day: "{{ aw_worktime_from }}" diff --git a/docs/runbook.md b/docs/runbook.md index 44f75c8..c5525ad 100755 --- a/docs/runbook.md +++ b/docs/runbook.md @@ -40,6 +40,14 @@ ls -l /opt/activitywatch/webui-ru/js/ Контрольные AQL-шаблоны для расчета рабочего времени: `docs/worktime_aql_detmir.md`. +Период рабочего времени задаётся переменными: + +- `aw_worktime_from` (например `08:00`) +- `aw_worktime_to` (например `17:00`) + +Playbook вычисляет `durationDefault` автоматически (включая смены через полночь) и выставляет: +`/api/0/settings/startOfDay` и `/api/0/settings/durationDefault`. + ## Типовые инциденты ### Сервис не стартует