Skip to content

Commit

Permalink
CORE-3728 API tags list
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostiantyn committed Nov 11, 2021
1 parent 0d53047 commit 2ff02dd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @method string workers(?string $workerName = null, ?int $start = null, ?int $last = null)
* @method string workerJobs(string $worker, ?int $minScoreTime = null)
* @method string subscription(string $queue, $op, $topic)
* @method string tags(int $offset = 0, int $count = 10000)
*
* @property-read JobsCollection $jobs
* @property-read WorkersCollection $workers
Expand Down
11 changes: 11 additions & 0 deletions src/Jobs/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,15 @@ public function offsetUnset($offset)
{
throw new UnsupportedFeatureException('Deleting a job is not supported using Jobs collection.');
}

/**
* @param int $offset
* @param int $count
*
* @return array
*/
public function tagsList(int $offset = 0, int $count = 10000): array
{
return json_decode($this->client->tags($offset, $count), true) ?: [];
}
}
14 changes: 14 additions & 0 deletions src/qless-core/qless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ function Qless.subscription(now, queue, command, topic)
end
end

function Qless.tags(cursor, count)
local tags = redis.call('scan', cursor, 'match', 'ql:t:*', 'count', count)

for i=1,#tags[2] do
tags[2][i] = tags[2][i]:gsub("ql:t:", "")
end

return tags[2]
end

function Qless.tag(now, command, ...)
assert(command,
'Tag(): Arg "command" must be "add", "remove", "get" or "top"')
Expand Down Expand Up @@ -2194,6 +2204,10 @@ QlessAPI.track = function(now, command, jid)
return cjson.encode(Qless.track(now, command, jid))
end

QlessAPI.tags = function(now, cursor, count)
return cjson.encode(Qless.tags(cursor, count))
end

QlessAPI.tag = function(now, command, ...)
return cjson.encode(Qless.tag(now, command, unpack(arg)))
end
Expand Down
12 changes: 12 additions & 0 deletions tests/Jobs/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ public function testItReturnsAllWorkerJobsByInvalidTimeFilter(): void
self::assertCount(3, $jobs);
}

public function testTagsList(): void
{
$queue = $this->client->queues['test-queue'];
$queue->put('SampleJobPerformClass', [], 'jid-1', 0, 0, 0, ['tag-a', 'tag-b']);
$queue->put('SampleJobPerformClass', [], 'jid-2', 0, 0, 0, ['tag-a', 'tag-c']);

$data = $this->client->jobs->tagsList();
sort($data);

self::assertEquals(['tag-a', 'tag-b', 'tag-c'], $data);
}


private function put($jid, $opts = []): void
{
Expand Down

0 comments on commit 2ff02dd

Please sign in to comment.