Sql Server维护计划任务&完成

发布于 2024-09-06 02:51:49 字数 771 浏览 11 评论 0原文

我有一个如下所示的维护计划...

Client 1 Import Data (Success) -> Process Data (Success) -> Post Process (Completion) -> Next Client
Client 2 Import Data (Success) -> Process Data (Success) -> Post Process (Completion) -> Next Client
Client N ...

导入数据和处理数据正在调用作业,而后处理是一个执行 Sql 任务。 如果导入数据或处理数据失败,它将转到下一个客户端导入数据...

导入数据和处理数据都是包含使用内置 SQL 日志记录提供程序的 SSIS 包的作业。

我对当前配置的期望是:

  1. 客户端 1 导入数据运行:失败 ->客户端2导入数据|成功处理数据
  2. 处理数据运行:失败->客户端2导入数据|成功后处理
  3. 后处理运行:完成 ->成功或失败->下一个客户端导入数据

但这不是我在日志中看到的内容...... 我看到几个客户端导入数据 SSIS 日志条目,然后是几个后处理日志条目,然后回到客户端导入数据!嗯!!

我做错了什么?我不认为客户端 1 导入数据的“成功”部分会开始,直到它......嗯......成功又完成!日志似乎表明不然......

我真的需要这些任务是连续的而不是并发的。这可能吗?

谢谢!

I have a maintenance plan that looks like this...

Client 1 Import Data (Success) -> Process Data (Success) -> Post Process (Completion) -> Next Client
Client 2 Import Data (Success) -> Process Data (Success) -> Post Process (Completion) -> Next Client
Client N ...

Import Data and Process Data are calling jobs and Post Process is an Execute Sql task.
If Import Data or Process Data Fail, it goes to the next client Import Data...

Both Import Data and Process Data are jobs that contain SSIS packages that are using the built-in SQL logging provider.

My expectation with the configuration as it stands is:

  1. Client 1 Import Data Runs: Failure -> Client 2 Import Data | Success Process Data
  2. Process Data Runs: Failure -> Client 2 Import Data | Success Post Process
  3. Post Process Runs: Completion -> Success or Failure -> Next Client Import Data

This isn't what I'm seeing in my logs though...
I see several Client Import Data SSIS log entries, then several Post Process log entries, then back to Client Import Data! Arg!!

What am I doing wrong? I didn't think the "success" piece of Client 1 Import Data would kick off until it... well... succeeded aka finished! The logs seem to indicate otherwise though...

I really need these tasks to be consecutive not concurrent. Is this possible?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彩扇题诗 2024-09-13 02:51:54

尝试在需要分组执行的任务周围放置一个序列容器。

Try placing a sequence container around tasks you need to execute in groups.

不一样的天空 2024-09-13 02:51:54

对我来说,解决方法最终是不使用内置的“执行 SQL Server 代理作业任务”,而是使用“执行 T-SQL 语句任务”并调用一个阻塞直到完成的存储过程...

甜蜜的成功:-)

CREATE PROCEDURE [dbo].[SQLJob_RunBlocking]
(
    @JobName SYSNAME
)
AS
BEGIN
    -- running a job returns before the job is complete
    -- this procedure will run the job and loop until its status is complete
    SET NOCOUNT ON;

    DECLARE @JobStatus INT;

    -- start job
    EXECUTE msdb.dbo.sp_start_job @job_name = @JobName;

    -- loop until status is complete
    WHILE ISNULL(@JobStatus, 0) != 4 BEGIN
        WAITFOR DELAY '00:00:01';

        EXECUTE dbo.SQLJob_GetStatus @job_name = @JobName, @select_data = 0, @execution_status = @JobStatus OUTPUT;
    END
END

并且...

CREATE PROCEDURE [dbo].[SQLJob_GetStatus]
(
    @job_name SYSNAME
    ,@select_data INT = 0
    ,@execution_status INT = NULL OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON;

    -- http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-sql-job-execution-status.html
    /*
        Is the execution status for the jobs. 
        Value Description 
        0 Returns only those jobs that are not idle or suspended.  
        1 Executing. 
        2 Waiting for thread. 
        3 Between retries. 
        4 Idle. 
        5 Suspended. 
        7 Performing completion actions 
    */

    DECLARE @job_id UNIQUEIDENTIFIER 
        ,@is_sysadmin INT
        ,@job_owner SYSNAME;

    SELECT @job_id = job_id FROM msdb.dbo.sysjobs_view where name = @job_name;
    SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0);
    SELECT @job_owner = SUSER_SNAME();

    CREATE TABLE #xp_results (
        job_id                UNIQUEIDENTIFIER NOT NULL,
        last_run_date         INT              NOT NULL,
        last_run_time         INT              NOT NULL,
        next_run_date         INT              NOT NULL,
        next_run_time         INT              NOT NULL,
        next_run_schedule_id  INT              NOT NULL,
        requested_to_run      INT              NOT NULL, -- BOOL
        request_source        INT              NOT NULL,
        request_source_id     sysname          COLLATE database_default NULL,
        running               INT              NOT NULL, -- BOOL
        current_step          INT              NOT NULL,
        current_retry_attempt INT              NOT NULL,
        job_state             INT              NOT NULL
    );


    IF ((@@microsoftversion / 0x01000000) >= 8) -- SQL Server 8.0 or greater
        INSERT INTO #xp_results
        EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner, @job_id;
    ELSE
        INSERT INTO #xp_results
        EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner;

    --declare @execution_status int
    SET @execution_status = (SELECT job_state FROM #xp_results);

    DROP TABLE #xp_results;

    IF @select_data = 1 
        SELECT @job_name AS 'job_name', @execution_status AS 'execution_status';
END

For me the workaround ended up being NOT using the built-in "Execute SQL Server Agent Job Task" and instead using "Execute T-SQL Statement Task" and calling a stored procedure that blocked until completion...

Sweet success :-)

CREATE PROCEDURE [dbo].[SQLJob_RunBlocking]
(
    @JobName SYSNAME
)
AS
BEGIN
    -- running a job returns before the job is complete
    -- this procedure will run the job and loop until its status is complete
    SET NOCOUNT ON;

    DECLARE @JobStatus INT;

    -- start job
    EXECUTE msdb.dbo.sp_start_job @job_name = @JobName;

    -- loop until status is complete
    WHILE ISNULL(@JobStatus, 0) != 4 BEGIN
        WAITFOR DELAY '00:00:01';

        EXECUTE dbo.SQLJob_GetStatus @job_name = @JobName, @select_data = 0, @execution_status = @JobStatus OUTPUT;
    END
END

And...

CREATE PROCEDURE [dbo].[SQLJob_GetStatus]
(
    @job_name SYSNAME
    ,@select_data INT = 0
    ,@execution_status INT = NULL OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON;

    -- http://www.siccolo.com/Articles/SQLScripts/how-to-create-sql-to-sql-job-execution-status.html
    /*
        Is the execution status for the jobs. 
        Value Description 
        0 Returns only those jobs that are not idle or suspended.  
        1 Executing. 
        2 Waiting for thread. 
        3 Between retries. 
        4 Idle. 
        5 Suspended. 
        7 Performing completion actions 
    */

    DECLARE @job_id UNIQUEIDENTIFIER 
        ,@is_sysadmin INT
        ,@job_owner SYSNAME;

    SELECT @job_id = job_id FROM msdb.dbo.sysjobs_view where name = @job_name;
    SELECT @is_sysadmin = ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0);
    SELECT @job_owner = SUSER_SNAME();

    CREATE TABLE #xp_results (
        job_id                UNIQUEIDENTIFIER NOT NULL,
        last_run_date         INT              NOT NULL,
        last_run_time         INT              NOT NULL,
        next_run_date         INT              NOT NULL,
        next_run_time         INT              NOT NULL,
        next_run_schedule_id  INT              NOT NULL,
        requested_to_run      INT              NOT NULL, -- BOOL
        request_source        INT              NOT NULL,
        request_source_id     sysname          COLLATE database_default NULL,
        running               INT              NOT NULL, -- BOOL
        current_step          INT              NOT NULL,
        current_retry_attempt INT              NOT NULL,
        job_state             INT              NOT NULL
    );


    IF ((@@microsoftversion / 0x01000000) >= 8) -- SQL Server 8.0 or greater
        INSERT INTO #xp_results
        EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner, @job_id;
    ELSE
        INSERT INTO #xp_results
        EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner;

    --declare @execution_status int
    SET @execution_status = (SELECT job_state FROM #xp_results);

    DROP TABLE #xp_results;

    IF @select_data = 1 
        SELECT @job_name AS 'job_name', @execution_status AS 'execution_status';
END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文