dystudio / pg_task

PostgreSQL job scheduler pg_task allows to execute any sql command at any specific time at background asynchronously

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PostgreSQL job scheduler pg_task allows to execute any sql command at any specific time at background asynchronously

pg_task config

to run pg_task add it to line

shared_preload_libraries = 'pg_task'

by default pg_task

  1. executes
pg_task.default_count = 1000

tasks until exit

  1. uses database
pg_task.default_data = 'postgres'
  1. deletes task if output is null
pg_task.default_delete = 'on'
  1. uses in output delimiter
pg_task.default_delimiter = '\t'
  1. uses drift
pg_task.default_drift = 'on'
  1. groupes tasks by
pg_task.default_group = 'group'
  1. prints headers in output
pg_task.default_header = 'on'
  1. processes tasks
pg_task.default_live = '1 hour'

before exit

  1. executes simultaniously
pg_task.default_max = 0

tasks

  1. prints null in output as
pg_task.default_null = '\N'
  1. uses schema
pg_task.default_partman = 'partman'

for pg_partman if extension available

  1. uses schema
pg_task.default_schema = 'public'

for tasks

  1. prints only strings in quotes in output
pg_task.default_string = 'on'
  1. uses table
pg_task.default_table = 'task'

for tasks

  1. uses sleep timeout
pg_task.default_timeout = 1000

milliseconds

  1. uses user
pg_task.default_user = 'postgres'

by default pg_task run on default database with default user with default schema with default table with default timeout

to run specific database and/or specific user and/or specific schema and/or specific table and/or specific timeout, set config (in json format)

pg_task.json = '[{"data":"database1"},{"data":"database2","user":"username2"},{"data":"database3","schema":"schema3"},{"data":"database4","table":"table4"},{"data":"database5","timeout":100}]'

if database and/or user and/or schema and/or table does not exist then pg_task create it/their (with using pg_partman if user does not exist then pg_task create it as superuser to create extension, but after that You may alter on nosuperuser)

pg_task using

by default pg_task create table with folowing columns

id bigserial - primary key

parent bigint - parent task (if exists)

plan timestamp - planned time of start

start timestamp - actual time of start

stop timestamp - actual time of stop

group text - task groupping

max int - maximum concurently tasks in group

pid int - id of process executing task

input text - sql to execute

output text - received result

error text - occured error

state state - PLAN, TAKE, WORK, DONE or STOP

timeout interval - allowed time to run

delete boolean - autodelete (if output is null)

repeat interval - autorepeat interval

drift boolean - see below

count integer - maximum tasks executed by current worker

live interval - maximum time of live of current worker

remote text - connect to remote database (if need)

but you may add any needed colums and/or make partitions

to run task more quickly execute sql command

INSERT INTO task (input) VALUES ('SELECT now()')

to run task after 5 minutes write plannded time

INSERT INTO task (plan, input) VALUES (now() + '5 min':INTERVAL, 'SELECT now()')

to run task at specific time so write

INSERT INTO task (plan, input) VALUES ('2029-07-01 12:51:00', 'SELECT now()')

to repeat task every 5 minutes write

INSERT INTO task (repeat, input) VALUES ('5 min', 'SELECT now()')

if write so

INSERT INTO task (repeat, input, drift) VALUES ('5 min', 'SELECT now()', false)

then repeat task will start after 5 minutes after task done (instead after planned time as default)

if exception occures it catched and writed in error as text

INSERT INTO task (input) VALUES ('SELECT 1/0')

if some group needs concurently run only 2 tasks then use command

INSERT INTO task (group, max, input) VALUES ('group', 1, 'SELECT now()')

if in this group there are more tasks and they are executing concurently by 2 then command

INSERT INTO task (group, max, input) VALUES ('group', 2, 'SELECT now()')

will execute task as more early in this group (as like priority)

to run task on remote database use sql command

INSERT INTO task (input, remote) VALUES ('SELECT now()', 'user=user host=host')

About

PostgreSQL job scheduler pg_task allows to execute any sql command at any specific time at background asynchronously

License:MIT License


Languages

Language:C 93.7%Language:PLpgSQL 5.9%Language:Makefile 0.3%