<commit_before>CREATE OR REPLACE FUNCTION cron.Schedule(_Function regprocedure, _ProcessID integer DEFAULT NULL)
RETURNS boolean
LANGUAGE plpgsql
SET search_path TO public, pg_temp
AS $FUNC$
DECLARE
_OK boolean;
BEGIN

IF _ProcessID IS NULL THEN
    SELECT cron.Processes.ProcessID INTO _ProcessID FROM cron.Jobs
    INNER JOIN cron.Processes ON (cron.Processes.JobID = cron.Jobs.JobID)
    WHERE cron.Jobs.Function = _Function::text
    LIMIT 1;
END IF;

UPDATE cron.Processes SET RunAtTime = now() WHERE ProcessID = _ProcessID RETURNING TRUE INTO STRICT _OK;
PERFORM pg_notify('cron.Dispatch()',_ProcessID::text);

RETURN TRUE;
END;
$FUNC$;

ALTER FUNCTION cron.Schedule(_Function regprocedure, _ProcessID integer) OWNER TO pgcronjob;<commit_msg>Fix cron.Schedule() to reset cron.Processes.RunAtTime when a job has been killed<commit_after>CREATE OR REPLACE FUNCTION cron.Schedule(_Function regprocedure, _ProcessID integer DEFAULT NULL)
RETURNS boolean
LANGUAGE plpgsql
SET search_path TO public, pg_temp
AS $FUNC$
DECLARE
_OK boolean;
BEGIN

IF _ProcessID IS NULL THEN
    SELECT cron.Processes.ProcessID INTO _ProcessID FROM cron.Jobs
    INNER JOIN cron.Processes ON (cron.Processes.JobID = cron.Jobs.JobID)
    WHERE cron.Jobs.Function = _Function::text
    LIMIT 1;
END IF;

UPDATE cron.Processes SET RunAtTime = CASE WHEN RunAtTime > now() THEN now() ELSE NULL END WHERE ProcessID = _ProcessID RETURNING TRUE INTO STRICT _OK;
PERFORM pg_notify('cron.Dispatch()',_ProcessID::text);

RETURN TRUE;
END;
$FUNC$;

ALTER FUNCTION cron.Schedule(_Function regprocedure, _ProcessID integer) OWNER TO pgcronjob;
{'fraction_non_alphanumeric': 0.07453416149068323, 'fraction_numerical': 0.0012422360248447205, 'mean_word_length': 5.418326693227091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6053547', 'n_tokens_mistral': 549, 'n_tokens_neox': 503, 'n_words': 171}