-
Notifications
You must be signed in to change notification settings - Fork 2
Filter tasks by task name #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f87486a
e809e18
e4c5b85
c4ef698
0a71ba8
c37a9e5
572c180
39b58fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,10 @@ public function createJob($taskName, $data, $notBefore = null) { | |
| * Looks for a new job that can be processed with the current abilities | ||
| * | ||
| * @param array $capabilities Available queue worker tasks. | ||
| * @param array $types Request a job from these types (or exclude certain types), or any otherwise. | ||
| * @return mixed Job data or false. | ||
| */ | ||
| public function requestJob($capabilities) { | ||
| public function requestJob($capabilities, array $types = []) { | ||
| $idlist = []; | ||
| $wasFetched = []; | ||
|
|
||
|
|
@@ -64,6 +65,10 @@ public function requestJob($capabilities) { | |
| ]; | ||
| $limit = Configure::read('Queue.workers'); | ||
|
|
||
| if ($types) { | ||
| $conditions = $this->_addFilter($conditions, 'task', $types); | ||
| } | ||
|
|
||
| // Generate the job specific conditions. | ||
| foreach ($capabilities as $task) { | ||
| list($plugin, $name) = pluginSplit($task['name']); | ||
|
|
@@ -179,7 +184,7 @@ public function getLength($taskName = null) { | |
| * @return array A list of task names | ||
| */ | ||
| public function getTypes() { | ||
| $fields = ['task']; | ||
| $fields = ['task', 'task']; | ||
| $group = ['task']; | ||
|
|
||
| return $this->find('list', compact('fields', 'group')); | ||
|
|
@@ -246,4 +251,33 @@ public function cleanFailedJobs($capabilities) { | |
| return $this->deleteAll($conditions, false); | ||
| } | ||
|
|
||
| /** | ||
| * Filters field `key` based on the provided values. Values prefixed with '-' are excluded. | ||
| * | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing doc-comment |
||
| * @param array $conditions Conditions | ||
| * @param string $key Key | ||
| * @param array $values Values | ||
| * @return array the conditions | ||
| */ | ||
| protected function _addFilter(array $conditions, $key, array $values) : array { | ||
| $include = []; | ||
| $exclude = []; | ||
| foreach ($values as $value) { | ||
| if (substr($value, 0, 1) === '-') { | ||
| $exclude[] = substr($value, 1); | ||
| } else { | ||
| $include[] = $value; | ||
| } | ||
| } | ||
|
|
||
| if ($include) { | ||
| $conditions[$key . ' IN'] = $include; | ||
| } | ||
| if ($exclude) { | ||
| $conditions[$key . ' NOT IN'] = $exclude; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may have been done on purpose. If $conditions['NOT'] is added here, there's a greater chance it would be overwritten by the calling function. Not too clean, though |
||
| } | ||
|
|
||
| return $conditions; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing doc-comment