Skip to content

Commit 1a5283c

Browse files
committed
Merge branch 'PGPROEE9_6_scheduler' into PGPROEE9_6
2 parents 90c37c0 + c9bd96b commit 1a5283c

12 files changed

+910
-180
lines changed

contrib/pgpro_scheduler/pgpro_scheduler--2.0.sql

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,15 @@ CREATE TABLE at_jobs_submitted(
2828
CREATE INDEX ON at_jobs_submitted(at,submit_time);
2929
CREATE INDEX ON at_jobs_submitted (last_start_available, node);
3030

31-
CREATE TABLE at_jobs_process(
32-
start_time timestamp with time zone default now()
33-
) INHERITS (at_jobs_submitted);
31+
CREATE TABLE at_jobs_process (like at_jobs_submitted including all);
32+
ALTER TABLE at_jobs_process ADD start_time timestamp with time zone default now();
33+
CREATE INDEX at_jobs_process_node_at_idx on at_jobs_process (node, at);
3434

35-
ALTER TABLE at_jobs_process ADD primary key (id);
36-
CREATE INDEX at_jobs_process_node_at_idx on at_jobs_process (node, at);
35+
CREATE TABLE at_jobs_done (like at_jobs_process including all);
36+
ALTER TABLE at_jobs_done ADD status boolean;
37+
ALTER TABLE at_jobs_done ADD reason text;
38+
ALTER TABLE at_jobs_done ADD done_time timestamp with time zone default now();
3739

38-
CREATE TABLE at_jobs_done(
39-
status boolean,
40-
reason text,
41-
done_time timestamp with time zone default now()
42-
) INHERITS (at_jobs_process);
43-
44-
ALTER TABLE at_jobs_done ADD primary key (id);
45-
CREATE INDEX at_jobs_done_node_at_idx on at_jobs_done (node, at);
4640

4741
CREATE TABLE cron(
4842
id SERIAL PRIMARY KEY,

contrib/pgpro_scheduler/src/pgpro_scheduler.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ char *scheduler_databases = NULL;
4646
char *scheduler_nodename = NULL;
4747
char *scheduler_transaction_state = NULL;
4848
int scheduler_max_workers = 2;
49-
int scheduler_at_max_workers = 2;
49+
int scheduler_max_parallel_workers = 2;
50+
int scheduler_worker_job_limit = 1;
5051
bool scheduler_service_enabled = false;
5152
char *scheduler_schema = NULL;
5253
/* Custom GUC done */
@@ -163,6 +164,29 @@ bool is_scheduler_enabled(void)
163164
return false;
164165
}
165166

167+
char *set_schema(const char *name, bool get_old)
168+
{
169+
char *schema_name = NULL;
170+
char *current = NULL;
171+
bool free_name = false;
172+
173+
if(get_old)
174+
current = _copy_string((char *)GetConfigOption("search_path", true, false));
175+
if(name)
176+
{
177+
schema_name = (char *)name;
178+
}
179+
else
180+
{
181+
schema_name = _copy_string((char *)GetConfigOption("schedule.schema", true, false));
182+
free_name = true;
183+
}
184+
SetConfigOption("search_path", schema_name, PGC_USERSET, PGC_S_SESSION);
185+
if(free_name) pfree(schema_name);
186+
187+
return current;
188+
}
189+
166190

167191
/** END of SOME UTILS **/
168192

@@ -472,10 +496,10 @@ void _PG_init(void)
472496
NULL
473497
);
474498
DefineCustomIntVariable(
475-
"schedule.at_max_workers",
499+
"schedule.max_parallel_workers",
476500
"How much workers can serve at jobs on one database",
477501
NULL,
478-
&scheduler_at_max_workers,
502+
&scheduler_max_parallel_workers,
479503
2,
480504
1,
481505
100,
@@ -497,6 +521,20 @@ void _PG_init(void)
497521
NULL,
498522
NULL
499523
);
524+
DefineCustomIntVariable(
525+
"schedule.worker_job_limit",
526+
"How much job can worker serve before shutdown",
527+
NULL,
528+
&scheduler_worker_job_limit,
529+
1,
530+
1,
531+
20000,
532+
PGC_SUSET,
533+
0,
534+
NULL,
535+
NULL,
536+
NULL
537+
);
500538
pg_scheduler_startup();
501539
}
502540

contrib/pgpro_scheduler/src/pgpro_scheduler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ int get_integer_from_string(char *s, int start, int len);
4040
TimestampTz get_timestamp_from_string(char *str);
4141
TimestampTz _round_timestamp_to_minute(TimestampTz ts);
4242
bool is_scheduler_enabled(void);
43+
char *set_schema(const char *name, bool get_old);
4344

4445
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy