feat(pchome): automate authorized sales acquisition
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
This commit is contained in:
@@ -8,6 +8,7 @@ from flask import Blueprint, render_template, jsonify, request
|
||||
import logging
|
||||
from services.import_service import humanize_import_error, import_service
|
||||
from services.google_drive_service import drive_service
|
||||
from services.pchome_sales_acquisition_service import pchome_sales_acquisition_service
|
||||
|
||||
# 建立 Blueprint
|
||||
auto_import_bp = Blueprint('auto_import', __name__)
|
||||
@@ -193,9 +194,9 @@ def list_drive_files():
|
||||
|
||||
@auto_import_bp.route('/api/manual_import', methods=['POST'])
|
||||
def manual_import():
|
||||
"""手動觸發匯入"""
|
||||
"""Backward-compatible command endpoint for the automated acquisition run."""
|
||||
try:
|
||||
result = import_service.auto_import_from_drive()
|
||||
result = pchome_sales_acquisition_service.run(trigger='operator_command')
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
@@ -207,6 +208,33 @@ def manual_import():
|
||||
}), 500
|
||||
|
||||
|
||||
@auto_import_bp.route('/api/auto_import/readiness', methods=['GET'])
|
||||
def auto_import_readiness():
|
||||
"""Return public-safe provider, freshness, and runtime-closure state."""
|
||||
try:
|
||||
return jsonify(pchome_sales_acquisition_service.readiness())
|
||||
except Exception:
|
||||
logger.exception("取得業績來源自動化狀態失敗")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'message': '暫時無法取得業績來源自動化狀態。'
|
||||
}), 500
|
||||
|
||||
|
||||
@auto_import_bp.route('/api/auto_import/run', methods=['POST'])
|
||||
def run_auto_import():
|
||||
"""Run the governed acquisition, controlled apply, and verifier chain."""
|
||||
try:
|
||||
return jsonify(pchome_sales_acquisition_service.run(trigger='operator_command'))
|
||||
except Exception as e:
|
||||
logger.exception("執行業績來源自動化失敗")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'status': 'failed_rolled_back',
|
||||
'message': f'自動取得與匯入失敗。{humanize_import_error(e)}'
|
||||
}), 500
|
||||
|
||||
|
||||
@auto_import_bp.route('/api/reset_stuck_jobs', methods=['POST'])
|
||||
def reset_stuck_jobs():
|
||||
"""重置逾時未完成的匯入任務"""
|
||||
|
||||
Reference in New Issue
Block a user