Ticket #2194: housekeeper.2.diff

File housekeeper.2.diff, 1.8 KB (added by willu.mailingLists@…, 19 years ago)

Add some sanity checking and break some of the longer lines

  • mythtv/programs/mythbackend/housekeeper.cpp

     
    5050    unsigned int longEnough = 0;
    5151
    5252    if (period)
    53         longEnough = ((period * oneday) - 600);
     53        longEnough = ((period * oneday) - oneday/2);
    5454    else
    5555        longEnough = oneday / 8;
    5656
     
    5858    QDateTime lastrun;
    5959    lastrun.setTime_t(0);
    6060
     61    if (minhour < 0)
     62        minhour = 0;
     63    if (maxhour > 23)
     64        maxhour = 23;
     65    if (minhour > maxhour)
     66    {
     67        VERBOSE(VB_GENERAL,
     68            "Housekeeping thread will not run: supplied time range is empty");
     69    }
     70
    6171    MSqlQuery result(MSqlQuery::InitCon());
    6272    if (result.isConnected())
    6373    {
     
    6979            result.next();
    7080            lastrun = result.value(0).toDateTime();
    7181
    72             if ((now.toTime_t() - lastrun.toTime_t()) > longEnough)
     82            if ((now.toTime_t() - lastrun.toTime_t()) > longEnough &&
     83                (now.toString(QString("d")).toInt() !=
     84                     lastrun.toString(QString("d")).toInt()))
    7385            {
    7486                int hour = now.toString(QString("h")).toInt();
    7587                if ((hour >= minhour) && (hour <= maxhour))
    76                     runOK = true;
     88                {
     89                    int minute = now.toString(QString("m")).toInt();
     90                    if ((hour == maxhour && minute > 30) ||
     91                        ((random()%((maxhour-hour)*12+(60-minute)/5 - 6) == 0)))
     92                        runOK = true;
     93                }
    7794            }
    7895        }
    7996        else
     
    239256            updateLastrun(dbTag);
    240257        }
    241258
    242         sleep(300);
     259        sleep(300 + (random()%8));
    243260    }
    244261}
    245262