Browse Source
- Basic update service handles only one feed at a time and possibly leaks memory - Output for REST requests is still very basic - No avatar support - No reporting of whether cron works - No cleanup before or after feed updatesmicrosub
J. King
7 years ago
9 changed files with 193 additions and 31 deletions
@ -0,0 +1,10 @@ |
|||||
|
<?php |
||||
|
namespace JKingWeb\Arsse; |
||||
|
require_once __DIR__.DIRECTORY_SEPARATOR."bootstrap.php"; |
||||
|
Data::load(new Conf()); |
||||
|
|
||||
|
if(\PHP_SAPI=="cli") { |
||||
|
(new Service)->watch(); |
||||
|
} else { |
||||
|
(new REST)->dispatch(); |
||||
|
} |
@ -1,3 +0,0 @@ |
|||||
<?php |
|
||||
require_once __DIR__.DIRECTORY_SEPARATOR."bootstrap.php"; |
|
||||
Data::load(new Conf()); |
|
@ -0,0 +1,42 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse; |
||||
|
|
||||
|
class Service { |
||||
|
|
||||
|
/** |
||||
|
* @var Service\Driver |
||||
|
*/ |
||||
|
protected $drv; |
||||
|
/** |
||||
|
* @var \DateInterval |
||||
|
*/ |
||||
|
protected $interval; |
||||
|
|
||||
|
function __construct() { |
||||
|
$driver = Data::$conf->serviceDriver; |
||||
|
$this->drv = new $driver(); |
||||
|
$this->interval = new \DateInterval(Data::$conf->serviceFrequency); // FIXME: this needs to fall back in case of incorrect input |
||||
|
} |
||||
|
|
||||
|
function watch() { |
||||
|
while(true) { |
||||
|
$t = new \DateTime(); |
||||
|
$list = Data::$db->feedListStale(); |
||||
|
if($list) { |
||||
|
echo date("H:i:s")." Updating feeds ".json_encode($list)."\n"; |
||||
|
// TODO: pre-cleanup |
||||
|
$this->drv->queue(...$list); |
||||
|
$this->drv->exec(); |
||||
|
$this->drv->clean(); |
||||
|
// TODO: post-cleanup |
||||
|
} else { |
||||
|
echo date("H:i:s")." No feeds to update; sleeping\n"; |
||||
|
} |
||||
|
$t->add($this->interval); |
||||
|
do { |
||||
|
@time_sleep_until($t->getTimestamp()); |
||||
|
} while($t->getTimestamp() > time()); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse\Service; |
||||
|
|
||||
|
interface Driver { |
||||
|
static function driverName(): string; |
||||
|
static function requirementsMet(): bool; |
||||
|
function queue(int ...$feeds): int; |
||||
|
function exec(): int; |
||||
|
function clean(): bool; |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
namespace JKingWeb\Arsse\Service\Internal; |
||||
|
use JKingWeb\Arsse\Data; |
||||
|
|
||||
|
class Driver implements \JKingWeb\Arsse\Service\Driver { |
||||
|
protected $queue = []; |
||||
|
|
||||
|
static function driverName(): string { |
||||
|
return Data::$lang->msg("Driver.Service.Internal.Name"); |
||||
|
} |
||||
|
|
||||
|
static function requirementsMet(): bool { |
||||
|
// this driver has no requirements |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
function __construct() { |
||||
|
} |
||||
|
|
||||
|
function queue(int ...$feeds): int { |
||||
|
$this->queue = array_merge($this->queue, $feeds); |
||||
|
return sizeof($this->queue); |
||||
|
} |
||||
|
|
||||
|
function exec(): int { |
||||
|
while(sizeof($this->queue)) { |
||||
|
$id = array_shift($this->queue); |
||||
|
Data::$db->feedUpdate($id); |
||||
|
} |
||||
|
return Data::$conf->serviceQueueWidth - sizeof($this->queue); |
||||
|
} |
||||
|
|
||||
|
function clean(): bool { |
||||
|
$this->queue = []; |
||||
|
return true; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue