Completed
Pull Request — master (#519)
by Michael
04:23
created

CreateEnvJob::onFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
class CreateEnvJob extends DeploynautJob {
3
4
	/**
5
	 *
6
	 * @var array
7
	 */
8
	public $args;
9
10
	/**
11
	 *
12
	 */
13
	public function setUp() {
14
		$this->updateStatus('Started');
15
		chdir(BASE_PATH);
16
	}
17
18
	public function onFailure(Exception $exception) {
19
		$this->updateStatus('Failed');
20
	}
21
22
	/**
23
	 *
24
	 */
25
	public function perform() {
26
		echo "[-] CreateEnvJob starting" . PHP_EOL;
27
		// This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque
28
		try {
29
			$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
30
			if(!($envCreate && $envCreate->exists())) {
31
				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
32
			}
33
34
			// This will throw and exception if it fails.
35
			$envCreate->createEnvironment();
36
37
		} catch(Exception $e) {
38
			echo "[-] CreateEnvJob failed" . PHP_EOL;
39
			throw $e;
40
		}
41
		$this->updateStatus('Finished');
42
		echo "[-] CreateEnvJob finished" . PHP_EOL;
43
	}
44
45
	/**
46
	 *
47
	 * @param string $status
48
	 * @global array $databaseConfig
49
	 */
50
	protected function updateStatus($status) {
51
		global $databaseConfig;
52
		DB::connect($databaseConfig);
53
54
		$record = DNCreateEnvironment::get()->byID($this->args['createID']);
55
		$record->Status = $status;
56
		$record->write();
57
	}
58
59
	/**
60
	 *
61
	 * @return DNData
62
	 */
63
	protected function DNData() {
64
		return DNData::inst();
65
	}
66
}
67
68