Quick pgagent bug fix

From: Brian Kalbfus <mlists(at)kalbfus(dot)com>
To: pgadmin-support(at)postgresql(dot)org
Subject: Quick pgagent bug fix
Date: 2007-11-28 18:45:00
Message-ID: 474DB72C.8090401@kalbfus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

I have two jobs scheduled and the second one ran every poll interval,
regardless of any schedule I put in it. I traced the cause to the "host
agent" field being populated.

Looking at the source of pgAgent.cpp, from 5 weeks ago, I see the
following query being used to check if the agent should run the job:

*while* (1)
{
*bool* foundJobToExecute=false;

LogMessage(_(*"Checking for jobs to run"*), LOG_DEBUG);
DBresult *res=serviceConn->Execute(
wxT(*"SELECT J.jobid "*)
wxT(*" FROM pgagent.pga_job J "*)
wxT(*" WHERE jobenabled "*)
wxT(*" AND jobagentid IS NULL "*)
wxT(*" AND jobnextrun <= now() "*)
wxT(*" AND jobhostagent = '' OR jobhostagent = '"*) + hostname + wxT(*"'"*)
wxT(*" ORDER BY jobnextrun"*));

*if* (res)

.....

The SQL will return a row if the jobhostagent field matches every time (the OR clause is on the same level as all the AND clauses). We need to group the last two clauses:

*while* (1)
{
*bool* foundJobToExecute=false;

LogMessage(_(*"Checking for jobs to run"*), LOG_DEBUG);
DBresult *res=serviceConn->Execute(
wxT(*"SELECT J.jobid "*)
wxT(*" FROM pgagent.pga_job J "*)
wxT(*" WHERE jobenabled "*)
wxT(*" AND jobagentid IS NULL "*)
wxT(*" AND jobnextrun <= now() "*)
wxT(*" AND (jobhostagent = '' OR jobhostagent = '"*) + hostname + wxT(*"')"*)
wxT(*" ORDER BY jobnextrun"*));

*if* (res)

.....

this bug would be reproduced by populating the host agent field of any
job with the full dns name of your server running pgagent. Look at the
debug log of pgagent and you'll see it run that job every poll
interval. I don't have a build environment to test this with, but I'm
sure the change I'm recommending to the SQL will fix this bug.

Thanks,
Brian Kalbfus

Responses

Browse pgadmin-support by date

  From Date Subject
Next Message Dave Page 2007-11-28 20:09:35 Re: variables during creation of a rule
Previous Message Jean-Max Reymond 2007-11-28 16:53:50 pgadmin 1.8 loops...