Skip to content

Commit c0f74cd

Browse files
author
Vladimir Ershov
committed
fix onstart && cron
1 parent 861c85a commit c0f74cd

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

pgpro_scheduler--2.0.sql

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -396,34 +396,42 @@ 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;
407408
BEGIN
408409

410+
IF NOT params?'cron' AND NOT params?'rule' AND NOT params?'date' AND NOT params?'dates' THEN
411+
RAISE EXCEPTION 'There is no information about job''s schedule'
412+
USING HINT = 'Use ''cron'' - cron string, ''rule'' - json to set schedule rules or ''date'' and ''dates'' to set exact date(s)';
413+
END IF;
414+
409415
IF params?'cron' THEN
410416
EXECUTE 'SELECT cron2jsontext($1::cstring)::jsonb'
411417
INTO cron
412418
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)';
419+
IF prev IS NOT NULL THEN
420+
cron := prev || cron;
421+
END IF;
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+
END IF;
427+
428+
cron := coalesce(cron, '{}'::jsonb) || coalesce(rule, '{}'::jsonb);
429+
430+
IF cron?'date' THEN
431+
dates := _get_array_from_jsonb(dates, cron->'date');
432+
END IF;
433+
IF cron?'dates' THEN
434+
dates := _get_array_from_jsonb(dates, cron->'dates');
427435
END IF;
428436

429437
IF params?'date' THEN
@@ -437,7 +445,7 @@ BEGIN
437445
IF N > 0 THEN
438446
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'
439447
INTO dates USING dates;
440-
cron := COALESCE(cron, '{}'::jsonb) || jsonb_build_object('dates', array_to_json(dates));
448+
cron := cron || jsonb_build_object('dates', array_to_json(dates));
441449
END IF;
442450

443451
clean_cron := '{}'::jsonb;
@@ -564,7 +572,7 @@ BEGIN
564572
RAISE WARNING 'You used excess keys in params: %.', array_to_string(excess, ', ');
565573
END IF;
566574

567-
cron := _get_cron_from_attrs(params);
575+
cron := _get_cron_from_attrs(params, NULL);
568576
commands := _get_commands_from_attrs(params);
569577
executor := _get_executor_from_attrs(params);
570578
node := 'master';
@@ -711,7 +719,7 @@ BEGIN
711719

712720
IF attrs?'cron' OR attrs?'date' OR attrs?'dates' OR attrs?'rule' THEN
713721
cmd := cmd || 'rule = ' ||
714-
quote_literal(_get_cron_from_attrs(attrs)) || '::jsonb, ';
722+
quote_literal(_get_cron_from_attrs(attrs, job.rule)) || '::jsonb, ';
715723
END IF;
716724

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

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