@@ -156,6 +156,7 @@ public function createStatsTable()
156156 scheduled_time TIMESTAMP,
157157 end_time TIMESTAMP,
158158 tables TEXT,
159+ ids TEXT,
159160 force BOOLEAN,
160161 log TEXT
161162 );
@@ -379,6 +380,34 @@ public function getMappings(): array
379380 }
380381
381382
383+ /**
384+ *
385+ */
386+ public function getNextScheduled ()
387+ {
388+ $ result = $ this ->destination ->query ("
389+ SELECT
390+ id
391+ FROM
392+ devour_stats
393+ WHRE
394+ start_time IS NULL
395+ AND
396+ scheduled_time IS NOT NULL
397+ ORDER BY
398+ scheduled_time desc
399+ LIMIT
400+ 1
401+ " );
402+
403+ if (!$ result ->rowCount ()) {
404+ return NULL ;
405+ }
406+
407+ return (int ) $ result ->fetch (PDO ::FETCH_ASSOC )['id ' ];
408+ }
409+
410+
382411 /**
383412 *
384413 */
@@ -434,7 +463,7 @@ public function isRunning(): ?bool
434463 /**
435464 *
436465 */
437- public function schedule (array $ mappings = array (), $ scheduled_by = NULL ): array
466+ public function schedule (array $ mappings = array (), array $ ids = array (), $ scheduled_by = NULL ): array
438467 {
439468 $ this ->stat ();
440469
@@ -450,6 +479,9 @@ public function schedule(array $mappings = array(), $scheduled_by = NULL): array
450479 $ this ->statSet ('scheduled_by ' , $ scheduled_by );
451480 $ this ->statSet ('scheduled_time ' , date ('Y-m-d H:i:s ' ));
452481 $ this ->statSet ('tables ' , json_encode ($ mappings ));
482+ if (count ($ mappings ) == 1 ) {
483+ $ this ->statSet ('ids ' , json_encode ($ ids ));
484+ }
453485
454486 return $ this ->stat ;
455487 }
@@ -531,6 +563,7 @@ public function stat(): void
531563 'scheduled_time ' => NULL ,
532564 'end_time ' => NULL ,
533565 'tables ' => NULL ,
566+ 'ids ' => NULL ,
534567 'log ' => NULL ,
535568 'force ' => 0
536569 ];
@@ -564,9 +597,9 @@ public function statSet(string $column, string $value): void
564597 $ insert_statement = $ this ->destination ->prepare ("
565598 INSERT INTO
566599 devour_stats
567- (start_time, scheduled_by, scheduled_time, end_time, tables, force, log)
600+ (start_time, scheduled_by, scheduled_time, end_time, tables, ids, force, log)
568601 VALUES
569- (:start_time, :scheduled_by, :scheduled_time, :end_time, :tables, :force, :log)
602+ (:start_time, :scheduled_by, :scheduled_time, :end_time, :tables, :ids, : force, :log)
570603 " );
571604
572605 $ insert_statement ->execute ($ this ->stat );
@@ -585,6 +618,7 @@ public function statSet(string $column, string $value): void
585618 scheduled_time = :scheduled_time,
586619 end_time = :end_time,
587620 tables = :tables,
621+ ids = :ids,
588622 force = false,
589623 log = :log
590624 WHERE
0 commit comments