Skip to content

Commit f53981a

Browse files
author
Vladimir Ershov
committed
fix set_attr
1 parent a0093a7 commit f53981a

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

pgpro_scheduler--2.0.sql

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ LANGUAGE plpgsql set search_path FROM CURRENT;
338338
CREATE FUNCTION _possible_args() RETURNS jsonb AS
339339
$BODY$
340340
BEGIN
341-
RETURN json_build_object(
341+
RETURN jsonb_build_object(
342342
'node', 'node name (default: master)',
343343
'name', 'job name',
344344
'comments', 'some comments on job',
@@ -437,9 +437,9 @@ BEGIN
437437
IF N > 0 THEN
438438
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'
439439
INTO dates USING dates;
440-
cron := COALESCE(cron, '{}'::jsonb) || json_build_object('dates', array_to_json(dates))::jsonb;
440+
cron := COALESCE(cron, '{}'::jsonb) || jsonb_build_object('dates', array_to_json(dates));
441441
END IF;
442-
442+
443443
clean_cron := '{}'::jsonb;
444444
FOR name IN SELECT * FROM unnest('{dates, crontab, onstart, days, hours, wdays, months, minutes}'::text[])
445445
LOOP
@@ -635,7 +635,7 @@ LANGUAGE plpgsql
635635
CREATE FUNCTION create_job(cron text, command text, node text DEFAULT NULL) RETURNS integer AS
636636
$BODY$
637637
BEGIN
638-
RETURN create_job(json_build_object('cron', cron, 'command', command, 'node', node)::jsonb);
638+
RETURN create_job(jsonb_build_object('cron', cron, 'command', command, 'node', node));
639639
END
640640
$BODY$
641641
LANGUAGE plpgsql
@@ -644,7 +644,7 @@ LANGUAGE plpgsql
644644
CREATE FUNCTION create_job(dt timestamp with time zone, command text, node text DEFAULT NULL) RETURNS integer AS
645645
$BODY$
646646
BEGIN
647-
RETURN create_job(json_build_object('date', dt::text, 'command', command, 'node', node)::jsonb);
647+
RETURN create_job(jsonb_build_object('date', dt::text, 'command', command, 'node', node));
648648
END
649649
$BODY$
650650
LANGUAGE plpgsql
@@ -653,7 +653,7 @@ LANGUAGE plpgsql
653653
CREATE FUNCTION create_job(dts timestamp with time zone[], command text, node text DEFAULT NULL) RETURNS integer AS
654654
$BODY$
655655
BEGIN
656-
RETURN create_job(json_build_object('dates', array_to_json(dts), 'command', command, 'node', node)::jsonb);
656+
RETURN create_job(jsonb_build_object('dates', array_to_json(dts), 'command', command, 'node', node));
657657
END
658658
$BODY$
659659
LANGUAGE plpgsql
@@ -662,7 +662,7 @@ LANGUAGE plpgsql
662662
CREATE FUNCTION create_job(cron text, commands text[], node text DEFAULT NULL) RETURNS integer AS
663663
$BODY$
664664
BEGIN
665-
RETURN create_job(json_build_object('cron', cron, 'commands', array_to_json(commands), 'node', node)::jsonb);
665+
RETURN create_job(jsonb_build_object('cron', cron, 'commands', array_to_json(commands), 'node', node));
666666
END
667667
$BODY$
668668
LANGUAGE plpgsql
@@ -671,7 +671,7 @@ LANGUAGE plpgsql
671671
CREATE FUNCTION create_job(dt timestamp with time zone, commands text[], node text DEFAULT NULL) RETURNS integer AS
672672
$BODY$
673673
BEGIN
674-
RETURN create_job(json_build_object('date', dt::text, 'commands', array_to_json(commands), 'node', node)::jsonb);
674+
RETURN create_job(jsonb_build_object('date', dt::text, 'commands', array_to_json(commands), 'node', node));
675675
END
676676
$BODY$
677677
LANGUAGE plpgsql
@@ -680,7 +680,7 @@ LANGUAGE plpgsql
680680
CREATE FUNCTION create_job(dts timestamp with time zone[], commands text[], node text DEFAULT NULL) RETURNS integer AS
681681
$BODY$
682682
BEGIN
683-
RETURN create_job(json_build_object('dates', array_to_json(dts), 'commands', array_to_json(commands), 'node', node)::jsonb);
683+
RETURN create_job(jsonb_build_object('dates', array_to_json(dts), 'commands', array_to_json(commands), 'node', node));
684684
END
685685
$BODY$
686686
LANGUAGE plpgsql
@@ -796,14 +796,27 @@ $BODY$
796796
LANGUAGE plpgsql
797797
SECURITY DEFINER set search_path FROM CURRENT;
798798

799+
CREATE FUNCTION set_job_attribute(jobId integer, name text, value jsonb) RETURNS boolean AS
800+
$BODY$
801+
BEGIN
802+
IF name <> 'rule' THEN
803+
RAISE EXCEPTION 'key % cannot have a jsonb value. Only "rule" allowed', name;
804+
END IF;
805+
806+
RETURN set_job_attributes(jobId, jsonb_build_object(name, value));
807+
END
808+
$BODY$
809+
LANGUAGE plpgsql
810+
SECURITY DEFINER set search_path FROM CURRENT;
811+
799812
CREATE FUNCTION set_job_attribute(jobId integer, name text, value anyarray) RETURNS boolean AS
800813
$BODY$
801814
BEGIN
802815
IF name <> 'dates' AND name <> 'commands' THEN
803816
RAISE EXCEPTION 'key % cannot have an array value. Only dates, commands allowed', name;
804817
END IF;
805818

806-
RETURN set_job_attributes(jobId, json_build_object(name, array_to_json(value))::jsonb);
819+
RETURN set_job_attributes(jobId, jsonb_build_object(name, array_to_json(value)));
807820
END
808821
$BODY$
809822
LANGUAGE plpgsql
@@ -815,9 +828,11 @@ DECLARE
815828
attrs jsonb;
816829
BEGIN
817830
IF name = 'dates' OR name = 'commands' THEN
818-
attrs := json_build_object(name, array_to_json(value::text[]));
831+
attrs := jsonb_build_object(name, array_to_json(value::text[]));
832+
ELSIF name = 'rule' THEN
833+
attrs := jsonb_build_object('rule', value::jsonb);
819834
ELSE
820-
attrs := json_build_object(name, value);
835+
attrs := jsonb_build_object(name, value);
821836
END IF;
822837
RETURN set_job_attributes(jobId, attrs);
823838
END

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