Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

tasks.py 2.2 KB

You have to be logged in to leave a comment. Sign In
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
  1. import sys
  2. from pathlib import Path
  3. import subprocess as sp
  4. import os
  5. import logging
  6. from invoke import task, Collection
  7. import ratings, support, viaf, openlib, loc, analyze
  8. from colorama import Fore as F, Back as B, Style as S
  9. _log = logging.getLogger(__package__)
  10. _log_fmt = '%(asctime)s %(levelname)s %(name)s: %(message)s'
  11. _log_date = '%H:%M:%S'
  12. try:
  13. import chromalog
  14. chromalog.basicConfig(stream=sys.stderr, level=logging.INFO, format=_log_fmt, datefmt=_log_date)
  15. except ImportError:
  16. logging.basicConfig(stream=sys.stderr, level=logging.INFO, format=_log_fmt, datefmt=_log_date)
  17. _log.warning('chromalog not found, using plain logs')
  18. @task
  19. def status(c):
  20. steps = support.get_steps(ns)
  21. recorded = set()
  22. with support.database(autocommit=True) as db, db.cursor() as cur:
  23. cur.execute('SELECT step, started_at, finished_at, finished_at - started_at AS elapsed FROM import_status ORDER BY started_at')
  24. for step, start, end, time in cur:
  25. recorded.add(step)
  26. if step in steps:
  27. dfn = f' (defined in {steps[step]})'
  28. else:
  29. dfn = ''
  30. if end:
  31. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.GREEN}finished{S.RESET_ALL} at {end} (took {time}){dfn}')
  32. else:
  33. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.YELLOW}started{S.RESET_ALL} at {start}{dfn}')
  34. for step in sorted(k for k in steps.keys() if k not in recorded):
  35. task = steps[step]
  36. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.RED}not run{S.RESET_ALL} (defined in {task})')
  37. @task
  38. def list_steps(c):
  39. steps = support.get_steps(ns)
  40. for s in sorted(steps.keys()):
  41. task = steps[s]
  42. print(f'{S.BRIGHT}{s}{S.RESET_ALL}: defined in {task}')
  43. ns = Collection()
  44. ns.add_task(status)
  45. ns.add_task(list_steps)
  46. ns.add_collection(support)
  47. ns.add_collection(ratings)
  48. ns.add_collection(viaf)
  49. ns.add_collection(openlib)
  50. ns.add_collection(loc)
  51. ns.add_collection(analyze)
  52. if 'DB_URL' not in os.environ and 'PGDATABASE' in os.environ:
  53. dbu = support.db_url()
  54. _log.info('initializing DB_URL=%s', dbu)
  55. os.environ['DB_URL'] = dbu
  56. if __name__ == '__main__':
  57. import invoke.program
  58. program = invoke.program.Program()
  59. program.run()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...