furniture-3d-system-Wu/furniture-3d-system/scripts/install-oa-board-sync-timer.sh
WuYongJie eaf11faea1 feat(oa-board): 出图进度页改为美术设计申请源数据视图
一行=一条流程实例,列=流程实例ID/编号/标题/状态/时间+128 个表单原字段(按全量填写率排序,与源库导出 xlsx 同口径)。新快照表 oa_art_flow_raw_snapshot(关键筛选列+fields_json 全字段清洗值)+ oa_art_flow_raw_meta 字段顺序;同步脚本入 timer 链;API /api/intake/oa-board/art-flow-raw。旧 SKU 维度视图从页面移除,后端服务与导出消费方保留。
2026-10-08 17:23:18 +08:00

69 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
BASE="${FURNITURE_PROD_BASE:-/opt/furniture-3d-system-prod}"
SERVICE_NAME="${OA_BOARD_SYNC_SERVICE_NAME:-furniture-oa-board-sync}"
APP_ROOT="$BASE/current/furniture-3d-system"
APP_ENV="$BASE/shared/.env"
HR_SYNC_ENV="$BASE/shared/employee-directory-sync.env"
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
TIMER_FILE="/etc/systemd/system/$SERVICE_NAME.timer"
SYNC_ON_BOOT_SEC="${OA_BOARD_SYNC_ON_BOOT_SEC:-2min}"
SYNC_INTERVAL="${OA_BOARD_SYNC_INTERVAL:-15min}"
if [ "$(id -u)" -ne 0 ]; then
echo "This installer must run as root." >&2
exit 1
fi
if [ ! -d "$APP_ROOT" ]; then
echo "Missing app root: $APP_ROOT" >&2
exit 1
fi
if [ ! -f "$APP_ENV" ]; then
echo "Missing app env: $APP_ENV" >&2
exit 1
fi
cat >"$SERVICE_FILE" <<EOF
[Unit]
Description=Furniture OA new product and brand planning board snapshot sync
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
WorkingDirectory=$APP_ROOT
Environment=NODE_ENV=production
EnvironmentFile=$APP_ENV
# Reuse the HR read-only credentials from the existing employee-directory sync.
# The leading '-' keeps the OA sync usable before that optional sync is installed.
EnvironmentFile=-$HR_SYNC_ENV
# Keep dependent snapshots and the todo scan after the OA refresh so each
# consumer uses the newest workflow state.
# The global switch remains off by default and skips the todo scan until it is explicitly enabled.
ExecStart=/bin/bash -lc 'set -euo pipefail; cd "$APP_ROOT"; ./node_modules/.bin/tsx scripts/sync-oa-board.ts --apply; ./node_modules/.bin/tsx scripts/sync-oa-brand-planning-board.ts --apply; ./node_modules/.bin/tsx scripts/sync-oa-video-flow-board.ts --apply; ./node_modules/.bin/tsx scripts/sync-oa-art-flow-raw.ts --apply; case "\${DINGTALK_TODO_ENABLED:-false}" in 1|true|TRUE|yes|YES|on|ON) ./node_modules/.bin/tsx scripts/sync-oa-board-todos.ts ;; *) echo "DingTalk OA todo dispatch is disabled; skipping." ;; esac'
StandardOutput=journal
StandardError=journal
EOF
cat >"$TIMER_FILE" <<EOF
[Unit]
Description=Refresh furniture OA and brand planning boards, then dispatch enabled overtime todos every 15 minutes
[Timer]
OnBootSec=$SYNC_ON_BOOT_SEC
OnUnitActiveSec=$SYNC_INTERVAL
Persistent=true
RandomizedDelaySec=30
Unit=$SERVICE_NAME.service
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable --now "$SERVICE_NAME.timer"
systemctl list-timers --all "$SERVICE_NAME.timer" --no-pager