Skip to content

Commit

Permalink
Replace pg_usleep with WaitLatch, check for postmaster death
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoslot committed Dec 15, 2016
1 parent 73ed99f commit ddb0e53
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/pg_cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ static void
pg_cron_sigterm(SIGNAL_ARGS)
{
got_sigterm = true;

if (MyProc != NULL)
{
SetLatch(&MyProc->procLatch);
}
}


Expand All @@ -183,6 +188,11 @@ static void
pg_cron_sighup(SIGNAL_ARGS)
{
CronJobCacheValid = false;

if (MyProc != NULL)
{
SetLatch(&MyProc->procLatch);
}
}


Expand Down Expand Up @@ -552,8 +562,19 @@ WaitForCronTasks(List *taskList)
}
else
{
/* wait for new jobs */
pg_usleep(MaxWait*1000L);
int rc = 0;
int waitFlags = WL_LATCH_SET | WL_POSTMASTER_DEATH;

/* nothing to do, wait for new jobs */
rc = WaitLatch(MyLatch, waitFlags, MaxWait);

ResetLatch(MyLatch);

if (rc & WL_POSTMASTER_DEATH)
{
/* postmaster died and we should bail out immediately */
proc_exit(1);
}
}
}

Expand Down

0 comments on commit ddb0e53

Please sign in to comment.