How can I determine the status of a job?

前端 未结 14 2260
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 02:36

I have a Stored procedure which schedules a job. This Job takes a lot of time to get completed (approx 30 to 40 min). I need to get to know the status of this Job. Below det

相关标签:
14条回答
  • 2020-11-30 03:02

    The tasks above work but I have seen many records in the msdb.dbo.sysjobactivity where run_Requested_date is not null and stop_execution_date is null ---- and the job is not currently running.

    I would recommend running the following script to clear out all of the bogus entries (make sure no jobs are running at the time).

    SQL2008:

        delete activity
        from msdb.dbo.sysjobs_view job  
        inner join msdb.dbo.sysjobactivity activity on job.job_id = activity.job_id 
        where  
            activity.run_Requested_date is not null  
        and activity.stop_execution_date is null  
    
    0 讨论(0)
  • 2020-11-30 03:06
    SELECT sj.name
      FROM msdb..sysjobactivity aj
      JOIN msdb..sysjobs sj
        on sj.job_id = aj.job_id
     WHERE aj.stop_execution_date  IS NULL     -- job hasn't stopped running
       AND aj.start_execution_date IS NOT NULL -- job is currently running
       AND sj.name = '<your Job Name>'
       AND NOT EXISTS( -- make sure this is the most recent run
                       select 1
                         from msdb..sysjobactivity new
                        where new.job_id = aj.job_id
                          and new.start_execution_date > aj.start_execution_date ) )
    print 'running'
    
    0 讨论(0)
提交回复
热议问题