feat(schedule): 优化排程任务配置与进度契约处理逻辑
This commit is contained in:
1 parent
d54f51ddc3
commit
99453aa52a
65 files changed
+2837
-487
No files matched your search
@@ -0,0 +1,135 @@
|
||||
"""schedule_type platform_job split
|
||||
|
||||
Revision ID: b9c0d1e2f3a4
|
||||
Revises: a8b9c0d1e2f3
|
||||
Create Date: 2026-07-08
|
||||
|
||||
用途:激活 schedule_type 执行模式;data_source_type 仅 data_pipeline;platform_job 用 platform_api_path。
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = 'b9c0d1e2f3a4'
|
||||
down_revision = 'a8b9c0d1e2f3'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table('schedule_tasks', schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
'data_source_type',
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=True,
|
||||
server_default=None,
|
||||
)
|
||||
batch_op.alter_column(
|
||||
'schedule_type',
|
||||
existing_type=sa.String(length=32),
|
||||
server_default='data_pipeline',
|
||||
)
|
||||
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_job',
|
||||
platform_api_path = 'shipping-inventory-rpa',
|
||||
data_source_type = NULL
|
||||
WHERE data_source_type = 'shipping_inventory_rpa'
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_job',
|
||||
platform_api_path = 'faq-aggregate-hot',
|
||||
data_source_type = NULL
|
||||
WHERE data_source_type = 'faq_hot_aggregate'
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_job',
|
||||
data_source_type = NULL,
|
||||
platform_api_path = LTRIM(RTRIM(REPLACE(REPLACE(platform_api_path, '/', ''), '\\', '')))
|
||||
WHERE LTRIM(RTRIM(REPLACE(REPLACE(platform_api_path, '/', ''), '\\', ''))) IN (
|
||||
'faq-aggregate-hot', 'fixed-assets-snapshot', 'shipping-inventory-rpa'
|
||||
)
|
||||
AND schedule_type IN ('platform_app', 'dify_app')
|
||||
""")
|
||||
# 兜底:历史 platform_api_path 可能存完整路径/URL(如 /api/internal/jobs/foo),
|
||||
# 精确匹配失败时按包含关系归一到对应 job key。
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_job',
|
||||
platform_api_path = 'faq-aggregate-hot',
|
||||
data_source_type = NULL
|
||||
WHERE schedule_type IN ('platform_app', 'dify_app')
|
||||
AND REPLACE(LOWER(platform_api_path), '_', '-') LIKE '%faq-aggregate-hot%'
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_job',
|
||||
platform_api_path = 'shipping-inventory-rpa',
|
||||
data_source_type = NULL
|
||||
WHERE schedule_type IN ('platform_app', 'dify_app')
|
||||
AND REPLACE(LOWER(platform_api_path), '_', '-') LIKE '%shipping-inventory-rpa%'
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_job',
|
||||
platform_api_path = 'fixed-assets-snapshot',
|
||||
data_source_type = NULL
|
||||
WHERE schedule_type IN ('platform_app', 'dify_app')
|
||||
AND REPLACE(LOWER(platform_api_path), '_', '-') LIKE '%fixed-assets-snapshot%'
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'data_pipeline',
|
||||
platform_api_path = NULL
|
||||
WHERE schedule_type IN ('platform_app', 'dify_app')
|
||||
AND data_source_type IN ('database', 'external_api')
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET platform_api_path = TRIM(BOTH '/' FROM platform_api_path)
|
||||
WHERE platform_api_path IS NOT NULL
|
||||
AND platform_api_path LIKE '/%'
|
||||
""")
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_app',
|
||||
data_source_type = 'shipping_inventory_rpa',
|
||||
platform_api_path = 'shipping-inventory-rpa'
|
||||
WHERE schedule_type = 'platform_job'
|
||||
AND platform_api_path = 'shipping-inventory-rpa'
|
||||
""")
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_app',
|
||||
data_source_type = 'faq_hot_aggregate',
|
||||
platform_api_path = 'faq-aggregate-hot'
|
||||
WHERE schedule_type = 'platform_job'
|
||||
AND platform_api_path = 'faq-aggregate-hot'
|
||||
""")
|
||||
# fixed-assets-snapshot 等其余 platform_job 统一回落旧语义(platform_app + database),
|
||||
# 避免 data_source_type 改回 NOT NULL 后残留 NULL 行导致约束失败。
|
||||
op.execute("""
|
||||
UPDATE schedule_tasks
|
||||
SET schedule_type = 'platform_app',
|
||||
data_source_type = 'database'
|
||||
WHERE schedule_type = 'platform_job'
|
||||
AND (data_source_type IS NULL OR data_source_type = '')
|
||||
""")
|
||||
with op.batch_alter_table('schedule_tasks', schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
'data_source_type',
|
||||
existing_type=sa.String(length=32),
|
||||
nullable=False,
|
||||
server_default='database',
|
||||
)
|
||||
batch_op.alter_column(
|
||||
'schedule_type',
|
||||
existing_type=sa.String(length=32),
|
||||
server_default='platform_app',
|
||||
)
|
||||
Reference in new issue
Block a user