From: | Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de> |
---|---|
To: | Luca Ferrari <fluca1978(at)gmail(dot)com> |
Cc: | "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How to run a task continuously in the background |
Date: | 2019-07-17 07:38:42 |
Message-ID: | 8D19E041-DFA4-40C0-9CCA-36D65548E842@mikatiming.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
So, as far as I understand, you want asynchronously processing data
with a process that can be started manually and/or periodically.
The process should be started manually and then run until it is stopped by a stop_job() function call. In Oracle there is a package which contains the functions engine.start_job() and engine.stop_job(). :-)
I only mentioned “periodic” because the current Oracle implementation polls to see if there is something to process and goes to sleep for a second when there is no data to process.
I'm probably unable to see what is the goal, but I would go for a
combined solution:
1) a trigger that notifies an external process
<https://www.postgresql.org/docs/current/sql-notify.html>
2) the process runs when notified (by the trigger) or when started
manually or when started by pg_cron (one per minute).
That is basically still my main question. How do I start a background job (e.g. a function) which waits by polling or LISTEN / NOTIFY for records in a table to be processed.
Of course the process is "internal", so something like a stored
procedure (at least as entry point).
The problem with such solution is about race conditions (what if you
manually start something that is already running?), but I guess you
had this problem on the oracle side too.
In the Oracle world, there is a maximum of one job that takes care of processing.
Dirk
--
Dirk Mika
Software Developer
[cid:image001_d0a5cf51-5dd3-4ff5-b428-1016a6d95a0f.png]
mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany
fon +49 2202 2401-1197
dirk(dot)mika(at)mikatiming(dot)de
www.mikatiming.de
AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika
[cid:CCh2U_f27a5ce6-8556-4db1-8aa4-fd610d6e9efe.jpg]<https://youtu.be/qfOFXrpSKLQ>
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2019-07-17 07:45:02 | Re: How to run a task continuously in the background |
Previous Message | Dirk Mika | 2019-07-17 07:26:13 | Re: How to run a task continuously in the background |