From 3d56f3d8b01c91bd57cd595d27c4a2d56f9abe2d Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 11 Jan 2019 09:40:17 +0100 Subject: [PATCH] FIX Add configurable sleep time before generation job completes to alleviate asset sync timing issues --- code/GenerateCSVJob.php | 14 ++++++++++++++ tests/GenerateCSVJobTest.php | 1 + 2 files changed, 15 insertions(+) diff --git a/code/GenerateCSVJob.php b/code/GenerateCSVJob.php index 2a81e51..b91c07f 100644 --- a/code/GenerateCSVJob.php +++ b/code/GenerateCSVJob.php @@ -15,6 +15,15 @@ */ class GenerateCSVJob extends AbstractQueuedJob { + /** + * Optionally define the number of seconds to wait after the job has finished before marking it as complete. + * This can help in multi-server environments, where asset synchronisation may not be immediate. + * + * @config + * @var int + */ + private static $sync_sleep_seconds = 0; + public function __construct() { $this->ID = Injector::inst()->create('RandomGenerator')->randomToken('sha1'); $this->Seperator = ','; @@ -255,6 +264,11 @@ public function process() { $this->currentStep += 100; if ($this->currentStep >= $this->totalSteps) { + // Check to see if we need to wait for some time for asset synchronisation to complete + $sleepTime = (int) Config::inst()->get('GenerateCSVJob', 'sync_sleep_seconds'); + if ($sleepTime > 0) { + sleep($sleepTime); + } $this->isComplete = true; } } diff --git a/tests/GenerateCSVJobTest.php b/tests/GenerateCSVJobTest.php index 1cd5801..07ff453 100644 --- a/tests/GenerateCSVJobTest.php +++ b/tests/GenerateCSVJobTest.php @@ -11,6 +11,7 @@ public function setUp() { Config::inst()->update('Director', 'rules', array( 'jobtest//$Action/$ID/$OtherID' => 'GenerateCSVJobTest_Controller' )); + Config::inst()->update('GenerateCSVJob', 'sync_sleep_seconds', 0); } protected $paths = array();