create proc ujo_set2act
@status int,
@run_num int,
@joid int,
@gmt int
AS
declare @auto_hold tinyint,
@auto_hold_over tinyint,
@curr_status int,
@over_num int,
@job_name varchar(64),
@has_ext int,
@isbox_job int,
@box_status int
SELECT @isbox_job = 0
SELECT @curr_status = status, @over_num=over_num
FROM ujo_job_status
WHERE joid = @joid
select @job_name = job_name, @auto_hold = auto_hold
from ujo_job
where joid = @joid
select @isbox_job = box_joid
from ujo_job
where joid = @joid and box_joid != NULL
if (@isbox_job > 0)
begin
select @box_status = status
from ujo_job_status
where joid = @isbox_job
end
if ( @over_num > 0 )
BEGIN
select @auto_hold_over = auto_hold from ujo_overjob
WHERE joid=@joid AND over_num = @over_num
IF @@rowcount=1 AND @auto_hold_over != 10
BEGIN
SELECT @auto_hold = @auto_hold_over
END
END
if ( @auto_hold = 1 AND @status = 9 ) SELECT @status = 11
if ( @curr_status = 12 )
BEGIN
DELETE ujo_wait_que
WHERE joid = @joid
END
if ( @status=9 AND (@curr_status = 7 OR @curr_status = 11) )
return 1
if ( @status=8 AND (@curr_status = 7 OR @curr_status = 11) )
return 1
if (@isbox_job > 0 AND (@box_status =7 OR @box_status = 11))
return 1
if ( @run_num > 0 )
BEGIN
if ( @status = 8 )
BEGIN
UPDATE ujo_job_status
SET status = @status,
status_time = @gmt, run_num = @run_num ,
exit_code=-656
WHERE joid = @joid
END
else
BEGIN
UPDATE ujo_job_status
SET status = @status,
status_time = @gmt, run_num = @run_num ,
ntry = 0, exit_code=-656,
last_start=0,last_end=0
WHERE joid = @joid
END
END
ELSE
BEGIN
if ( @run_num = 0 AND @curr_status != 1 AND @curr_status != 3)
BEGIN
UPDATE ujo_job_status
SET status = @status,
status_time = @gmt, last_start=0,last_end=0,
exit_code=-656
WHERE joid = @joid
END
END
if EXISTS ( select job_name FROM ujo_req_job WHERE job_name=@job_name )
select @has_ext = 1
else
select @has_ext = 0
if @curr_status = 12 and @status != 9
BEGIN
if @has_ext=1
return 4
else
return 3
END
if @has_ext=1
return 2
return 1
GO
GRANT EXECUTE ON [dbo].[ujo_set2act] TO [ujoadmin]
GO