Thread: pgagent status always successful

pgagent status always successful

From
"Eric Shuman"
Date:
I am new to pgadmin and pgagent and need some help.

I am trying to set up a job in pgadmin3 that runs automatically through
pgagent.  I want the job to stop if any of the steps fail. Some of the steps
are bash scripts.  I have set the "On Error" flag to fail.

I can get my bash scripts to run through pgagent, but the status of the
script always comes back as "Successful" with a result of "1" (in the
statistics section for the step in pgadmin), this happens even if I use an
invalid filename for the script. I have also tried exiting the scripts with
various exit codes and have used "set -e" with out effect.

Is this a bug or am I missing something obvious?  Can anyone give me some
advice on setting up jobs?


Thanks for the help,

~ Eric






Re: pgagent status always successful

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgadmin-support-owner@postgresql.org
> [mailto:pgadmin-support-owner@postgresql.org] On Behalf Of Eric Shuman
> Sent: 29 June 2006 20:06
> To: pgadmin-support@postgresql.org
> Subject: [pgadmin-support] pgagent status always successful
>
> I am new to pgadmin and pgagent and need some help.
>
> I am trying to set up a job in pgadmin3 that runs
> automatically through
> pgagent.  I want the job to stop if any of the steps fail.
> Some of the steps
> are bash scripts.  I have set the "On Error" flag to fail.
>
> I can get my bash scripts to run through pgagent, but the
> status of the
> script always comes back as "Successful" with a result of "1" (in the
> statistics section for the step in pgadmin), this happens
> even if I use an
> invalid filename for the script. I have also tried exiting
> the scripts with
> various exit codes and have used "set -e" with out effect.
>
> Is this a bug or am I missing something obvious?  Can anyone
> give me some
> advice on setting up jobs?

Yes, it's a bug. Please give the attached patch to xtra/pgagent/job.cpp
a whirl and see if it helps. You should get a result of -1 if there is
an error executing the script, otherwise whatever the return value of
the script is.

Note that on Windows there is currently no way to get the script return
value.

Please let me know if it works as expected.

Regards, Dave

Attachment

Re: pgagent status always successful

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgadmin-support-owner@postgresql.org
> [mailto:pgadmin-support-owner@postgresql.org] On Behalf Of Dave Page
> Sent: 30 June 2006 08:57
> To: erics@ameri-title.com; pgadmin-support@postgresql.org
> Subject: Re: [pgadmin-support] pgagent status always successful
>
>
> Yes, it's a bug. Please give the attached patch to
> xtra/pgagent/job.cpp
> a whirl and see if it helps. You should get a result of -1 if there is
> an error executing the script, otherwise whatever the return value of
> the script is.
>
> Note that on Windows there is currently no way to get the
> script return
> value.
>
> Please let me know if it works as expected.

Sorry - just realised the patch I sent was against the current dev code,
so if you're running 1.4.x it won't apply. In that case, please use the
attached version.

Regards, Dave.

Attachment

Re: pgagent status always successful

From
Dave Page
Date:


On 5/7/06 19:34, "Eric Shuman" <erics@ameri-title.com> wrote:

> Hi Dave,
>
> I think I got the patch installed via Raphaël's instructions.  I seem to now
> get a result code for my step, but the status for the step and job is still
> "successful".  Also, the result code returned is not the same as the exit code
> for the script (is it supposed to be???).
>

Hi Eric,

If the script can be executed successfully (ie. It was created and run on
the host machine by pgAgent), then the result status code will be whatever
is returned by the pclose() call the corresponds to the popen() used to
execute the script.

If pgAgent cannot run the script (because it can't create a temporary
directory and file for example), it will return -1.

So, if you're seeing a -1 return value, run pgAgent with the log level set
to show at least warnings and you should see an error message if pgAgent is
having trouble. Otherwise, see 'man 3 pclose' which should tell you what
your system's pclose does.

As for failing the job, do you have 'On Error' set to 'Fail' for that step?

Regards, Dave.

PS. I'm off to the PostgreSQL conference in Toronto tomorrow so might not be
around much for the next week or so.



Re: pgagent status always successful

From
"Dave Page"
Date:
[Please keep on list!!]

> -----Original Message-----
> From: Raphaël Enrici [mailto:blacknoz@club-internet.fr]
> Sent: 06 July 2006 11:37
> To: erics@ameri-title.com
> Cc: Dave Page
> Subject: Re: [pgadmin-support] pgagent status always successful
>
>
> @Dave: any reason why pgagent is linked against wx although not a Gui
> program?
> @Dave bis: if you describe to me what to test, I can do the tests in
> Eric's place.

It still uses a number of wx classes. In 1.6.0 however, the linking is minimised as there is definitely more libraries
therethan are actually required. It's not really a backport candidate though. 

/D


Re: pgagent status always successful

From
blacknoz@club-internet.fr
Date:
Hi Dave,

{"keep on the list! :)))" Dave said}

Yeah, I'll build something for Eric tomorrow morning.

Cheers,
Raph

----Message d'origine----
>Sujet: RE: [pgadmin-support] pgagent status always successful
>Date: Tue, 11 Jul 2006 21:51:19 +0100
>De: "Dave Page" <dpage@vale-housing.co.uk>
>A: <erics@ameri-title.com>
>Copie à: Raphaël Enrici <blacknoz@club-internet.fr>
>
>
>
>> -----Original Message-----
>> From: Eric Shuman [mailto:erics@ameri-title.com]
>> Sent: 05 July 2006 22:07
>> To: Dave Page
>> Subject: RE: [pgadmin-support] pgagent status always successful
>>
>> Hi Dave,
>>
>> The "On Error" flag is set to fail.
>>
>> The script will run, but I have been trying to make it fail
>> by entering bad
>> code or wrong filenames just to test if the job would fail
>> and to see what
>> my statistics would be like when it does.
>>
>> The result values I get now in pgAdmin seem to be 5 digit
>> numbers (32512 for
>> example was the result of a call to the script using a bad
>> filename) I use
>> to always get a value of "1" no matter what.
>>
>> Errors will show up in the debugging, but the steps and job will still
>> always show "success".
>
>Hi Eric,
>
>Sorry for the delay. I just got to look at this some more and found that the return value is actually stored in the
top8 bits of the int returned by pclose(). I've applied suitable patched to convert that back to a signed value and now
getsensible results in my testing. As per convention, any negative value will be seen as a failure. 
>
>Raphael; I've committed patches to trunk and 1.4 - any chance you can rustle up another build for Eric to test for us
please?
>
>Thanks, Dave.
>