Skip to content

Commit f7c0ee0

Browse files
feat(cli): add ptq command
1 parent a29a976 commit f7c0ee0

9 files changed

Lines changed: 121 additions & 5 deletions

File tree

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGES
22
=======
33

4+
2.4.0
5+
-----
6+
7+
* release(2.4.0): adds elapsed\_time DI argument to stop\_fn
8+
* docs: describe elapsed\_time parameter
9+
* feat: add "elapsed\_time" DI argument to stop\_fn
10+
411
2.3.0
512
-----
613

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2017,
3+
Copyright (c) 2017-2020, William Silversmith, Seung Lab
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE
2+
include cloudfiles_cli/LICENSE

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
boto3
2+
click
23
gevent
34
google-auth>=1.10.0
45
google-cloud-core>=1.1.0

setup.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import setuptools
22

33
setuptools.setup(
4-
setup_requires=['pbr'],
5-
long_description_content_type="text/markdown",
6-
pbr=True)
4+
setup_requires=['pbr'],
5+
include_package_data=True,
6+
entry_points={
7+
"console_scripts": [
8+
"ptq=taskqueue_cli:main"
9+
],
10+
},
11+
long_description_content_type="text/markdown",
12+
pbr=True
13+
)

taskqueue/paths.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515
def mkpath(extracted_path):
1616
return extracted_path.protocol + "://" + extracted_path.path
1717

18+
def get_protocol(cloudpath):
19+
protocol_re = re.compile(r'(?P<proto>\w+)://')
20+
match = re.match(protocol_re, cloudpath)
21+
if not match:
22+
return None
23+
return match.group("proto")
24+
1825
def pop_protocol(cloudpath):
1926
protocol_re = re.compile(r'(\w+)://')
2027

2128
match = re.match(protocol_re, cloudpath)
2229

2330
if not match:
24-
return ('sqs', cloudpath)
31+
return ("sqs", cloudpath)
2532

2633
(protocol,) = match.groups()
2734
cloudpath = re.sub(protocol_re, '', cloudpath, count=1)

taskqueue_cli/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2017-2020, William Silversmith, Seung Lab
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

taskqueue_cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .taskqueue_cli import *

taskqueue_cli/taskqueue_cli.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
3+
import click
4+
5+
from taskqueue import TaskQueue, __version__
6+
from taskqueue.lib import toabs
7+
from taskqueue.paths import get_protocol
8+
9+
def normalize_path(queuepath):
10+
if not get_protocol(queuepath):
11+
return "fq://" + toabs(queuepath)
12+
return queuepath
13+
14+
@click.group()
15+
@click.version_option(version=__version__)
16+
def main():
17+
"""
18+
CLI tool for managing python-task-queue queues.
19+
20+
https://github.com/seung-lab/python-task-queue
21+
"""
22+
pass
23+
24+
# @main.command()
25+
# def version():
26+
# """Prints the version."""
27+
# print(f"task-queue v{__version__}")
28+
29+
@main.command()
30+
def license():
31+
"""Prints the license for this library and cli tool."""
32+
path = os.path.join(os.path.dirname(__file__), 'LICENSE')
33+
with open(path, 'rt') as f:
34+
print(f.read())
35+
36+
@main.command()
37+
@click.argument("queuepath")
38+
def rezero(queuepath):
39+
"""Reset collected statistics for queue."""
40+
TaskQueue(normalize_path(queuepath)).rezero()
41+
42+
@main.command()
43+
@click.argument("queuepath")
44+
def status(queuepath):
45+
"""Print vital statistics for queue."""
46+
tq = TaskQueue(normalize_path(queuepath))
47+
ins = tq.inserted
48+
enq = tq.enqueued
49+
comp = tq.completed
50+
print(f"Inserted: {ins}")
51+
if ins > 0:
52+
print(f"Enqueued: {enq} ({enq / ins * 100:.1f}% left)")
53+
print(f"Completed: {comp} ({comp / ins * 100:.1f}%)")
54+
else:
55+
print(f"Enqueued: {enq} (--% left)")
56+
print(f"Completed: {comp} (--%)")
57+
58+
@main.command()
59+
@click.argument("queuepath")
60+
def release(queuepath):
61+
"""Release all tasks from their leases."""
62+
TaskQueue(normalize_path(queuepath)).release_all()

0 commit comments

Comments
 (0)