aboutsummaryrefslogtreecommitdiffstats
path: root/include/poller.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-09-30 18:33:27 -0700
committerfriendica <info@friendica.com>2013-09-30 18:33:27 -0700
commite992cfeca9a80583b7cde12776fcfe279be02996 (patch)
tree8e36d5f0a350fa5f1fae4c931c4a4028c5ac62a7 /include/poller.php
parente0391de90674e759a73d08517641e6207606493f (diff)
downloadvolse-hubzilla-e992cfeca9a80583b7cde12776fcfe279be02996.tar.gz
volse-hubzilla-e992cfeca9a80583b7cde12776fcfe279be02996.tar.bz2
volse-hubzilla-e992cfeca9a80583b7cde12776fcfe279be02996.zip
directory sync - this will either work, or it won't work, or it will possibly recurse and blow up the matrix. Hard to say. Do you feel lucky? Well do ya' ... punk? Rule #1 - don't mess with anything unless it's blowing up the matrix. If it doesn't blow up the matrix, but doesn't work, just let it go and let's figure out what it is doing and what it isn't doing.
The flow is as follows: Once a day go out to all the directory servers besides yourself and grab a list of updates. This happens in the poller. If we've never seen them before add them to the updates table. The poller also looks to see if we're a directory server and have updates that haven't yet been processed. It calls onedirsync.php to process each one. If we contact the channel to update and don't find anything (we're just doing a basic zot_finger), set a ud_last timestamp. If this is set we will only try once a day for seven days. Then we stop trying to update. This will probably cause a spike the first time through because you haven't seen any updates before, but we spread out the load over your delivery interval.
Diffstat (limited to 'include/poller.php')
-rw-r--r--include/poller.php128
1 files changed, 74 insertions, 54 deletions
diff --git a/include/poller.php b/include/poller.php
index f084005c7..05584a05d 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -69,6 +69,8 @@ function poller_run($argv, $argc){
$d1 = get_config('system','last_expire_day');
$d2 = intval(datetime_convert('UTC','UTC','now','d'));
+ $dirmode = get_config('system','directory_mode');
+
if($d2 != intval($d1)) {
// If this is a directory server, request a sync with an upstream
@@ -76,7 +78,6 @@ function poller_run($argv, $argc){
// Pull remote changes and push local changes.
// potential issue: how do we keep from creating an endless update loop?
- $dirmode = get_config('system','directory_mode');
if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
require_once('include/dir_fns.php');
sync_directories($dirmode);
@@ -171,76 +172,95 @@ function poller_run($argv, $argc){
);
- if(! $contacts) {
- return;
- }
+ if($contacts) {
- foreach($contacts as $contact) {
+ foreach($contacts as $contact) {
- $update = false;
+ $update = false;
- $t = $contact['abook_updated'];
- $c = $contact['abook_connected'];
+ $t = $contact['abook_updated'];
+ $c = $contact['abook_connected'];
- if($c == $t) {
- if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
- $update = true;
- }
- else {
- // if we've never connected with them, start the mark for death countdown from now
-
- if($c == '0000-00-00 00:00:00') {
- $r = q("update abook set abook_connected = '%s' where abook_id = %d limit 1",
- dbesc(datetime_convert()),
- intval($contact['abook_id'])
- );
- $c = datetime_convert();
- $update = true;
+ if($c == $t) {
+ if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
+ $update = true;
}
+ else {
+ // if we've never connected with them, start the mark for death countdown from now
+
+ if($c == '0000-00-00 00:00:00') {
+ $r = q("update abook set abook_connected = '%s' where abook_id = %d limit 1",
+ dbesc(datetime_convert()),
+ intval($contact['abook_id'])
+ );
+ $c = datetime_convert();
+ $update = true;
+ }
+
+ // He's dead, Jim
+
+ if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) {
+ $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1",
+ intval(ABOOK_FLAG_ARCHIVED),
+ intval($contact['abook_id'])
+ );
+ $update = false;
+ continue;
+ }
+
+ if($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) {
+ $update = false;
+ continue;
+ }
+
+ // might be dead, so maybe don't poll quite so often
+
+ // recently deceased, so keep up the regular schedule for 3 days
+
+ if((strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 3 day")) > 0)
+ && (strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 1 day")) > 0))
+ $update = true;
- // He's dead, Jim
+ // After that back off and put them on a morphine drip
+
+ if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) {
+ $update = true;
+ }
- if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) {
- $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1",
- intval(ABOOK_FLAG_ARCHIVED),
- intval($contact['abook_id'])
- );
- $update = false;
- continue;
- }
- if($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) {
- $update = false;
- continue;
}
- // might be dead, so maybe don't poll quite so often
+ if((! $update) && (! $force))
+ continue;
- // recently deceased, so keep up the regular schedule for 3 days
-
- if((strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 3 day")) > 0)
- && (strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 1 day")) > 0))
- $update = true;
+ proc_run('php','include/onepoll.php',$contact['abook_id']);
+ if($interval)
+ @time_sleep_until(microtime(true) + (float) $interval);
- // After that back off and put them on a morphine drip
+ }
+ }
- if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) {
- $update = true;
+ if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) {
+ $r = q("select ud_id from updates where not ( ud_flags & %d ) and ( ud_last = '0000-00-00 00:00:00' OR ud_last > UTC_TIMESTAMP() - INTERVAL 7 DAYS) ",
+ intval(UPDATE_FLAGS_UPDATED)
+ );
+ if($r) {
+ foreach($r as $rr) {
+
+ // If they didn't respond when we attempted before, back off to once a day
+ // After 7 days we won't bother anymore
+
+ if($rr['ud_last'] != '0000-00-00 00:00:00')
+ if($rr['ud_last'] > datetime_convert('UTC','UTC', 'now - 1 day'))
+ continue;
+ proc_run('php','include/onedirsync.php',$rr['ud_id']);
+ if($interval)
+ @time_sleep_until(microtime(true) + (float) $interval);
}
-
-
}
-
- if((! $update) && (! $force))
- continue;
-
- proc_run('php','include/onepoll.php',$contact['abook_id']);
- if($interval)
- @time_sleep_until(microtime(true) + (float) $interval);
-
}
-
+
return;
}