Skip to content

Commit

Permalink
o omit the exception handler in pg_cron 1.1 upgrade file
Browse files Browse the repository at this point in the history
o removed unneeded REGRESS_OPTS from Makefile
o add cron.schedule and cron.unschedule to regression test
o removed some odd extra newlines
  • Loading branch information
Sven Stadler committed Apr 10, 2018
1 parent 84f9f17 commit 0305160
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ EXTVERSION = 1.1
DATA_built = $(EXTENSION)--$(EXTVERSION).sql $(EXTENSION)--1.0.sql
DATA = $(wildcard $(EXTENSION)--*--*.sql)
REGRESS = pg_cron-test
REGRESS_OPTS = --dbname=postgres

# compilation configuration
MODULE_big = $(EXTENSION)
Expand Down
14 changes: 14 additions & 0 deletions expected/pg_cron-test.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@ SELECT extversion FROM pg_extension WHERE extname='pg_cron';
1.1
(1 row)

-- Vacuum every day at 10:00am (GMT)
SELECT cron.schedule('0 10 * * *', 'VACUUM');
schedule
----------
1
(1 row)

-- Stop scheduling a job
SELECT cron.unschedule(1);
unschedule
------------
t
(1 row)

DROP EXTENSION pg_cron;
11 changes: 1 addition & 10 deletions pg_cron--1.0--1.1.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/* pg_cron--1.0--1.1.sql */

DO $$
BEGIN
BEGIN
ALTER TABLE cron.job ADD COLUMN active boolean not null default 'true';
EXCEPTION
WHEN duplicate_column THEN RAISE NOTICE 'column <active> already exists in <cron.job>.';
END;
END;
$$

ALTER TABLE cron.job ADD COLUMN active boolean not null default 'true';
7 changes: 7 additions & 0 deletions sql/pg_cron-test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ CREATE EXTENSION pg_cron VERSION '1.0';
SELECT extversion FROM pg_extension WHERE extname='pg_cron';
ALTER EXTENSION pg_cron UPDATE TO '1.1';
SELECT extversion FROM pg_extension WHERE extname='pg_cron';

-- Vacuum every day at 10:00am (GMT)
SELECT cron.schedule('0 10 * * *', 'VACUUM');

-- Stop scheduling a job
SELECT cron.unschedule(1);

DROP EXTENSION pg_cron;
17 changes: 12 additions & 5 deletions src/job_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ cron_schedule(PG_FUNCTION_ARGS)

char *schedule = text_to_cstring(scheduleText);
char *command = text_to_cstring(commandText);

entry *parsedSchedule = NULL;

int64 jobId = 0;
Expand Down Expand Up @@ -205,7 +204,6 @@ cron_schedule(PG_FUNCTION_ARGS)
values[Anum_cron_job_database - 1] = CStringGetTextDatum(CronTableDatabaseName);
values[Anum_cron_job_username - 1] = CStringGetTextDatum(userName);


cronSchemaId = get_namespace_oid(CRON_SCHEMA_NAME, false);
cronJobsRelationId = get_relname_relid(JOBS_TABLE_NAME, cronSchemaId);

Expand Down Expand Up @@ -557,8 +555,6 @@ TupleToCronJob(TupleDesc tupleDescriptor, HeapTuple heapTuple)
tupleDescriptor, &isNull);
Datum userName = heap_getattr(heapTuple, Anum_cron_job_username,
tupleDescriptor, &isNull);
Datum active = heap_getattr(heapTuple, Anum_cron_job_active,
tupleDescriptor, &isNull);

Assert(!HeapTupleHasNulls(heapTuple));

Expand All @@ -572,7 +568,18 @@ TupleToCronJob(TupleDesc tupleDescriptor, HeapTuple heapTuple)
job->nodePort = DatumGetInt32(nodePort);
job->userName = TextDatumGetCString(userName);
job->database = TextDatumGetCString(database);
job->active = DatumGetBool(active);

if (HeapTupleHeaderGetNatts(heapTuple->t_data) >= Anum_cron_job_active)
{
Datum active = heap_getattr(heapTuple, Anum_cron_job_active,
tupleDescriptor, &isNull);
Assert(!isNull);
job->active = DatumGetBool(active);
}
else
{
job->active = true;
}

parsedSchedule = parse_cron_entry(job->scheduleText);
if (parsedSchedule != NULL)
Expand Down

0 comments on commit 0305160

Please sign in to comment.