Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9e826fc

Browse files
author
Vladimir Ershov
committed
Merge commit '1792a38c751ee03980e406e350f54633ad541233' into PGPROEE9_6_scheduler
2 parents 01146d7 + 1792a38 commit 9e826fc

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

contrib/pgpro_scheduler/pgpro_scheduler--2.0.sql

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -396,34 +396,43 @@ END
396396
$BODY$
397397
LANGUAGE plpgsql set search_path FROM CURRENT;
398398

399-
CREATE FUNCTION _get_cron_from_attrs(params jsonb) RETURNS jsonb AS
399+
CREATE FUNCTION _get_cron_from_attrs(params jsonb, prev jsonb) RETURNS jsonb AS
400400
$BODY$
401401
DECLARE
402402
dates text[];
403403
cron jsonb;
404+
rule jsonb;
404405
clean_cron jsonb;
405406
N integer;
406407
name text;
408+
updatePrev boolean;
407409
BEGIN
408410

411+
updatePrev := true;
412+
413+
IF NOT params?'cron' AND NOT params?'rule' AND NOT params?'date' AND NOT params?'dates' THEN
414+
RAISE EXCEPTION 'There is no information about job''s schedule'
415+
USING HINT = 'Use ''cron'' - cron string, ''rule'' - json to set schedule rules or ''date'' and ''dates'' to set exact date(s)';
416+
END IF;
417+
409418
IF params?'cron' THEN
410419
EXECUTE 'SELECT cron2jsontext($1::cstring)::jsonb'
411420
INTO cron
412421
USING params->>'cron';
413-
ELSIF params?'rule' THEN
414-
cron := params->'rule';
415-
ELSIF NOT params?'date' AND NOT params?'dates' THEN
416-
RAISE EXCEPTION 'There is no information about job''s schedule'
417-
USING HINT = 'Use ''cron'' - cron string, ''rule'' - json to set schedule rules or ''date'' and ''dates'' to set exact date(s)';
418422
END IF;
419423

420-
IF cron IS NOT NULL THEN
421-
IF cron?'date' THEN
422-
dates := _get_array_from_jsonb(dates, cron->'date');
423-
END IF;
424-
IF cron?'dates' THEN
425-
dates := _get_array_from_jsonb(dates, cron->'dates');
426-
END IF;
424+
IF params?'rule' THEN
425+
rule := params->'rule';
426+
updatePrev := false;
427+
END IF;
428+
429+
cron := coalesce(cron, '{}'::jsonb) || coalesce(rule, '{}'::jsonb);
430+
431+
IF cron?'date' THEN
432+
dates := _get_array_from_jsonb(dates, cron->'date');
433+
END IF;
434+
IF cron?'dates' THEN
435+
dates := _get_array_from_jsonb(dates, cron->'dates');
427436
END IF;
428437

429438
IF params?'date' THEN
@@ -437,7 +446,11 @@ BEGIN
437446
IF N > 0 THEN
438447
EXECUTE 'SELECT array_agg(lll) FROM (SELECT distinct(date_trunc(''min'', unnest::timestamp with time zone)) as lll FROM unnest($1) ORDER BY date_trunc(''min'', unnest::timestamp with time zone)) as Z'
439448
INTO dates USING dates;
440-
cron := COALESCE(cron, '{}'::jsonb) || jsonb_build_object('dates', array_to_json(dates));
449+
cron := cron || jsonb_build_object('dates', array_to_json(dates));
450+
END IF;
451+
452+
IF updatePrev AND prev IS NOT NULL THEN
453+
cron := prev || cron;
441454
END IF;
442455

443456
clean_cron := '{}'::jsonb;
@@ -564,7 +577,7 @@ BEGIN
564577
RAISE WARNING 'You used excess keys in params: %.', array_to_string(excess, ', ');
565578
END IF;
566579

567-
cron := _get_cron_from_attrs(params);
580+
cron := _get_cron_from_attrs(params, NULL);
568581
commands := _get_commands_from_attrs(params);
569582
executor := _get_executor_from_attrs(params);
570583
node := 'master';
@@ -711,7 +724,7 @@ BEGIN
711724

712725
IF attrs?'cron' OR attrs?'date' OR attrs?'dates' OR attrs?'rule' THEN
713726
cmd := cmd || 'rule = ' ||
714-
quote_literal(_get_cron_from_attrs(attrs)) || '::jsonb, ';
727+
quote_literal(_get_cron_from_attrs(attrs, job.rule)) || '::jsonb, ';
715728
END IF;
716729

717730
IF attrs?'command' OR attrs?'commands' THEN

0 commit comments

Comments
 (0)