zoukankan      html  css  js  c++  java
  • SQLServer实现作业依赖(非步骤)


    背景:
    有些存储过程是可以通过步骤来实现依赖,但有些需要实现作业与作业间的依赖,可以将前置依赖的最后一个步骤的处理信息结果保存,后置依赖的第一个步骤根据前置信息来判断是否执行,实现依赖关系

    主要步骤
    1、创建记录表
    2、前置依赖表完成该任务后插入记录表
    3、后置依赖表根据记录表的信息,判断是等待还是执行


    -- 1.创建任务记录表
    CREATE TABLE [dbo].[temp_depend](
        [dateday] [date] NULL,
        [project] [varchar](10) NULL,
        [item] [varchar](100) NULL,
        [createtime] [datetime] NULL
    ) ON [PRIMARY]
    
    
    -- 2.模拟前置依赖表完成该任务后插入记录表
    insert into temp_depend
    (
    dateday,
    project,
    createtime
    )
    select cast(getdate() as date) dateday,'ODS' project,getdate() createtime
    
    
    
    -- 3.后置依赖表根据记录表的信息,判断ODS层任务是等待还是执行
    delete from temp_depend where dateday=cast(getdate() as date) and project='DW' and item='Usp_Updae_User'
    
    -- 执行依赖
    while not exists(select 1 from temp_depend where dateday=cast(getdate() as date) and project='DW' and item='Usp_Updae_User') -- 依赖的数据未处理一直循环
    begin
    
    if exists(select 1 from temp_depend where dateday=cast(getdate() as date) and project='ODS') -- 前置依赖ODS层数据已处理完,才执行DW层
    begin
    
    -- 执行存储过程
    exec Usp_Updae_User
    
    -- 写入记录表
    insert into temp_depend(dateday,project,item,createtime)
    select cast(getdate() as date) dateday,'DW' project,'Usp_Updae_User' item,getdate() createtime
    end
    
    else
    waitfor delay '00:01:00'  -- 延时等待1分钟再次尝试执行
    
    end



  • 相关阅读:
    lnmp+memcache+tomcat
    redis的主从搭建
    curl只取状态码
    Tomcat的优化
    pip9 安装 centos6.8
    文件的下载
    保存图片到图库更新图库
    上传图片总结
    Android 大图片预览ViewPager
    Android 软件盘 Editext 问题
  • 原文地址:https://www.cnblogs.com/kylan/p/15749343.html
Copyright © 2011-2022 走看看