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

stage-status.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  1. """
  2. Usage:
  3. stage-status.py [options] STAGE
  4. Options:
  5. --timestamps
  6. Include timestamps in stage status.
  7. -o FILE
  8. Write output to FILE.
  9. STAGE
  10. The stage to check.
  11. """
  12. import sys
  13. from docopt import docopt
  14. from bookdata import db, script_log
  15. _log = script_log(__name__)
  16. opts = docopt(__doc__)
  17. timestamps = opts.get('--timestamps')
  18. stage = opts.get('STAGE')
  19. out = opts.get('-o', None)
  20. if out is None:
  21. out = f'{stage}.status'
  22. if out == '-':
  23. sf = sys.stdout
  24. else:
  25. sf = open(out, 'w')
  26. with db.connect() as dbc:
  27. # initialize database, in case nothing has been run
  28. with dbc, dbc.cursor() as cur:
  29. cur.execute(db.meta_schema)
  30. # get the status
  31. with dbc, dbc.cursor() as cur:
  32. cur.execute('''
  33. SELECT started_at, finished_at, stage_key FROM stage_status WHERE stage_name = %s
  34. ''', [stage])
  35. row = cur.fetchone()
  36. if not row:
  37. _log.error('stage %s not run', stage)
  38. sys.exit(2)
  39. start, end, key = row
  40. _log.info('stage %s finished at %s', stage, end)
  41. print('STAGE', stage, file=sf)
  42. if timestamps:
  43. print('START', start, file=sf)
  44. cur.execute('''
  45. SELECT dep_name, dep_key
  46. FROM stage_dep
  47. WHERE stage_name = %s
  48. ORDER BY dep_name
  49. ''', [stage])
  50. for dn, dk in cur:
  51. print('DEP', dn, dk, file=sf)
  52. cur.execute('''
  53. SELECT filename, COALESCE(link.checksum, src.checksum)
  54. FROM source_file src
  55. JOIN stage_file link USING (filename)
  56. WHERE stage_name = %s
  57. ORDER BY filename
  58. ''', [stage])
  59. for fn, fh in cur:
  60. print('SOURCE', fn, fh, file=sf)
  61. cur.execute('''
  62. SELECT st_ns, st_name, oid, kind
  63. FROM stage_table_oids
  64. WHERE stage_name = %s
  65. ORDER BY st_ns, st_name
  66. ''', [stage])
  67. for ns, tbl, oid, kind in cur:
  68. print(f'TABLE {ns}.{tbl} OID {oid} KIND {kind}', file=sf)
  69. if timestamps:
  70. print('FINISH', end, file=sf)
  71. if key:
  72. print('KEY', key, file=sf)
  73. sf.close()
Tip!

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

Comments

Loading...