Skip to content

Commit 2f72cc9

Browse files
author
Vladimir Ershov
committed
fix execution window
1 parent 3f85a66 commit 2f72cc9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/scheduler_manager.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ scheduler_task_t *scheduler_get_active_tasks(scheduler_manager_ctx_t *ctx, int *
378378

379379
*nt = 0;
380380
initStringInfo(&sql);
381-
appendStringInfo(&sql, "select id, rule, postpone, _next_exec_time, next_time_statement from cron where active and not broken and (start_date <= 'now' or start_date is null) and (end_date >= 'now' or end_date is null) and node = '%s'", ctx->nodename);
381+
appendStringInfo(&sql, "select id, rule, postpone, _next_exec_time, next_time_statement, start_date, end_date from cron where active and not broken and (start_date <= 'now' or start_date is null) and (end_date >= 'now' or end_date is null) and node = '%s'", ctx->nodename);
382382

383383
pgstat_report_activity(STATE_RUNNING, "select 'at' tasks");
384384

@@ -413,6 +413,8 @@ scheduler_task_t *scheduler_get_active_tasks(scheduler_manager_ctx_t *ctx, int *
413413
{
414414
tasks[i].has_next_time_statement = false;
415415
}
416+
tasks[i].date1 = get_timestamp_from_spi(NULL, i, 6, 0);
417+
tasks[i].date2 = get_timestamp_from_spi(NULL, i, 7, 0);
416418
}
417419
*nt = processed;
418420
}
@@ -622,6 +624,11 @@ TimestampTz *scheduler_calc_next_task_time(scheduler_task_t *task, TimestampTz s
622624

623625
*ntimes = 0;
624626

627+
if(task->date1 > 0 && task->date1 > stop) return NULL;
628+
if(task->date1 > 0 && task->date1 > start) start = task->date1;
629+
if(task->date2 > 0 && task->date2 < start) return NULL;
630+
if(task->date2 > 0 && task->date2 < stop) stop = task->date2;
631+
625632
if(first_time && jsonb_has_key(task->rule, "onstart"))
626633
{
627634
*ntimes = 1;
@@ -643,6 +650,8 @@ TimestampTz *scheduler_calc_next_task_time(scheduler_task_t *task, TimestampTz s
643650
return NULL;
644651
}
645652

653+
654+
646655
/* to avoid to set job on minute has already passed we add 1 minute */
647656
curr = start;
648657
#ifdef HAVE_INT64_TIMESTAMP

src/scheduler_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ typedef struct {
2323
TimestampTz postpone;
2424
TimestampTz next;
2525
bool has_next_time_statement;
26+
TimestampTz date1;
27+
TimestampTz date2;
2628
} scheduler_task_t;
2729

2830
typedef enum {

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