From 48b182b2f6512409663be0c3cee9afe15b439f4c Mon Sep 17 00:00:00 2001 From: Renzo Date: Sat, 30 Jul 2016 13:45:57 -0500 Subject: [PATCH] Hopefuly fixes #147; made tag sub delay configurable --- app/models/JobTask.php | 24 ++++++++++++++++++------ config/default_config.php | 8 ++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/models/JobTask.php b/app/models/JobTask.php index fbac654..50e1c15 100755 --- a/app/models/JobTask.php +++ b/app/models/JobTask.php @@ -43,8 +43,15 @@ class JobTask extends Rails\ActiveRecord\Base break; case "calculate_tag_subscriptions": - return "last run: " . (isset($this->data->last_run) ? $this->data->last_run : 'never'); - break; + if (CONFIG()->tag_subscription_delay && isset($this->data->last_run)) { + $nextRun = date('Y-m-d H:i:s', strtotime('+' . CONFIG()->tag_subscription_delay, strtotime($this->data->last_run))); + } else { + $nextRun = 'imminent'; + } + + $lastRun = (isset($this->data->last_run) ? $this->data->last_run : 'never'); + + return "last run: " . $lastRun . '; next run: ' . $nextRun; // case "upload_posts_to_mirrors" // ret = "" @@ -264,12 +271,17 @@ class JobTask extends Rails\ActiveRecord\Base public function execute_calculate_tag_subscriptions() { - if (Rails::cache()->read("delay-tag-sub-calc")) { - return; + if (CONFIG()->tag_subscription_delay) { + if (Rails::cache()->read("delay-tag-sub-calc")) { + return; + } + + Rails::cache()->write("delay-tag-sub-calc", 1, ['expires_in' => CONFIG()->tag_subscription_delay]); } - Rails::cache()->write("delay-tag-sub-calc", ['expires_in' => '360 minutes']); + TagSubscription::process_all(); - $this->updateAttributes(['data' => ['last_run' => date('Y-m-d H:i')]]); + + $this->updateAttributes(['data' => ['last_run' => date('Y-m-d H:i:s')]]); } protected function init() diff --git a/config/default_config.php b/config/default_config.php index 78d32e6..8cd9e19 100755 --- a/config/default_config.php +++ b/config/default_config.php @@ -462,6 +462,14 @@ abstract class DefaultConfig # Set to 0 to wait indefinitely. public $http_streaming_timeout = 10; + /** + * Don't process tag subscriptions again within this time. + * Set to null to process tag subscriptions asap. + * + * @param string + */ + public $tag_subscription_delay = '360 minutes'; + public function __get($prop) { return null;