Skip to content

Commit

Permalink
Merge pull request #32 from dysosmus/partial-cronjob
Browse files Browse the repository at this point in the history
Partial cronjob (pull request of @dysosmus merged)
  • Loading branch information
Frédéric Guillot committed May 21, 2013
2 parents 5ada718 + 3c95af8 commit 11e4703
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
update*
make-archive.sh
*.sqlite
*.db
19 changes: 17 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,28 @@ FAQ

### How to update your feeds with a cronjob?

You just need to be inside the directory `miniflux` and run the script `cronjob.php`.
You just need to be inside the directory `miniflux` and run the script `cronjob.php`.

By example:
Prameters | Type | Value
-------------------|--------------------------------|-----------------------------
--limit | optional |time in minutes
--call-interval | optional, exclude by --limit, requires --update-interval |time in minutes < update inteval time
--update-interval | optional, exclude by --limit, requires --call-interval |time in minutes >= call interval time

Examples:

crontab -e

0 */4 * * * cd /path/to/miniflux && php cronjob.php >/dev/null 2>&1

# Updates the 10 oldest feeds each time

0 */4 * * * cd /path/to/miniflux && php cronjob.php --limit=10 >/dev/null 2>&1

# Updates all feeds in 60mn (updates the 8 oldest feeds each time with a total of 120 feeds).

0 */4 * * * cd /path/to/miniflux && php cronjob.php --call-interval=4 --update-interval=60 >/dev/null 2>&1

### How Miniflux update my feeds from the user interface?

Expand Down
12 changes: 8 additions & 4 deletions miniflux/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
require 'model.php';


const DB_VERSION = 4;
const APP_VERSION = 'master';
const DB_VERSION = 5;
const APP_VERSION = 'master';
const APP_USERAGENT = 'Miniflux - http://miniflux.net';
const HTTP_TIMEOUT = 5;

const HTTP_TIMEOUT = 5;
const LIMIT_ALL = -1;

function get_db_filename()
{
return 'data/db.sqlite';
}

function is_console()
{
return php_sapi_name() === 'cli';
}

PicoTools\container('db', function() {

Expand Down
21 changes: 19 additions & 2 deletions miniflux/cronjob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<?php

require 'common.php';

Model\update_feeds();
if(is_console()) {
$options = getopt('', array(
'limit::',
'call-interval::',
'update-interval::'
));

$limit = empty($options['limit']) ? LIMIT_ALL : (int)$options['limit'];
$update_interval = empty($options['update-interval']) ? null : (int)$options['update-interval'];
$call_interval = empty($options['call-interval']) ? null : (int)$options['call-interval'];

if($update_interval !== null && $call_interval !== null && $limit === LIMIT_ALL && $update_interval >= $call_interval) {

$feeds_count = \PicoTools\singleton('db')->table('feeds')->count();
$limit = ceil($feeds_count / ( $update_interval / $call_interval )) ; // compute new limit
}

Model\update_feeds($limit);
}
36 changes: 27 additions & 9 deletions miniflux/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ function import_feed($url)
return false;
}


function update_feeds()
function update_feeds($limit = LIMIT_ALL)
{
foreach (get_feeds_id() as $feed_id) {
$feeds_id = get_feeds_id($limit);

foreach ($feeds_id as $feed_id) {

update_feed($feed_id);
}
Expand All @@ -134,6 +135,8 @@ function update_feed($feed_id)
APP_USERAGENT
);

update_feed_last_checked($feed_id);

if (! $resource->isModified()) {

return true;
Expand All @@ -158,12 +161,18 @@ function update_feed($feed_id)
}


function get_feeds_id()
function get_feeds_id($limit = LIMIT_ALL)
{
return \PicoTools\singleton('db')
->table('feeds')
->asc('updated')
->listing('id', 'id');
$table_feeds = \PicoTools\singleton('db')->table('feeds')
->asc('last_checked');

if($limit !== LIMIT_ALL) {

$table_feeds->limit((int)$limit);
}

return $table_feeds->listing('id', 'id');

}


Expand All @@ -184,6 +193,14 @@ function get_feed($feed_id)
->findOne();
}

function update_feed_last_checked($feed_id) {
\PicoTools\singleton('db')
->table('feeds')
->eq('id', $feed_id)
->save(array(
'last_checked' => time(),
));
}

function update_feed_cache_infos($feed_id, $last_modified, $etag)
{
Expand All @@ -192,7 +209,8 @@ function update_feed_cache_infos($feed_id, $last_modified, $etag)
->eq('id', $feed_id)
->save(array(
'last_modified' => $last_modified,
'etag' => $etag
'etag' => $etag,
'last_checked' => time(),
));
}

Expand Down
4 changes: 4 additions & 0 deletions miniflux/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Schema;

function version_5($pdo)
{
$pdo->exec('ALTER TABLE feeds ADD COLUMN last_checked INTEGER');
}

function version_4($pdo)
{
Expand Down
1 change: 0 additions & 1 deletion miniflux/templates/read_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<p class="alert alert-info"><?= t('Item not found') ?></p>

<?php else: ?>

<article class="item" id="current-item" data-item-id="<?= urlencode($item['id']) ?>">
<h1>
<a href="<?= $item['url'] ?>" rel="noreferrer" target="_blank" id="original-item"><?= Helper\escape($item['title']) ?></a>
Expand Down

0 comments on commit 11e4703

Please sign in to comment.