Background jobs are not loading user settings properly

This commit is contained in:
Frederic Guillot 2017-01-15 18:03:53 -05:00
parent 4ab9ca165c
commit d9295207b0
2 changed files with 17 additions and 5 deletions

View File

@ -4,6 +4,7 @@ require __DIR__.'/app/common.php';
use Miniflux\Handler; use Miniflux\Handler;
use Miniflux\Model; use Miniflux\Model;
use Miniflux\Session\SessionStorage;
if (php_sapi_name() === 'cli') { if (php_sapi_name() === 'cli') {
$options = getopt('', array( $options = getopt('', array(
@ -25,17 +26,23 @@ if (php_sapi_name() === 'cli') {
$limit = get_cli_option('limit', $options); $limit = get_cli_option('limit', $options);
$update_interval = get_cli_option('update-interval', $options); $update_interval = get_cli_option('update-interval', $options);
$call_interval = get_cli_option('call-interval', $options); $call_interval = get_cli_option('call-interval', $options);
$session = SessionStorage::getInstance();
foreach (Model\User\get_all_user_ids() as $user_id) {
$session->flush();
$session->setUser(Model\User\get_user_by_id($user_id));
foreach (Model\User\get_all_users() as $user) {
if ($update_interval !== null && $call_interval !== null && $limit === null && $update_interval >= $call_interval) { if ($update_interval !== null && $call_interval !== null && $limit === null && $update_interval >= $call_interval) {
$feeds_count = Model\Feed\count_feeds($user['id']); $feeds_count = Model\Feed\count_feeds($user_id);
$current_limit = ceil($feeds_count / ($update_interval / $call_interval)); $current_limit = ceil($feeds_count / ($update_interval / $call_interval));
} else { } else {
$current_limit = $limit; $current_limit = $limit;
} }
Handler\Feed\update_feeds($user['id'], $current_limit); echo 'Update feeds for user_id='.$user_id.', limit='.$current_limit.PHP_EOL;
Model\Item\autoflush_read($user['id']);
Model\Item\autoflush_unread($user['id']); Handler\Feed\update_feeds($user_id, $current_limit);
Model\Item\autoflush_read($user_id);
Model\Item\autoflush_unread($user_id);
Miniflux\Helper\write_debug_file(); Miniflux\Helper\write_debug_file();
} }

View File

@ -2,6 +2,7 @@
use Miniflux\Handler; use Miniflux\Handler;
use Miniflux\Model; use Miniflux\Model;
use Miniflux\Session\SessionStorage;
use Pheanstalk\Pheanstalk; use Pheanstalk\Pheanstalk;
require __DIR__.'/app/common.php'; require __DIR__.'/app/common.php';
@ -11,6 +12,7 @@ if (php_sapi_name() !== 'cli') {
} }
$connection = new Pheanstalk(BEANSTALKD_HOST); $connection = new Pheanstalk(BEANSTALKD_HOST);
$session = SessionStorage::getInstance();
while ($job = $connection->reserveFromTube(BEANSTALKD_QUEUE)) { while ($job = $connection->reserveFromTube(BEANSTALKD_QUEUE)) {
$payload = unserialize($job->getData()); $payload = unserialize($job->getData());
@ -18,6 +20,9 @@ while ($job = $connection->reserveFromTube(BEANSTALKD_QUEUE)) {
echo 'Processing feed_id=', $payload['feed_id'], ' for user_id=', $payload['user_id']; echo 'Processing feed_id=', $payload['feed_id'], ' for user_id=', $payload['user_id'];
$session->flush();
$session->setUser(Model\User\get_user_by_id($payload['user_id']));
Handler\Feed\update_feed($payload['user_id'], $payload['feed_id']); Handler\Feed\update_feed($payload['user_id'], $payload['feed_id']);
Model\Item\autoflush_read($payload['user_id']); Model\Item\autoflush_read($payload['user_id']);
Model\Item\autoflush_unread($payload['user_id']); Model\Item\autoflush_unread($payload['user_id']);