Completed
Pull Request — master (#518)
by Michael
03:07
created

CreateEnvJob::onFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
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
	/**
19
	 *
20
	 * @global array $databaseConfig
21
	 */
22
	public function tearDown() {
23
		$this->updateStatus('Finished');
24
		chdir(BASE_PATH);
25
	}
26
27
	public function onFailure(Exception $exception) {
28
		$this->updateStatus('Failed');
29
	}
30
31
	/**
32
	 *
33
	 */
34
	public function perform() {
35
		echo "[-] CreateEnvJob starting" . PHP_EOL;
36
		// This is a bit icky, but there is no easy way of capturing a failed deploy by using the PHP Resque
37
		try {
38
			$envCreate = DNCreateEnvironment::get()->byId($this->args['createID']);
39
			if(!($envCreate && $envCreate->exists())) {
40
				throw new RuntimeException(sprintf('Could not find create environment record %s', $args['createID']));
41
			}
42
43
			// This will throw and exception if it fails.
44
			$envCreate->createEnvironment();
45
46
		} catch(Exception $e) {
47
			echo "[-] CreateEnvJob failed" . PHP_EOL;
48
			throw $e;
49
		}
50
		echo "[-] CreateEnvJob finished" . PHP_EOL;
51
	}
52
53
	/**
54
	 *
55
	 * @param string $status
56
	 * @global array $databaseConfig
57
	 */
58
	protected function updateStatus($status) {
59
		global $databaseConfig;
60
		DB::connect($databaseConfig);
61
62
		$record = DNCreateEnvironment::get()->byID($this->args['createID']);
63
		$record->Status = $status;
64
		$record->write();
65
	}
66
67
	/**
68
	 *
69
	 * @return DNData
70
	 */
71
	protected function DNData() {
72
		return DNData::inst();
73
	}
74
}
75
76