Author Topic: Query Filter based on date range  (Read 3394 times)

methodhai

  • Sr. Member
  • ****
  • Posts: 28
Query Filter based on date range
« on: November 06, 2007, 03:09:03 AM »
Hi,

I was wondering if how to setup a query filter in the C++ API for qbjobinfo so that it only returns a job starting from a particular date? e.g. I want it to only return a list of jobs for the last 7 days.

...also..I'm sure this has been asked before - but I couldn't find it searching through the forums - is it possible for me to get a list of all the tasks that the farm is working on at the moment?

Thanks,
Hai

anthony

  • Senior Software Engineer
  • Hero Member
  • *****
  • Posts: 183
Re: Query Filter based on date range
« Reply #1 on: November 09, 2007, 10:06:59 PM »
Hey Hai,

     I'm gonna reply to this one in 2 parts.  The first one is in answer to your first question.  In order to get a list of jobs "pre-filtered" at the supervisor, you must create a QbQuery object with a filter attached to it.

     If you're already familiar with binding to our libraries, then the following snippit will be useful:

        QbQuery query;

        // we need to grab the current time.
        QbTime now;
        now.setToNow();

        // create a new time filter
        QbFilter *timeFilter = QB_NULL;
        timeFilter = new QbFilter("timecomplete", '>', now.value() - QB_TIME_WEEK);

        // add filter to the query
        query.filters().push(timeFilter);

        /*
                we pass the query object into the qbjobinfo routine and
               the result if successful will be placed in the 'jobs' object.

                we return a QB_TRUE on success and QB_FALSE on an error.
         */
        QbJobList jobs;
        if (!qbjobinfo(query, jobs)) {
                cout << "ERROR: couldn't obtain data from supervisor." << endl;
                exit(1);
        }



anthony

  • Senior Software Engineer
  • Hero Member
  • *****
  • Posts: 183
Re: Query Filter based on date range
« Reply #2 on: November 09, 2007, 10:15:41 PM »
In answer to part 2, we need to filter the data ourselves a little bit.

        QbQuery query;

        // create a status filter
        QbFilter *runFilter = QB_NULL;
        runFilter = new QbFilter("status", QB_STATUS_RUNNING);

        // add filter to the query
        query.filters().push(runFilter);

        // we'll also ask the supervisor to attach all frames to the query
        query.fields().push(new QbField("work"));

        /*
                we pass the query object into the qbjobinfo routine and
               the result if successful will be placed in the 'jobs' object.

                we return a QB_TRUE on success and QB_FALSE on an error.
         */
        QbJobList jobs;
        if (!qbjobinfo(query, jobs)) {
                cout << "ERROR: couldn't obtain data from supervisor." << endl;
                exit(1);
        }

        for (QB_INT i = 0; i < jobs.length(); i++) {
                QbJob* job = jobs.get(i);
                if (job == NULL)
                        continue;

                for (QB_INT j = 0; j < job->agenda().length(); j++) {
                        QbWork* work = job->agenda().get(j);
                        if (work == NULL)
                                continue;

                        // skip all agenda items not currently running or waiting
                        if (!work->assigned())
                                continue;

                        cout << "Job Id: " << job->id() << ":" << work->name() << endl;
                }
        }

methodhai

  • Sr. Member
  • ****
  • Posts: 28
Re: Query Filter based on date range
« Reply #3 on: November 10, 2007, 03:13:52 AM »
Thanks Anthony!

This is extremely useful.