From 39bc0664a773a97ccce276161739f217e3ba7449 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 19 May 2016 21:22:04 -0700 Subject: Separate cron into periodic components and use that as the main interface for scheduled tasks instead of the quaint 'poller'. --- Zotlabs/Daemon/Cron.php | 181 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 Zotlabs/Daemon/Cron.php (limited to 'Zotlabs/Daemon/Cron.php') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php new file mode 100644 index 000000000..63078edd7 --- /dev/null +++ b/Zotlabs/Daemon/Cron.php @@ -0,0 +1,181 @@ + $maxsysload) { + logger('system: load ' . $load . ' too high. Cron deferred to next scheduled run.'); + return; + } + } + + // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. + $lockfile = 'store/[data]/cron'; + if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600)) + && (! get_config('system','override_cron_lockfile'))) { + logger("cron: Already running"); + return; + } + + // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. + file_put_contents($lockfile, $x); + + logger('cron: start'); + + // run queue delivery process in the background + + Master::Summon(array('Queue')); + + Master::Summon(array('Poller')); + + // maintenance for mod sharedwithme - check for updated items and remove them + + require_once('include/sharedwithme.php'); + apply_updates(); + + + // expire any expired mail + + q("delete from mail where expires != '%s' and expires < %s ", + dbesc(NULL_DATE), + db_utcnow() + ); + + // expire any expired items + + $r = q("select id from item where expires != '%s' and expires < %s + and item_deleted = 0 ", + dbesc(NULL_DATE), + db_utcnow() + ); + if($r) { + require_once('include/items.php'); + foreach($r as $rr) + drop_item($rr['id'],false); + } + + + // Ensure that every channel pings a directory server once a month. This way we can discover + // channels and sites that quietly vanished and prevent the directory from accumulating stale + // or dead entries. + + $r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s", + db_utcnow(), + db_quoteinterval('30 DAY') + ); + if($r) { + foreach($r as $rr) { + Master::Summon(array('Directory',$rr['channel_id'],'force')); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); + } + } + + // publish any applicable items that were set to be published in the future + // (time travel posts). Restrict to items that have come of age in the last + // couple of days to limit the query to something reasonable. + + $r = q("select id from item where item_delayed = 1 and created <= %s and created > '%s' ", + db_utcnow(), + dbesc(datetime_convert('UTC','UTC','now - 2 days')) + ); + if($r) { + foreach($r as $rr) { + $x = q("update item set item_delayed = 0 where id = %d", + intval($rr['id']) + ); + if($x) { + Master::Summon(array('Notifier','wall-new',$rr['id'])); + } + } + } + + $abandon_days = intval(get_config('system','account_abandon_days')); + if($abandon_days < 1) + $abandon_days = 0; + + + // once daily run birthday_updates and then expire in background + + // FIXME: add birthday updates, both locally and for xprof for use + // by directory servers + + $d1 = intval(get_config('system','last_expire_day')); + $d2 = intval(datetime_convert('UTC','UTC','now','d')); + + // Allow somebody to staggger daily activities if they have more than one site on their server, + // or if it happens at an inconvenient (busy) hour. + + $h1 = intval(get_config('system','cron_hour')); + $h2 = intval(datetime_convert('UTC','UTC','now','G')); + + + if(($d2 != $d1) && ($h1 == $h2)) { + Master::Summon('Cron_daily'); + } + + // update any photos which didn't get imported properly + // This should be rare + + $r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = '' + and xchan_photo_date < %s - INTERVAL %s", + db_utcnow(), + db_quoteinterval('1 DAY') + ); + if($r) { + require_once('include/photo/photo_driver.php'); + foreach($r as $rr) { + $photos = import_xchan_photo($rr['xchan_photo_l'],$rr['xchan_hash']); + $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' + where xchan_hash = '%s'", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($rr['xchan_hash']) + ); + } + } + + + // pull in some public posts + + if(! get_config('system','disable_discover_tab')) + Master::Summon(array('Externals')); + + $generation = 0; + + $restart = false; + + if(($argc > 1) && ($argv[1] == 'restart')) { + $restart = true; + $generation = intval($argv[2]); + if(! $generation) + killme(); + } + + reload_plugins(); + + $d = datetime_convert(); + + // TODO check to see if there are any cronhooks before wasting a process + + if(! $restart) + Master::Summon(array('Cronhooks')); + + set_config('system','lastcron',datetime_convert()); + + //All done - clear the lockfile + @unlink($lockfile); + + return; + } +} -- cgit v1.2.3 From a2cec8899ad191b47d116f4ea124be6bd5b05472 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 19 May 2016 22:26:37 -0700 Subject: daemon conversion continued... --- Zotlabs/Daemon/Cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Daemon/Cron.php') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index 63078edd7..f23cb14dc 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -119,7 +119,7 @@ class Cron { if(($d2 != $d1) && ($h1 == $h2)) { - Master::Summon('Cron_daily'); + Master::Summon(array('Cron_daily')); } // update any photos which didn't get imported properly -- cgit v1.2.3 From bd403276f2884ce8cd28102aa613a4de40aad6db Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 30 Jun 2016 21:27:59 -0700 Subject: disable wiki if feature disabled, sync updates of delayed publish posts --- Zotlabs/Daemon/Cron.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Daemon/Cron.php') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index f23cb14dc..d5b41274b 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -41,7 +41,6 @@ class Cron { require_once('include/sharedwithme.php'); apply_updates(); - // expire any expired mail q("delete from mail where expires != '%s' and expires < %s ", @@ -93,6 +92,18 @@ class Cron { intval($rr['id']) ); if($x) { + $z = q("select * from item where id = %d", + intval($message_id) + ); + if($z) { + xchan_query($z); + $sync_item = fetch_post_tags($z); + build_sync_packet($sync_item[0]['uid'], + [ + 'item' => [ encode_item($sync_item[0],true) ] + ] + ); + } Master::Summon(array('Notifier','wall-new',$rr['id'])); } } -- cgit v1.2.3 From 01fe7d6620644daa8c73ed34aa5b9e4bf832db15 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Fri, 15 Jul 2016 17:34:44 -0700 Subject: remove expired access tokens --- Zotlabs/Daemon/Cron.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Zotlabs/Daemon/Cron.php') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index d5b41274b..5af8174bf 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -62,6 +62,15 @@ class Cron { } + // delete expired access tokens + + q("delete from atoken where atoken_expires != '%s' && atoken_expires < %s", + dbesc(NULL_DATE), + dbutcnow() + ); + + + // Ensure that every channel pings a directory server once a month. This way we can discover // channels and sites that quietly vanished and prevent the directory from accumulating stale // or dead entries. -- cgit v1.2.3 From 0c3543ac43d552dbaee597df41c8b7ea2d650e04 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 20 Jul 2016 21:55:23 -0700 Subject: undefined function --- Zotlabs/Daemon/Cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Daemon/Cron.php') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index 5af8174bf..c6e82b13a 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -66,7 +66,7 @@ class Cron { q("delete from atoken where atoken_expires != '%s' && atoken_expires < %s", dbesc(NULL_DATE), - dbutcnow() + db_utcnow() ); -- cgit v1.2.3