cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to do a mass status change of Jobs from Console to Unknown status?

Former Member
0 Kudos

Hi All,

I'm running CPS Build M33.120-83827

I have approximately 300 very old jobs in Job Monitor that are currently in Console status, which I need to delete.

Note: the corresponding Operator Messages were deleted as part of regular system maintenance a long time back.

Since these jobs aren't in a Final State, I'm aiming to change their status to Unknown and then proceed with deletion.

Note: I do not want to terminate these jobs as I don't trust how many new jobs it'll spawn as a result. Termination of these jobs will also result in automatic incidents being raised in my system which I would rather not happen.

Given the sheer number of jobs, manually forcing each job into Unknown status is a very cumbersome process.

Is anyone aware of a Redwood script (or any other method), to perform a mass job status change to Unknown? Possibly a script that takes in a mass list of JobIDs and iteratively modifies the status of each?

Appreciate any assistance.

Thanx.

-V-

Accepted Solutions (1)

Accepted Solutions (1)

h_carpenter
Active Contributor
0 Kudos

Hi Vinit,

You could do the following:


{

//Execute a query to get all jobs in status Console (letter O) that started more than 1 day ago

for (Iterator it = jcsSession.executeObjectQuery("select Job.* from Job where Job.Status = 'O' and Job.RunStart < now('subtract 1 day') order by Job.JobId DESC", null); it.hasNext();)

  {

//get the job

    Job j = (Job) it.next();

    jcsOut.println("Job :" + j.getDescription() + " ("+ j.getJobId() + " ) has status: " +j.getStatus() + " (" + j.getStatus().getCodeEx() + ")");

  //create the job to force status to unknown

    Job setUnknown = jcsSession.getJobDefinitionByName("System_ForceJobStatusUnknown").prepare();

    setUnknown.getJobParameterByName("JobId").setInValue(j.getJobId());

//Uncomment the following line to make the whole thing wet

    //jcsSession.persist();

  }

}

Note that I have commented-out jcsSession.persist(); which actually saves the changes to the database and creates the jobs ... I do this so you can verify using the output in the shell that you are only affecting the jobs you mean to ... I order descending, so that the first are the "newest" ...

Regards,

HP

Former Member
0 Kudos

Thanx HP,

This seems exactly like what I'm after. I'll test this out and advise the results.

Much appreciated.

Answers (1)

Answers (1)

0 Kudos

Hello Vinit ,

Use predefined System_ForceJobStatusUnknown to move the job status from console to Unknown.

If its 1 job you have to give job id to convert from console to unknown.

if its mass then you have to processserver name , but we cant filter with the job name to convert from console to Unknown.


this might help you

Former Member
0 Kudos

Thanx Krishna.

It is a mass change of status I was after. Unfortunately there're 100s of other jobs that run successfully on the same ProcessServer, so I'd be reluctant to reference the ProcessServer itself when performing a mass status change.

gmblom
Active Contributor
0 Kudos

Hello,

You want to be very careful here as potentially you set all jobs in your system in Unknown here!!!

- The JobId parameter is a Number field and MUST take a BigDecimal as input.

- Also pass in the ProcessServer, just to be sure.

- Use a bind variable for the date selection as the 'now' sql option has some caching issues


{

  //Execute a query to get all jobs in status Console (letter O) that started more than 1 day ago

  DateTimeZone yesterday = DateTimeZone.expressionNow("subtract 1 day");

  for (Iterator it = jcsSession.executeObjectQuery("select Job.* from Job where Job.Status = 'O' and Job.RunStart < ? order by Job.JobId DESC", new Object [] {new Long(yesterday.getUTCMilliSecs())}); it.hasNext();)

  { 

    //get the job

    Job j = (Job) it.next();

    jcsOut.println("Job :" + j.getDescription() + " ("+ j.getJobId() + " ) has status: " +j.getStatus() + " (" + j.getStatus().getCodeEx() + ")");

    //create the job to force status to unknown 

    Job setUnknown = jcsSession.getJobDefinitionByName("System_ForceJobStatusUnknown").prepare();

    setUnknown.getJobParameterByName("JobId").setInValueNumber(new java.math.BigDecimal(j.getJobId().toString()));

    setUnknown.getJobParameterByName("ProcessServer").setInValueString(j.getProcessServer().getName());

    //Uncomment the following line to make the whole thing wet 

    //jcsSession.persist();

  }

}

Regards Gerben