mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Merge pull request #9 from madmatt/pulls/resque-event
Add Resque_Event::listen() call to register the testsession state switcher with the silverstripe-resque module.
This commit is contained in:
commit
e198f738b4
23
_config.php
23
_config.php
@ -2,3 +2,26 @@
|
||||
|
||||
// Determine whether there is a testsession currently running, and if so - setup the persistent details for it.
|
||||
Injector::inst()->get('TestSessionEnvironment')->loadFromFile();
|
||||
|
||||
/**
|
||||
* This closure will run every time a Resque_Event is forked (just before it is forked, so it applies to the parent
|
||||
* and child process).
|
||||
*/
|
||||
if(class_exists('Resque_Event') && class_exists('SSResqueRun')) {
|
||||
Resque_Event::listen('beforeFork', function($data) {
|
||||
global $databaseConfig;
|
||||
|
||||
// Reconnect to the database - this may connect to the old DB first, but is required because these processes
|
||||
// are long-lived, and MySQL connections often get closed in between worker runs. We need to connect before
|
||||
// calling {@link TestSessionEnvironment::loadFromFile()}.
|
||||
DB::connect($databaseConfig);
|
||||
|
||||
$testEnv = Injector::inst()->get('TestSessionEnvironment');
|
||||
|
||||
if($testEnv->isRunningTests()) {
|
||||
$testEnv->loadFromFile();
|
||||
} else {
|
||||
$testEnv->endTestSession();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user