Skip to content

Commit

Permalink
Hopefuly fixes #147; made tag sub delay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Parziphal committed Jul 30, 2016
1 parent 6e77aa8 commit 48b182b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
24 changes: 18 additions & 6 deletions app/models/JobTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ public function pretty_data()
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 = ""
Expand Down Expand Up @@ -264,12 +271,17 @@ public function execute_approve_tag_implication()

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()
Expand Down
8 changes: 8 additions & 0 deletions config/default_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ public function can_see_ads($user)
# 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;
Expand Down

0 comments on commit 48b182b

Please sign in to comment.