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

Commit 8c885c6

Browse files
author
Vladimir Ershov
committed
Merge commit '0e38b2ceed97de4740abfd6dc6a6c53ec25f43d5' into PGPROEE9_6_scheduler
2 parents e444800 + 0e38b2c commit 8c885c6

File tree

6 files changed

+29
-98
lines changed

6 files changed

+29
-98
lines changed

contrib/pgpro_scheduler/src/scheduler_job.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ job_t *set_job_error(job_t *j, const char *fmt, ...)
462462

463463
int move_job_to_log(job_t *j, bool status, bool process)
464464
{
465-
if(j->type == CronJob) _cron_move_job_to_log(j, status);
465+
if(j->type == CronJob) return _cron_move_job_to_log(j, status);
466466
return _at_move_job_to_log(j, status, process);
467467
}
468468

@@ -513,9 +513,9 @@ int move_at_job_process(int job_id)
513513
int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
514514
{
515515
char *this_error = NULL;
516-
Datum values[20];
517-
char nulls[20];
518-
Oid argtypes[20] = { INT4OID };
516+
Datum values[21];
517+
char nulls[21];
518+
Oid argtypes[21] = { INT4OID };
519519
bool canceled = false;
520520
int i;
521521
char *oldpath;
@@ -524,8 +524,9 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
524524
int n = 1;
525525
spi_response_t *r;
526526
spi_response_t *r2;
527+
527528
const char *get_sql = "select * from at_jobs_process where id = $1";
528-
const char *insert_sql = "insert into at_jobs_done values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)";
529+
const char *insert_sql = "insert into at_jobs_done values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21)";
529530
const char *delete_sql = "delete from at_jobs_process where id = $1";
530531
const char *resubmit_sql = "insert into at_jobs_submitted values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)";
531532

@@ -558,8 +559,10 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
558559
}
559560
argtypes[18] = BOOLOID;
560561
argtypes[19] = TEXTOID;
562+
argtypes[20] = TIMESTAMPTZOID;
561563
nulls[18] = ' ';
562564
nulls[19] = ' ';
565+
nulls[20] = ' ';
563566

564567
canceled = nulls[15] == 'n' ? false: DatumGetBool(values[15]);
565568

@@ -569,10 +572,11 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
569572
{
570573
this_error = _copy_string("job was canceled while processing: cannot resubmit");
571574
sql = insert_sql;
572-
n = 20;
575+
n = 21;
573576

574577
values[18] = BoolGetDatum(false);
575578
values[19] = CStringGetTextDatum(this_error);
579+
values[20] = TimestampTzGetDatum(GetCurrentTimestamp());
576580
}
577581
else if(job->attempt + 1 < job->resubmit_limit)
578582
{
@@ -585,15 +589,16 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
585589
{
586590
this_error = _copy_string("resubmit limit reached");
587591
sql = insert_sql;
588-
n = 20;
592+
n = 21;
589593

590594
values[18] = BoolGetDatum(false);
591595
values[19] = CStringGetTextDatum(this_error);
596+
values[20] = TimestampTzGetDatum(GetCurrentTimestamp());
592597
}
593598
}
594599
else
595600
{
596-
n = 20;
601+
n = 21;
597602
sql = insert_sql;
598603
if(error)
599604
{
@@ -605,6 +610,7 @@ int set_at_job_done(job_t *job, char *error, int64 resubmit, char **set_error)
605610
values[18] = BoolGetDatum(true);
606611
nulls[19] = 'n';
607612
}
613+
values[20] = TimestampTzGetDatum(GetCurrentTimestamp());
608614
}
609615
r2 = execute_spi_sql_with_args(sql, n, argtypes, values, nulls);
610616
if(this_error) pfree(this_error);

contrib/pgpro_scheduler/test/perl/t/jobError.t

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ my $dbh = DBI->connect("dbi:Pg:dbname=$dbname; host=$host", "$username", "$passw
1717
{PrintError => 0});
1818
ok($dbh->err == 0) or (print $DBI::errstr and BAIL_OUT);
1919

20-
my $query = "SELECT schedule.clean_log();";
21-
$dbh->do($query);
22-
ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
23-
24-
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test\",
20+
my $query = "SELECT schedule.create_job(\'{ \"name\": \"Test\",
2521
\"cron\": \"* * * * *\",
2622
\"command\": \"aaaaaaaaaa;\",
2723
\"run_as\": \"tester\",

contrib/pgpro_scheduler/test/perl/t/jobLastStartAvailable.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
5454
my $result = $sth->fetchrow_array() and $sth->finish();
5555
ok ($result == 0) or print "Count != 0\n";
5656

57+
$query = "SELECT count(*) FROM schedule.get_log() WHERE cron = $job_id AND status = 'error'";
58+
$sth = $dbh->prepare($query);
59+
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
60+
61+
my $result = $sth->fetchrow_array() and $sth->finish();
62+
ok ($result > 0) or print "Count == 0\n";
63+
5764
$query = "SELECT schedule.deactivate_job(?)";
5865
$sth = $dbh->prepare($query);
5966
$sth->bind_param(1, $job_id);

contrib/pgpro_scheduler/test/perl/t/jobMaxInstances.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ my $sth = $dbh->prepare($query);
3434
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
3535
my $job_id = $sth->fetchrow_array() and $sth->finish();
3636

37-
sleep 120;
37+
sleep 180;
3838
$query = "SELECT schedule.deactivate_job(?)";
3939
$sth = $dbh->prepare($query);
4040
$sth->bind_param(1, $job_id);
4141
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
4242
$sth->finish();
4343

44-
$query = "SELECT message FROM schedule.get_log() WHERE cron=$job_id AND status=\'error\' ORDER BY cron DESC LIMIT 1";
44+
$query = "SELECT message FROM schedule.get_log()
45+
WHERE cron=$job_id AND status=\'error\' AND message = 'max instances limit reached' LIMIT 1";
4546
my $sth = $dbh->prepare($query);
4647
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
4748
my $errorstr = $sth->fetchrow_array() and $sth->finish();

contrib/pgpro_scheduler/test/perl/t/jobMaxRunTime.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ok($dbh->err == 0) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL
2424
$query = "SELECT schedule.create_job(\'{ \"name\": \"Test 1\",
2525
\"cron\": \"*/3 * * * *\",
2626
\"commands\": [\"SELECT pg_sleep(120)\",
27-
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''createJob'')\"],
27+
\"INSERT INTO test_results (time_mark, commentary) VALUES(now(), ''jobMaxRunTime'')\"],
2828
\"run_as\": \"tester\",
2929
\"use_same_transaction\": \"true\",
3030
\"max_run_time\":\"00:01:00\"
@@ -34,7 +34,7 @@ my $sth = $dbh->prepare($query);
3434
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
3535
my $job_id = $sth->fetchrow_array() and $sth->finish();
3636

37-
sleep 250;
37+
sleep 180;
3838
$query = "SELECT count(*) FROM test_results";
3939
$sth = $dbh->prepare($query);
4040
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
@@ -48,7 +48,8 @@ $sth->bind_param(1, $job_id);
4848
ok($sth->execute(), $dbh->errstr) or print $DBI::errstr . "\n";
4949
$sth->finish();
5050

51-
$query = "SELECT message FROM schedule.get_log() WHERE cron=$job_id AND status=\'error\' ORDER BY cron DESC LIMIT 1";
51+
$query = "SELECT message FROM schedule.get_log()
52+
WHERE cron=$job_id AND status=\'error\' AND message = 'job timeout' LIMIT 1";
5253
my $sth = $dbh->prepare($query);
5354
ok($sth->execute()) or (print $DBI::errstr . "\n" and $dbh->disconnect() and BAIL_OUT);
5455

contrib/pgpro_scheduler/test/perl/t/jobOnStart.t

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)