Passed
Push — master ( fdca42...7dd147 )
by Hennik
03:23 queued 10s
created

Resque_Job_PID::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * PID tracker for the forked worker job.
4
 *
5
 * @package		Resque/Job
6
 * @author		Chris Boulton <[email protected]>
7
 * @license		http://www.opensource.org/licenses/mit-license.php
8
 */
9
class Resque_Job_PID
10
{
11
	/**
12
	 * Create a new PID tracker item for the supplied job ID.
13
	 *
14
	 * @param string $id The ID of the job to track the PID of.
15
	 */
16
	public static function create($id)
17
	{
18
		Resque::redis()->set('job:' . $id . ':pid', (string)getmypid());
0 ignored issues
show
Bug introduced by
The method set() does not exist on Resque_Redis. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
		Resque::redis()->/** @scrutinizer ignore-call */ set('job:' . $id . ':pid', (string)getmypid());
Loading history...
19
	}
20
21
	/**
22
	 * Fetch the PID for the process actually executing the job.
23
	 *
24
	 * @param string $id The ID of the job to get the PID of.
25
	 *
26
	 * @return int PID of the process doing the job (on non-forking OS, PID of the worker, otherwise forked PID).
27
	 */
28 3
	public static function get($id)
29
	{
30 3
		return (int)Resque::redis()->get('job:' . $id . ':pid');
0 ignored issues
show
Bug introduced by
The method get() does not exist on Resque_Redis. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
		return (int)Resque::redis()->/** @scrutinizer ignore-call */ get('job:' . $id . ':pid');
Loading history...
31
	}
32
33
	/**
34
	 * Remove the PID tracker for the job.
35
	 *
36
	 * @param string $id The ID of the job to remove the tracker from.
37
	 */
38
	public static function del($id)
39
	{
40
		Resque::redis()->del('job:' . $id . ':pid');
0 ignored issues
show
Bug introduced by
The method del() does not exist on Resque_Redis. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
		Resque::redis()->/** @scrutinizer ignore-call */ del('job:' . $id . ':pid');
Loading history...
41
	}
42
}
43
44