Skip to content

Commit

Permalink
move all feedwriter logging to emoncms log
Browse files Browse the repository at this point in the history
  • Loading branch information
Trystan Lea committed Apr 19, 2019
1 parent e9954ed commit b561ac1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions Modules/feed/engine/RedisBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,12 @@ private function process_feed_buffer($feedid){
// process if there is data on buffer and no write lock from real data
if ($len > 0 && !$this->checkLock($feedid,"write")) {
$this->setLock($feedid,"read"); // set read lock
echo "Processing feed=$feedid len=$len :\n";
$this->log->info("process_buffer() engine=$engine feed=$feedid len=$len");
$lasttime=0;
$range = 50000; // step range number of points to extract on each iteration 50k-100k is ok
for ($i=$range; $i<=$len+$range; $i++)
{
echo " Reading block $i\n";
$this->log->info(" Reading block $i");
if ($i > $len) $range = $range-($i-$len);
$i = $i + $range-1;
$buf_item = $this->redis->zRange("feed:$feedid:buffer", 0, $range-1, true);
Expand All @@ -218,13 +217,13 @@ private function process_feed_buffer($feedid){
$matchcnt++;
}
if ($matchcnt > 0) {
echo " Invoking post_bulk_save engine=" . $engine . "\n";
$this->log->info(" Invoking post_bulk_save engine=" . $engine);
$this->feed->EngineClass($engine)->post_bulk_save();
}

if ($range != $matchcnt) { echo "WARN: expected $range but found $matchcnt items\n"; }
if ($range != $matchcnt) { $this->log->info("WARN: expected $range but found $matchcnt items"); }
$remcnt = $this->redis->zRemRangeByRank("feed:$feedid:buffer", 0, $range-1); // Remove processed range
if ($remcnt != $matchcnt) { echo "WARN: found $matchcnt but deleted $remcnt items\n"; }
if ($remcnt != $matchcnt) { $this->log->info("WARN: found $matchcnt but deleted $remcnt items"); }
}
}
$this->removeLock($feedid,"read"); // remove read lock
Expand Down
10 changes: 5 additions & 5 deletions scripts/feedwriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
require "Lib/EmonLogger.php";
require "process_settings.php";

if (!$redis_enabled) { echo "Error: setting must be true: redis_enabled\n"; die; }
if (!$feed_settings['redisbuffer']['enabled']) { echo "Error: setting must be true: feed_settings['redisbuffer']['enabled']\n"; die; }
if (!$feed_settings['redisbuffer']['sleep'] || (int)$feed_settings['redisbuffer']['sleep'] < 1) { echo "Error: setting must be > 0 : feed_settings['redisbuffer']['sleep']\n"; die; }

$log = new EmonLogger(__FILE__);
$log->error("Starting feedwriter script");

if (!$redis_enabled) { $log->error("Error: setting must be true: redis_enabled"); die; }
if (!$feed_settings['redisbuffer']['enabled']) { $log->error("Error: setting must be true: feed_settings['redisbuffer']['enabled']"); die; }
if (!$feed_settings['redisbuffer']['sleep'] || (int)$feed_settings['redisbuffer']['sleep'] < 1) { $log->error("Error: setting must be > 0 : feed_settings['redisbuffer']['sleep']"); die; }

$mysqli = @new mysqli($server,$username,$password,$database,$port);
if ($mysqli->connect_error) { $log->error("Can't connect to database:". $mysqli->connect_error); die('Check log\n'); }
Expand Down Expand Up @@ -49,7 +49,7 @@
$feed->EngineClass(Engine::REDISBUFFER)->removeLock($feedid,"write");
}

echo "Buffered feed writer daemon started with sleep " . $feed_settings['redisbuffer']['sleep'] . "s...\n";
$log->info("Buffered feed writer daemon started with sleep " . $feed_settings['redisbuffer']['sleep'] . "s...");
while(true)
{
$feed->EngineClass(Engine::REDISBUFFER)->process_buffers();
Expand Down

0 comments on commit b561ac1

Please sign in to comment.