miniflux-legacy/worker.php

49 lines
1.1 KiB
PHP
Raw Normal View History

2016-05-02 04:03:21 +02:00
<?php
use Pheanstalk\Pheanstalk;
2016-08-25 03:17:58 +02:00
use Miniflux\Model;
2016-05-02 04:03:21 +02:00
2016-08-19 03:02:49 +02:00
require __DIR__.'/app/common.php';
2016-05-02 04:03:21 +02:00
if (php_sapi_name() !== 'cli') {
die('This script can run only from the command line.'.PHP_EOL);
}
$options = getopt('', array(
'stop',
));
function check_job_left(Pheanstalk $connection, array $options)
{
if (isset($options['stop'])) {
$queues = $connection->listTubes();
if (in_array(BEANSTALKD_QUEUE, $queues)) {
$stats = $connection->statsTube(BEANSTALKD_QUEUE);
2016-05-03 10:45:07 +02:00
echo 'Jobs in queue: ', $stats->current_jobs_ready, PHP_EOL;
(int) $stats->current_jobs_ready === 0 && exit(0);
} else {
2016-05-03 10:45:07 +02:00
echo 'No queue', PHP_EOL;
exit(0);
}
}
}
2016-05-02 04:03:21 +02:00
$connection = new Pheanstalk(BEANSTALKD_HOST);
check_job_left($connection, $options);
2016-05-02 04:03:21 +02:00
while ($job = $connection->reserveFromTube(BEANSTALKD_QUEUE)) {
$feed_id = $job->getData();
2016-05-03 10:45:07 +02:00
echo 'Processing feed_id=', $feed_id, PHP_EOL;
2016-05-02 04:03:21 +02:00
Model\Feed\refresh($feed_id);
2016-05-17 03:58:56 +02:00
Model\Item\autoflush_read();
Model\Item\autoflush_unread();
2016-05-02 04:03:21 +02:00
$connection->delete($job);
check_job_left($connection, $options);
2016-05-02 04:03:21 +02:00
}