Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fad2e22

Browse files
author
Vladimir Ershov
committed
run tasks but still fail sometimes
1 parent 5f85e54 commit fad2e22

10 files changed

+401
-108
lines changed

src/memutils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ MemoryContext init_worker_mem_ctx(const char *name)
1515
return SchedulerWorkerContext;
1616
}
1717

18+
MemoryContext switch_to_worker_context(void)
19+
{
20+
AssertState(SchedulerWorkerContext != NULL);
21+
return MemoryContextSwitchTo(SchedulerWorkerContext);
22+
}
23+
1824
void *worker_alloc(Size size)
1925
{
2026
AssertState(SchedulerWorkerContext != NULL);

src/memutils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
extern MemoryContext SchedulerWorkerContext;
88

99
MemoryContext init_worker_mem_ctx(const char *name);
10+
MemoryContext switch_to_worker_context(void);
1011
void *worker_alloc(Size size);
1112
void delete_worker_mem_ctx(void);
1213

src/pgpro_scheduler.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ worker_spi_sigterm(SIGNAL_ARGS)
6363
errno = save_errno;
6464
}
6565

66+
/** Some utils **/
67+
6668
TimestampTz timestamp_add_seconds(TimestampTz to, int add)
6769
{
6870
if(to == 0) to = GetCurrentTimestamp();
@@ -72,6 +74,63 @@ TimestampTz timestamp_add_seconds(TimestampTz to, int add)
7274
return add + to;
7375
}
7476

77+
int get_integer_from_string(char *s, int start, int len)
78+
{
79+
char buff[100];
80+
81+
memcpy(buff, s + start, len);
82+
buff[len] = 0;
83+
return atoi(buff);
84+
}
85+
86+
char *make_date_from_timestamp(TimestampTz ts)
87+
{
88+
struct pg_tm dt;
89+
char *str = worker_alloc(sizeof(char) * 17);
90+
int tz;
91+
fsec_t fsec;
92+
const char *tzn;
93+
94+
timestamp2tm(ts, &tz, &dt, &fsec, &tzn, NULL ); /* TODO ERROR */
95+
sprintf(str, "%04d-%02d-%02d %02d:%02d", dt.tm_year , dt.tm_mon,
96+
dt.tm_mday, dt.tm_hour, dt.tm_min);
97+
return str;
98+
}
99+
100+
TimestampTz get_timestamp_from_string(char *str)
101+
{
102+
struct pg_tm dt;
103+
int tz;
104+
TimestampTz ts;
105+
106+
memset(&dt, 0, sizeof(struct tm));
107+
dt.tm_year = get_integer_from_string(str, 0, 4);
108+
dt.tm_mon = get_integer_from_string(str, 5, 2);
109+
dt.tm_mday = get_integer_from_string(str, 8, 2);
110+
dt.tm_hour = get_integer_from_string(str, 11, 2);
111+
dt.tm_min = get_integer_from_string(str, 14, 2);
112+
113+
tz = DetermineTimeZoneOffset(&dt, session_timezone);
114+
115+
tm2timestamp(&dt, 0, &tz, &ts);
116+
117+
return ts;
118+
}
119+
120+
TimestampTz _round_timestamp_to_minute(TimestampTz ts)
121+
{
122+
#ifdef HAVE_INT64_TIMESTAMP
123+
return ts - ts % USECS_PER_MINUTE;
124+
#else
125+
return ts - ts % SECS_PER_MINUTE;
126+
#endif
127+
}
128+
129+
130+
/** END of SOME UTILS **/
131+
132+
133+
75134
char_array_t *readBasesToCheck(void)
76135
{
77136
const char *value;

src/pgpro_scheduler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ void parent_scheduler_main(Datum) pg_attribute_noreturn();
2323
int checkSchedulerNamespace(void);
2424
void manager_worker_main(Datum arg);
2525
pid_t registerManagerWorker(schd_manager_t *man);
26+
2627
TimestampTz timestamp_add_seconds(TimestampTz to, int add);
28+
char *make_date_from_timestamp(TimestampTz ts);
29+
int get_integer_from_string(char *s, int start, int len);
30+
TimestampTz get_timestamp_from_string(char *str);
31+
TimestampTz _round_timestamp_to_minute(TimestampTz ts);
2732

2833
#endif

0 commit comments

Comments
 (0)