Skip to content

Commit

Permalink
Fix task timezone
Browse files Browse the repository at this point in the history
When set the GUC task_timezone, it will assign and check the new value
by hook function assign_timezone and show_timezone. But this two
functions are associated with system GUC timezone.

We should add our own hook function for this.
  • Loading branch information
roseduan committed Nov 4, 2024
1 parent 8dffe76 commit 6542e06
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/backend/task/pg_cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ char *task_timezone = "GMT";
int max_running_tasks = 5;
char *task_host_addr = "127.0.0.1";

static pg_tz *task_timezone_tz = NULL;

/* flags set by signal handlers */
static volatile sig_atomic_t got_sigterm = false;

Expand Down Expand Up @@ -298,6 +300,25 @@ bgw_generate_returned_message(StringInfoData *display_msg, ErrorData edata)
appendStringInfo(display_msg, "\nCONTEXT: %s", edata.context);
}

void
assign_task_timezone(const char *newval, void *extra)
{
task_timezone_tz = *((pg_tz **) extra);
}

const char *show_task_timezone(void)
{
const char *tzn;

/* Always show the zone's canonical name */
tzn = pg_get_timezone_name(task_timezone_tz);

if (tzn != NULL)
return tzn;

return "unknown";
}

bool PgCronStartRule(Datum main_arg)
{
return (Gp_role == GP_ROLE_DISPATCH);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/misc/guc_gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4733,7 +4733,7 @@ struct config_string ConfigureNamesString_gp[] =
},
&task_timezone,
"GMT",
check_timezone, assign_timezone, show_timezone
check_timezone, assign_task_timezone, show_task_timezone
},

{
Expand Down
2 changes: 2 additions & 0 deletions src/include/task/pg_cron.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ extern void CronBackgroundWorker(Datum arg);
extern pid_t PgCronLauncherPID(void);
extern Size PgCronLauncherShmemSize(void);
extern void PgCronLauncherShmemInit(void);
extern void assign_task_timezone(const char *newval, void *extra);
extern const char *show_task_timezone(void);

#endif /* PG_CRON_H */

0 comments on commit 6542e06

Please sign in to comment.