-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.py
79 lines (61 loc) · 2.09 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from time import time
import argparse
from jobs import update_registry
from util import elapsed
from app import db
from app import logger
# needs to be imported so the definitions get loaded into the registry
import jobs_defs
"""
examples of calling this:
# update everything
python update.py Person.refresh --limit 10 --chunk 5 --rq
# update one thing not using rq
python update.py Package.test --id 0000-1111-2222-3333
"""
def parse_update_optional_args(parser):
# just for updating lots
parser.add_argument(
"--limit", "-l", nargs="?", type=int, help="how many jobs to do"
)
parser.add_argument(
"--chunk",
"-ch",
nargs="?",
default=10,
type=int,
help="how many to take off db at once",
)
parser.add_argument(
"--after", nargs="?", type=str, help="minimum id or id start, ie 0000-0001"
)
parser.add_argument(
"--rq", action="store_true", default=False, help="do jobs in this thread"
)
parser.add_argument("--order", action="store_true", default=True, help="order them")
parser.add_argument(
"--append", action="store_true", default=False, help="append, dont' clear queue"
)
parser.add_argument("--name", nargs="?", type=str, help="name for the thread")
# just for updating one
parser.add_argument(
"--id", nargs="?", type=str, help="id of the one thing you want to update"
)
parser.add_argument(
"--doi", nargs="?", type=str, help="doi of the one thing you want to update"
)
# parse and run
parsed_args = parser.parse_args()
return parsed_args
def run_update(parsed_args):
update = update_registry.get(parsed_args.fn)
start = time()
update.run(**vars(parsed_args))
db.session.remove()
logger.info("finished update in {} secconds".format(elapsed(start)))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run stuff.")
# for everything
parser.add_argument("fn", type=str, help="what function you want to run")
parsed_args = parse_update_optional_args(parser)
run_update(parsed_args)