Thread: Async triggers

Async triggers

From
Peter
Date:
Is this possible in PG somehow? Basically I need to call web service
whenever new row is inserted in a table - the lookup takes time up to
10-15 seconds. Obviously I cant do this inside trigger proc as that
would delay inserts a lot. I suppose I could do a cron job to do
webservice lookups periodically, but that involves delay and added point
of failure (if cron process stops working for whatever reason). Ideally
async trigger proc would be the solution, but it seems I cant do
asynchronous execution in PG.

Thanks!
Peter

Re: Async triggers

From
Martijn van Oosterhout
Date:
On Fri, Mar 23, 2007 at 07:30:17PM +0200, Peter wrote:
> Is this possible in PG somehow? Basically I need to call web service
> whenever new row is inserted in a table - the lookup takes time up to
> 10-15 seconds. Obviously I cant do this inside trigger proc as that
> would delay inserts a lot. I suppose I could do a cron job to do
> webservice lookups periodically, but that involves delay and added point
> of failure (if cron process stops working for whatever reason). Ideally
> async trigger proc would be the solution, but it seems I cant do
> asynchronous execution in PG.

Perhaps LISTEN/NOTIFY can do what you want. The problem with "async" is
that any query has to run on the context of some session. Which one?

Normally you have a queue table that queues work to be done, and
LISTEN/NOTIFY to wake up the daemon when there's something to do.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment