IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_execute_kernel_task_slow]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_execute_kernel_task_slow]
GO
CREATE procedure [dbo].[mps_execute_kernel_task_slow]  
as  
begin  
  
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
  declare @res int 
  exec checktask 3,@res output 
  if (@res=1) return 
  
  declare status1 cursor LOCAL FORWARD_ONLY READ_ONLY for  
  select tsk_id,tsk_command,tsk_type   from mps_task_kernel  with(nolock) where tsk_times<10 and tsk_command like '%mps_sys_calc%'   order by tsk_times , tsk_id 

  open status1  
  declare @sql nvarchar(4000)   
  declare @taskid bigint   
  declare @type varchar(50) 
  declare @newordid bigint   
  declare @t1 datetime 
  declare @t2 datetime 
  declare @t0 float 
  FETCH NEXT FROM status1 INTO @taskid,@sql ,@type  
  WHILE (@@FETCH_STATUS = 0)  
  BEGIN  
set @t1 = GETDATE()  
    set @sql = isnull(@sql,'')   
    if (len(@sql)>10)   
    begin  
    BEGIN TRY 
       BEGIN TRAN 
        if (@type='newbiz') 
        begin
set @newordid = 0 
exec sp_executesql @sql ,N'@taskid bigint,@newordid bigint output',@taskid  , @newordid output 
set @t2 = GETDATE()  
set @t0 =  convert(float,@t2) - convert(float,@t1 )
if (@newordid>0) 
begin
update mps_task_kernel with(rowlock) set tsk_command=tsk_command+' --'+CONVERT(varchar(10),@newordid), tsk_usedtime=convert(int,@t0 * (24 * 3600) * 100) where tsk_id=@taskid 
delete mps_task_kernel  where tsk_id=@taskid 

end else
begin
update mps_task_kernel with(rowlock) set  tsk_times = tsk_times+1 where tsk_id=@taskid 
end
        end  else 
        begin
exec sp_executesql @sql 
set @t2 = GETDATE()  
set @t0 =  convert(float,@t2) - convert(float,@t1 )
update mps_task_kernel with(rowlock) set tsk_usedtime=convert(int,@t0 * (24 * 3600) * 100) where tsk_id=@taskid 
delete mps_task_kernel  where tsk_id=@taskid 
        end 

    COMMIT TRAN -------提交事务
    END TRY-----------结束捕捉异常
    BEGIN CATCH------------有异常被捕获
    
        
        
        IF @@TRANCOUNT > 0---------------判断有没有事务
        BEGIN
            ROLLBACK TRAN----------回滚事务
        END 
        insert into mps_task_error(tske_type,tske_tskid,tske_number,tske_severity,tske_state,tske_procedure,tske_line,tske_message)
SELECT 'kernel',@taskid,ERROR_NUMBER(),ERROR_SEVERITY(),ERROR_STATE(),ERROR_PROCEDURE(),
        ERROR_LINE(),ERROR_MESSAGE() 
        update mps_task_kernel with(rowlock) set  tsk_times = tsk_times+1 where tsk_id=@taskid 
    END CATCH--------结束异常处理
    end
    FETCH NEXT FROM status1 INTO @taskid,@sql ,@type  
  END  
  CLOSE status1  
 DEALLOCATE status1   
   exec finishedtask 3
end