typedef struct cron
{
char *str; ///< String representation
+ time_t last; ///< Last execution time
uint64_t min; ///< Minutes
uint32_t hour; ///< Hours
uint32_t dom; ///< Day of month
return save;
}
-int cron_is_time ( cron_t *cron )
+time_t cron_run ( cron_t *cron )
{
+ time_t t;
+ struct tm now;
int ret = 1;
uint64_t b = 0x1;
/* Get the current time */
- time_t t = time(NULL);
- struct tm now;
- localtime_r(&t, &now);
-
+ time(&t);
+ localtime_t(&t, &now);
+
+ /* Find next event */
+ if ( now->min == cron->last->min) {
+
+ }
+
/* Check */
if ( ret && !((b << now.tm_min) & cron->min) ) ret = 0;
if ( ret && !((b << now.tm_hour) & cron->hour) ) ret = 0;
return ret;
}
-// TODO: use this as part of cron_next/cron_is_time
-void cron_run ( cron_t *cron )
-{
-}
-
-// TODO: do proper search for next time
-time_t cron_next ( cron_t *cron )
-{
- time_t now;
- time(&now);
- now += 62; // TODO: hack because timer goes off just before second tick
- now /= 60;
- now *= 60;
- return now;
-}
-
-
void cron_serialize ( cron_t *cron, htsmsg_t *msg )
{
htsmsg_add_str(msg, "cron", cron->str);
void cron_destroy ( cron_t *cron );
const char *cron_get_string ( cron_t *cron );
int cron_set_string ( cron_t *cron, const char *str );
-int cron_is_time ( cron_t *cron );
-time_t cron_next ( cron_t *cron );
-void cron_run ( cron_t *cron );
+int cron_run ( cron_t *cron, time_t *next );
void cron_serialize ( cron_t *cron, htsmsg_t *msg );
cron_t *cron_deserialize ( htsmsg_t *msg );
*/
static time_t _epggrab_thread_advanced ( void )
{
- time_t ret, now;
+ time_t now, ret, tmp;
epggrab_sched_t *s;
/* Determine which to run */
time(&now);
- ret = now + 3600; // default
+ ret = now + 3600; // once an hour if no entries
TAILQ_FOREACH(s, &epggrab_schedule, link) {
- if ( cron_is_time(s->cron) ) {
- cron_run(s->cron);
+ if ( cron_run(s->cron, &tmp) ) {
+ ret = now; // re-run immediately
_epggrab_module_run(s->mod, s->cmd, s->opts);
- return now + 10;
// TODO: don't try to interate the list, it'll break due to locking
// module (i.e. _epggrab_module_run() unlocks)
} else {
- ret = MIN(ret, cron_next(s->cron));
+ ret = MIN(ret, tmp);
}
}
- return ret;//now + 30;
+ return ret;
}
/*