Completed
Pull Request — master (#594)
by Mateusz
03:09
created

AnthillJob::perform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
/**
4
 * Ideally, we would enqueue AnthillJobs straight from the deploynaut where possible, bypassing half a dozen
5
 * layers of abstraction in the process. For this to happen though we would need to:
6
 * - remove DNEnvironment, DNProject dependencies from jobs see DeploymentBackend interface.
7
 * - construct ClientFactory to reflect the authorisation context (right now it's null in DeploynautJob::runOp).
8
 *
9
 * This would be a nice first step towards decoupling workers from Deploynaut, because it would introduce
10
 * an array-only API to job subsystem (based on Anthill Params). This wouldn't really work for Capistrano,
11
 * because (a) it doesn't run on Anthill, (b) it relies on local capistrano config files, which would need
12
 * to be somehow copied to the workers.
13
 *
14
 * In any caase, to decouple, we'd need to additionally:
15
 * - be able to fetch log files remotely (HTTP from worker? Redis? - no local file access)
16
 * - remove triggers in jobs that update the job status (state machine) in the SS DB. Would
17
 *   need some kind of a polling mechanism in Deploynaut to constantly query resque and update status in DB.
18
 *
19
 * With that, we would be able to enqueue jobs from Deploynaut like this:
20
 * 		$params = new Anthill\Operations\Params\Smoketest([
21
 *			'url' => 'silverstripe.com/host.txt',
22
 *		]);
23
 *		Resque::enqueue('deploy', 'AnthillJob', [
24
 *			'Smoketest',
25
 *			$params->toArray()
26
 *		], true);
27
 */
28
class AnthillJob extends DeploynautJob {
29
30
	public function perform() {
31
		$opName = $this->args['opName'];
32
		$params = $this->args['params'];
33
		$paramClass = sprintf('SilverStripe\Platform\Core\Rainforest\Anthill\Operations\Params\%s', $opName);
34
		$runner = $this->runOp($opName, new $paramClass($params));
35
		if (!$runner->isSuccessful()) {
36
			throw $runner->getFailureException();
37
		}
38
	}
39
40
	protected function updateStatus($status) {
41
		// No-op
42
	}
43
44
}
45