Skip to content

Commit

Permalink
Make MythFillDatabaseTask run if it missed its original run window.
Browse files Browse the repository at this point in the history
This corrects an issue where MythFillDatabaseTask would never run if
performing its custom suggested time check and it had missed its
original window. This modifies the DailyHouseKeeperTask:InWindow
method to return true if it is beyond the initial window, but still
within the time frame limits set by 'MinHour' and 'MaxHour' database
settings.
  • Loading branch information
wagnerrp committed Jun 3, 2013
1 parent 0be46c8 commit f529c67
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mythtv/libs/libmythbase/housekeeper.cpp
Expand Up @@ -66,6 +66,7 @@ HouseKeeperTask::HouseKeeperTask(const QString &dbTag, HouseKeeperScope scope,

bool HouseKeeperTask::CheckRun(QDateTime now)
{
LOG(VB_GENERAL, LOG_DEBUG, QString("Checking to run %1").arg(GetTag()));
bool check = false;
if (!m_confirm && (check = DoCheckRun(now)))
// if m_confirm is already set, the task is already in the queue
Expand Down Expand Up @@ -278,6 +279,13 @@ bool PeriodicHouseKeeperTask::InWindow(QDateTime now)
return false;
}

bool PeriodicHouseKeeperTask::PastWindow(QDateTime now)
{
if (GetLastRun().secsTo(now) > m_windowElapsed.second)
return true;
return false;
}

DailyHouseKeeperTask::DailyHouseKeeperTask(const QString &dbTag,
HouseKeeperScope scope, HouseKeeperStartup startup) :
PeriodicHouseKeeperTask(dbTag, 86400, .5, 1.5, scope, startup),
Expand Down Expand Up @@ -308,6 +316,9 @@ void DailyHouseKeeperTask::CalculateWindow(void)
// so add a 30 minute buffer prior to the end of the window
if (GetLastRun().addSecs(m_windowElapsed.second) > tmp)
m_windowElapsed.second = GetLastRun().secsTo(tmp);

LOG(VB_GENERAL, LOG_DEBUG, QString("%1 Run window between %2 - %3.")
.arg(GetTag()).arg(m_windowElapsed.first).arg(m_windowElapsed.second));
}

void DailyHouseKeeperTask::SetHourWindow(int min, int max)
Expand All @@ -317,6 +328,21 @@ void DailyHouseKeeperTask::SetHourWindow(int min, int max)
CalculateWindow();
}

bool DailyHouseKeeperTask::InWindow(QDateTime now)
{
if (PeriodicHouseKeeperTask::InWindow(now))
// parent says we're in the window
return true;

int hour = now.time().hour();
if (PastWindow(now) && (m_windowHour.first <= hour)
&& (m_windowHour.second > hour))
// we've missed the window, but we're within our time constraints
return true;

return false;
}

void HouseKeepingThread::run(void)
{
m_waitMutex.lock();
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythbase/housekeeper.h
Expand Up @@ -78,6 +78,7 @@ class MBASE_PUBLIC PeriodicHouseKeeperTask : public HouseKeeperTask
HouseKeeperStartup startup=kHKNormal);
virtual bool DoCheckRun(QDateTime now);
virtual bool InWindow(QDateTime now);
virtual bool PastWindow(QDateTime now);
virtual QDateTime UpdateLastRun(QDateTime last);
virtual void SetLastRun(QDateTime last);
virtual void SetWindow(float min, float max);
Expand All @@ -101,6 +102,7 @@ class MBASE_PUBLIC DailyHouseKeeperTask : public PeriodicHouseKeeperTask
HouseKeeperScope scope=kHKGlobal,
HouseKeeperStartup startup=kHKNormal);
virtual void SetHourWindow(int min, int max);
virtual bool InWindow(QDateTime now);

protected:
virtual void CalculateWindow(void);
Expand Down
9 changes: 9 additions & 0 deletions mythtv/programs/mythbackend/backendhousekeeper.cpp
Expand Up @@ -494,8 +494,11 @@ bool MythFillDatabaseTask::UseSuggestedTime(void)
bool MythFillDatabaseTask::DoCheckRun(QDateTime now)
{
if (!gCoreContext->GetNumSetting("MythFillEnabled", 1))
{
// we don't want to run this manually, so abort early
LOG(VB_GENERAL, LOG_DEBUG, "MythFillDatabase is disabled. Cannot run.");
return false;
}

// if (m_running)
// // we're still running from the previous pass, so abort early
Expand All @@ -506,6 +509,9 @@ bool MythFillDatabaseTask::DoCheckRun(QDateTime now)
QDateTime nextRun = MythDate::fromString(
gCoreContext->GetSetting("MythFillSuggestedRunTime",
"1970-01-01T00:00:00"));
LOG(VB_GENERAL, LOG_DEBUG,
QString("MythFillDatabase scheduled to run at %1.")
.arg(nextRun.toString()));
if (nextRun > now)
// not yet time
return false;
Expand All @@ -517,8 +523,11 @@ bool MythFillDatabaseTask::DoCheckRun(QDateTime now)
return false;
}
else
{
// just let DailyHouseKeeperTask handle things
LOG(VB_GENERAL, LOG_DEBUG, "Performing daily run check.");
return DailyHouseKeeperTask::DoCheckRun(now);
}
}

bool MythFillDatabaseTask::DoRun(void)
Expand Down

0 comments on commit f529c67

Please sign in to comment.