Job control in sql
От | Svenne Krap |
---|---|
Тема | Job control in sql |
Дата | |
Msg-id | 4FBF4293.4090902@krap.dk обсуждение исходный текст |
Ответы |
Re: Job control in sql
Re: Job control in sql |
Список | pgsql-sql |
Hi. <br /><br /> I am building a system, where we have jobs that run at different times (and takes widely different lengthsof time). <br /><br /> Basically I have a jobs table: <br /><br /> create table jobs(<br /> id serial, <br /> ready boolean, <br /> job_begun timestamptz, <br /> job_done timestamptz, <br /> primary key (id)<br />);<br /><br /> This should run by cron, at it is my intention that the cronjob (basically) consists of<br /><i><br /> psql-c "select run_jobs()"</i><br /><br /> My problem is, that the job should ensure that it is not running already, whichwould be to set job_begun when the job starts". That can easily happen as jobs should be started every 15 minutes (tolower latency from ready to done) but some jobs can run for hours.. <br /><br /> The problem is that a later run of run_jobs()will not see the job_begun has been set by a prior run (that is unfinished - as all queries from the plpgsql-functionruns in a single, huge transaction). <br /><br /> My intitial idea was to set the isolation level to "readuncommitted" while doing the is-somebody-else-running-lookup, but I cannot change that in the plpgsql function (it complainsthat the session has to be empty - even when I have run nothing before it). <br /><br /> Any ideas on how to solvethe issue?<br /><br /> I run it on Pgsql 9.1.<br /><br /> Svenne<br />
В списке pgsql-sql по дате отправления: