create proc ujo_chase_state
@starting_delay_time int
AS
declare @nstart int
select @nstart = max( nstart ) from ujo_chase
if (@nstart IS NULL)
begin
set @nstart = 0
end
set @nstart = @nstart+1
if @nstart > 50
begin
set @nstart = 1
delete ujo_chase
end
delete ujo_chase where nstart = @nstart
insert into ujo_chase
(nstart, joid, eoid, job_name, job_type, status, run_machine, pid, jc_pid )
select @nstart, j.joid, e.eoid, j.job_name, j.job_type, status, e.machine, pid, jc_pid
from ujo_event e, ujo_job j, ujo_machine m
where e.joid = j.joid
and j.machine = m.name
and job_type in ('c', 'f')
and m.type in ('L', 'l', 'r', 'n')
and que_status = 0
and status = 1
insert into ujo_chase
(nstart, joid, job_name, job_type, status, run_machine, pid, jc_pid )
select @nstart, j.joid, j.job_name, j.job_type, status, run_machine, pid, jc_pid
from ujo_job j, ujo_job_status s, ujo_machine m
where j.joid = s.joid
and j.machine = m.name
and status = 1
and job_type in ('c','f')
and m.type in ('L', 'l', 'r', 'n')
and j.joid not in
( select joid from ujo_chase where nstart = @nstart )
insert ujo_chase
(nstart, joid, job_name, job_type, status, run_machine, pid, jc_pid )
select @nstart, j.joid, j.job_name, j.job_type, status, run_machine, pid, jc_pid
from ujo_job j, ujo_job_status s, ujo_machine m
where j.joid = s.joid
and j.machine = m.name
and status = 3
and status_time < @starting_delay_time
and job_type in ('c','f')
and m.type in ('L', 'l', 'r', 'n')
and j.joid not in
( select joid from ujo_event where status = 3 and event_time_gmt < @starting_delay_time )
and j.joid not in
( select joid from ujo_chase where nstart = @nstart )
delete from ujo_chase
where joid in
(SELECT r.joid
FROM ujo_chase r, ujo_event e
WHERE r.joid = e.joid
and que_status = 0
and e.status in ( 4,5,6,10 )
and nstart = @nstart)
delete from ujo_chase where run_machine in
(select distinct j.run_machine from ujo_job_status j, ujo_machine m where
j.run_machine = m.name and m.type in ('z', 't'))
delete from ujo_chase where run_machine='' and nstart=@nstart
if ( select top 1 1 from ujo_chase where nstart = @nstart ) > 0
begin
select @nstart
end
else
begin
select @nstart = 0
end
select @nstart as nstart
return -999
GO
GRANT EXECUTE ON [dbo].[ujo_chase_state] TO [ujoadmin]
GO