Skip to content

Commit 055587a

Browse files
committed
Merge pull request #158 from ruudk/default-logger
Set Resque_Log in constructor
2 parents 4442e1b + aeabb5b commit 055587a

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

lib/Resque/Worker.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ class Resque_Worker
4949
*/
5050
private $child = null;
5151

52+
/**
53+
* Instantiate a new worker, given a list of queues that it should be working
54+
* on. The list of queues should be supplied in the priority that they should
55+
* be checked for jobs (first come, first served)
56+
*
57+
* Passing a single '*' allows the worker to work on all queues in alphabetical
58+
* order. You can easily add new queues dynamically and have them worked on using
59+
* this method.
60+
*
61+
* @param string|array $queues String with a single queue name, array with multiple.
62+
*/
63+
public function __construct($queues)
64+
{
65+
$this->logger = new Resque_Log();
66+
67+
if(!is_array($queues)) {
68+
$queues = array($queues);
69+
}
70+
71+
$this->queues = $queues;
72+
if(function_exists('gethostname')) {
73+
$hostname = gethostname();
74+
}
75+
else {
76+
$hostname = php_uname('n');
77+
}
78+
$this->hostname = $hostname;
79+
$this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues);
80+
}
81+
5282
/**
5383
* Return all workers known to Resque as instantiated instances.
5484
* @return array
@@ -107,34 +137,6 @@ public function setId($workerId)
107137
$this->id = $workerId;
108138
}
109139

110-
/**
111-
* Instantiate a new worker, given a list of queues that it should be working
112-
* on. The list of queues should be supplied in the priority that they should
113-
* be checked for jobs (first come, first served)
114-
*
115-
* Passing a single '*' allows the worker to work on all queues in alphabetical
116-
* order. You can easily add new queues dynamically and have them worked on using
117-
* this method.
118-
*
119-
* @param string|array $queues String with a single queue name, array with multiple.
120-
*/
121-
public function __construct($queues)
122-
{
123-
if(!is_array($queues)) {
124-
$queues = array($queues);
125-
}
126-
127-
$this->queues = $queues;
128-
if(function_exists('gethostname')) {
129-
$hostname = gethostname();
130-
}
131-
else {
132-
$hostname = php_uname('n');
133-
}
134-
$this->hostname = $hostname;
135-
$this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues);
136-
}
137-
138140
/**
139141
* The primary loop for a worker which when called on an instance starts
140142
* the worker's life cycle.

0 commit comments

Comments
 (0)