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.1 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
  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, goodreads
  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. finished = 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. finished.add(step)
  26. if end:
  27. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.GREEN}finished{S.RESET_ALL} at {end} (took {time})')
  28. else:
  29. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.YELLOW}started{S.RESET_ALL} at {start}')
  30. for step in sorted(k for k in steps.keys() if k not in finished):
  31. task = steps[step]
  32. print(f'{S.BRIGHT}{step}{S.RESET_ALL}: {F.RED}not run{S.RESET_ALL} (defined in {task})')
  33. @task
  34. def list_steps(c):
  35. steps = support.get_steps(ns)
  36. for s in sorted(steps.keys()):
  37. task = steps[s]
  38. print(f'{S.BRIGHT}{s}{S.RESET_ALL}: defined in {task}')
  39. ns = Collection()
  40. ns.add_task(status)
  41. ns.add_task(list_steps)
  42. ns.add_collection(support)
  43. ns.add_collection(ratings)
  44. ns.add_collection(viaf)
  45. ns.add_collection(openlib)
  46. ns.add_collection(loc)
  47. ns.add_collection(analyze)
  48. ns.add_collection(goodreads)
  49. if 'DB_URL' not in os.environ and 'PGDATABASE' in os.environ:
  50. dbu = support.db_url()
  51. _log.info('initializing DB_URL=%s', dbu)
  52. os.environ['DB_URL'] = dbu
  53. if __name__ == '__main__':
  54. import invoke.program
  55. program = invoke.program.Program()
  56. program.run()
Tip!

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

Comments

Loading...