forked from symbiote/silverstripe-queuedjobs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from assertchris/add-additional-core-engine
Added additional core engine
- Loading branch information
Showing
7 changed files
with
567 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<?php | ||
|
||
use AsyncPHP\Doorman\Rule; | ||
|
||
/** | ||
* @property int $Processes | ||
* @property string $Handler | ||
* @property float $MinimumProcessorUsage | ||
* @property float $MaximumProcessorUsage | ||
* @property float $MinimumMemoryUsage | ||
* @property float $MaximumMemoryUsage | ||
* @property float $MinimumSiblingProcessorUsage | ||
* @property float $MaximumSiblingProcessorUsage | ||
* @property float $MinimumSiblingMemoryUsage | ||
* @property float $MaximumSiblingMemoryUsage | ||
*/ | ||
class QueuedJobRule extends DataObject implements Rule { | ||
/** | ||
* @var array | ||
*/ | ||
private static $db = array( | ||
'Processes' => 'Int', | ||
'Handler' => 'Varchar', | ||
'MinimumProcessorUsage' => 'Decimal', | ||
'MaximumProcessorUsage' => 'Decimal', | ||
'MinimumMemoryUsage' => 'Decimal', | ||
'MaximumMemoryUsage' => 'Decimal', | ||
'MinimumSiblingProcessorUsage' => 'Decimal', | ||
'MaximumSiblingProcessorUsage' => 'Decimal', | ||
'MinimumSiblingMemoryUsage' => 'Decimal', | ||
'MaximumSiblingMemoryUsage' => 'Decimal', | ||
); | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return int | ||
*/ | ||
public function getProcesses() { | ||
if($this->getField('Processes')) { | ||
return $this->getField('Processes'); | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|string | ||
*/ | ||
public function getHandler() { | ||
if($this->getField('Handler')) { | ||
return $this->getField('Handler'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @return null|float | ||
*/ | ||
public function getMinimumProcessorUsage() { | ||
if($this->getField('MinimumProcessorUsage')) { | ||
return $this->getField('MinimumProcessorUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|float | ||
*/ | ||
public function getMaximumProcessorUsage() { | ||
if($this->getField('MaximumProcessorUsage')) { | ||
return $this->getField('MaximumProcessorUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|float | ||
*/ | ||
public function getMinimumMemoryUsage() { | ||
if($this->getField('MinimumMemoryUsage')) { | ||
return $this->getField('MinimumMemoryUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @return null|float | ||
*/ | ||
public function getMaximumMemoryUsage() { | ||
if($this->getField('MaximumMemoryUsage')) { | ||
return $this->getField('MaximumMemoryUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|float | ||
*/ | ||
public function getMinimumSiblingProcessorUsage() { | ||
if($this->getField('MinimumSiblingProcessorUsage')) { | ||
return $this->getField('MinimumSiblingProcessorUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|float | ||
*/ | ||
public function getMaximumSiblingProcessorUsage() { | ||
if($this->getField('MaximumSiblingProcessorUsage')) { | ||
return $this->getField('MaximumSiblingProcessorUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|float | ||
*/ | ||
public function getMinimumSiblingMemoryUsage() { | ||
if($this->getField('MinimumSiblingMemoryUsage')) { | ||
return $this->getField('MinimumSiblingMemoryUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|float | ||
*/ | ||
public function getMaximumSiblingMemoryUsage() { | ||
if($this->getField('MaximumSiblingMemoryUsage')) { | ||
return $this->getField('MaximumSiblingMemoryUsage'); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
use AsyncPHP\Doorman\Manager\ProcessManager; | ||
|
||
class DoormanProcessManager extends ProcessManager | ||
{ | ||
/** | ||
* @inheritdoc | ||
* | ||
* @return string | ||
*/ | ||
protected function getWorker() { | ||
return BASE_PATH . "/framework/cli-script.php dev/tasks/ProcessJobQueueChildTask"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<?php | ||
|
||
use AsyncPHP\Doorman\Expires; | ||
use AsyncPHP\Doorman\Process; | ||
use AsyncPHP\Doorman\Task; | ||
|
||
class DoormanQueuedJobTask implements Task, Expires, Process { | ||
/** | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var QueuedJobDescriptor | ||
*/ | ||
protected $descriptor; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return null|int | ||
*/ | ||
public function getId() { | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @param int $id | ||
* | ||
* @return $this | ||
*/ | ||
public function setId($id) { | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return QueuedJobDescriptor | ||
*/ | ||
public function getDescriptor() | ||
{ | ||
return $this->descriptor; | ||
} | ||
|
||
/** | ||
* @param QueuedJobDescriptor $descriptor | ||
*/ | ||
public function __construct(QueuedJobDescriptor $descriptor) { | ||
$this->descriptor = $descriptor; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return string | ||
*/ | ||
public function serialize() { | ||
return serialize(array( | ||
'descriptor' => $this->descriptor->ID, | ||
)); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function unserialize($serialized) { | ||
$data = unserialize($serialized); | ||
|
||
if(!isset($data['descriptor'])) { | ||
throw new InvalidArgumentException('Malformed data'); | ||
} | ||
|
||
$descriptor = QueuedJobDescriptor::get() | ||
->filter('ID', $data['descriptor']) | ||
->first(); | ||
|
||
if(!$descriptor) { | ||
throw new InvalidArgumentException('Descriptor not found'); | ||
} | ||
|
||
$this->descriptor = $descriptor; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getHandler() { | ||
return 'DoormanQueuedJobHandler'; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getData() { | ||
return array( | ||
'descriptor' => $this->descriptor, | ||
); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function ignoresRules() { | ||
if (method_exists($this->descriptor, 'ignoreRules')) { | ||
return $this->descriptor->ignoreRules(); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function stopsSiblings() { | ||
if (method_exists($this->descriptor, 'stopsSiblings')) { | ||
return $this->descriptor->stopsSiblings(); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @return int | ||
*/ | ||
public function getExpiresIn() { | ||
if (method_exists($this->descriptor, 'getExpiresIn')) { | ||
return $this->descriptor->getExpiresIn(); | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @param int $startedAt | ||
* | ||
* @return bool | ||
*/ | ||
public function shouldExpire($startedAt) { | ||
if (method_exists($this->descriptor, 'shouldExpire')) { | ||
return $this->descriptor->shouldExpire($startedAt); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use AsyncPHP\Doorman\Handler; | ||
use AsyncPHP\Doorman\Task; | ||
|
||
class ProcessJobQueueChildTask extends BuildTask { | ||
/** | ||
* @param SS_HttpRequest $request | ||
*/ | ||
public function run($request) { | ||
if (!isset($_SERVER['argv'][2])) { | ||
print "No task data provided.\n"; | ||
return; | ||
} | ||
|
||
$task = @unserialize(@base64_decode($_SERVER['argv'][2])); | ||
|
||
if ($task) { | ||
$this->getService()->runJob($task->getDescriptor()->ID); | ||
} | ||
} | ||
|
||
/** | ||
* Returns an instance of the QueuedJobService. | ||
* | ||
* @return QueuedJobService | ||
*/ | ||
protected function getService() { | ||
return singleton('QueuedJobService'); | ||
} | ||
} |
Oops, something went wrong.