cancel
Showing results for 
Search instead for 
Did you mean: 

Active jobs list

Former Member
0 Kudos

Hi All,

I am trying to get the report of jobs of type 'CMD' which are currently in 'running' status for more than 20 min. Can anyone please help me with the select query.

Regards,

Chandu

Accepted Solutions (1)

Accepted Solutions (1)

gmblom
Active Contributor

select j.* from Job j, JobDefinition jd, JobDefinitionType jdt where j.JobDefinition = jd.UniqueId and jd.JobDefinitionType = jdt.UniqueId and jdt.Name = 'CMD' and j.Status = 'R' and j.RunStart < NOW('subtract 20 minutes')

Regards Gerben

Former Member
0 Kudos

Thank you Gerben for the query. I tried the query, but it is not listing any jobs which are currently active and running more than 20min. Please advise.

import java.util.Iterator;

import com.redwood.scheduler.api.model.Job;

import com.redwood.scheduler.api.model.SchedulerSession;

import com.redwood.scheduler.api.model.Table;

import com.redwood.scheduler.api.model.TableValue;

import com.redwood.scheduler.api.scripting.variables.ScriptSessionFactory;

import com.redwood.scheduler.api.date.DateTimeZone;

{

  SchedulerSession session = ScriptSessionFactory.getSession();

    String strSql= "select j.* from Job j, JobDefinition jd, JobDefinitionType jdt where j.JobDefinition = jd.UniqueId and jd.JobDefinitionType = jdt.UniqueId and jdt.Name = 'CMD' and j.Status = 'R' and j.RunStart < NOW('subtract 20 minutes')";

    long lngDurationBefore=0;

    Iterator it = jcsSession.executeObjectQuery(strSql, null);

    while (it.hasNext())

    {

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

      if (j.getJobDefinition().getName()!= null)

      {

             

       

        jcsOut.println(j.getJobDefinition().getName());

     

        } else

        {

//          jcsOut.println(" No jobs match selected criteria ");

        }

      }

    }

Regards,

Chandu

basv
Explorer
0 Kudos

Hi,

This works for me. Are you sure you have jobs of type CMD running for over 20m when you execute this ?

Former Member
0 Kudos

Thanks a lot Gerben for the query. Thank you Valentijn for testing it. I made a small mistake. It is working now.

Regards,

Chandu

Answers (1)

Answers (1)

nanda_kumar21
Active Contributor
0 Kudos

What have you tried so far?

thanks

Nanda

Former Member
0 Kudos

Hello Nanda,

I tried below way as we have only 'CMD' jobs in this process server. I tried to first list all the jobs which are currently running and their duration. But the runtime in minutes(lngDurationBefore/60000) is returning a negative value.  Not sure where I am doing wrong.

import java.util.Iterator;

import com.redwood.scheduler.api.model.Job;

import com.redwood.scheduler.api.model.SchedulerSession;

import com.redwood.scheduler.api.model.Table;

import com.redwood.scheduler.api.model.TableValue;

import com.redwood.scheduler.api.scripting.variables.ScriptSessionFactory;

import com.redwood.scheduler.api.date.DateTimeZone;

{

  SchedulerSession session = ScriptSessionFactory.getSession();

  DateTimeZone t = new DateTimeZone();

  DateTimeZone t2 = new DateTimeZone();

  t.setNow();

  t2.setNow();

  t2.truncateDay();

  long currtime = t.getUTCMilliSecs() - t2.getUTCMilliSecs();

    String strSql= "select j.* from Job j, ProcessServer ps where ps.SearchName = 'XX_PROCESSSERVER' and j.ProcessServer = ps.UniqueId and j.Status in ('R')";

    long lngDurationBefore=0;

    Iterator it = jcsSession.executeObjectQuery(strSql, null);

    while (it.hasNext())

    {

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

      if (j.getRunStart() != null)

      {

        

       

          lngDurationBefore=currtime - j.getRunStart().getUTCMilliSecs();

           jcsOut.println(j.getJobDefinition().getName() + "  " + lngDurationBefore/60000);

       

        } else

        {

//          jcsOut.println(" No jobs in the specified criteria ");

 

        }

      }

    }

Regards,

Chandu