Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Add configurable sleep time before generation job completes to alleviate asset sync timing issues #33

Merged
merged 1 commit into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions code/GenerateCSVJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ',';
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/GenerateCSVJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down