@tedbrain/vlink 0.0.0-dpv2.pdkadapt.plugin.0.1.10.r6 → 0.0.0-dpv2.pdkadapt.plugin.0.1.11.r7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@tedbrain/vlink", "private": false, "version": "0.0.0-dpv2.pdkadapt.plugin.0.1.10.r6"}
1
+ {"name": "@tedbrain/vlink", "private": false, "version": "0.0.0-dpv2.pdkadapt.plugin.0.1.11.r7"}
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
  import sys
7
7
  import traceback
8
8
  from .installer import atomic,canonical,loads,ContractError
9
- from .jobs import Conflict,Jobs
9
+ from .jobs import Conflict,Jobs,shared_db_path,shared_store_root
10
10
 
11
11
  # Matches the transport's own DEFAULT_REQUEST_TIMEOUT_SECONDS: a single remote
12
12
  # call can never silently outlast its request budget, so the supervisor's
@@ -28,7 +28,12 @@ class Cancelled(Exception):
28
28
 
29
29
  def run(path):
30
30
  path=Path(path);spec=loads(path.read_bytes());row=spec['job'];config=spec['config'];station=spec['workstation']
31
- jobs=Jobs(Path(config['state_root'])/'jobs.sqlite3')
31
+ # Engine and supervisor share one jobs table; the engine's completion row
32
+ # lands in the same database the supervisor operates.
33
+ jobs_root=shared_store_root(Path(config['state_root']),config.get('delivery_store_root'))
34
+ jobs_path=shared_db_path(Path(config['state_root']),config.get('delivery_store_root'))
35
+ legacy_jobs=Path(config['state_root'])/'jobs.sqlite3'
36
+ jobs=Jobs(jobs_path,legacy_path=legacy_jobs if jobs_path!=legacy_jobs else None)
32
37
  request=loads(row['request']);directory=path.parent
33
38
  # I01900 heartbeat lease: the engine renews at every tool boundary and
34
39
  # every progress checkpoint. Renewal is best-effort against a supervisor
@@ -73,7 +78,8 @@ def run(path):
73
78
  return None
74
79
 
75
80
  session=Session(str(Path(config['state_root'])/'engine'),'dpv2',station['connection_id'],
76
- row['id'],request['alias'],client_key=row['subject'],machine_key=row['workstation'],mode='full')
81
+ row['id'],request['alias'],client_key=row['subject'],machine_key=row['workstation'],mode='full',
82
+ jobs_root=str(jobs_root))
77
83
  pointer=directory.parent/'session-location.json'
78
84
  if request['action']=='resume':
79
85
  previous=Path(loads(pointer.read_bytes())['path'])
@@ -162,6 +162,11 @@ def sync(config, jobs, *, only=None):
162
162
  rows = db.execute("SELECT * FROM jobs WHERE state='SUCCEEDED' ORDER BY updated DESC, id").fetchall()
163
163
  newest = {}
164
164
  for row in rows:
165
+ # The shared jobs table may also hold engine-settled rows keyed by the
166
+ # canonical ``mcp-...`` identity, which carry no retained DPV2 tree.
167
+ # Handoff only announces rows the DPV2 supervisor owns.
168
+ if not SUBJECT.fullmatch(row["subject"] or ""):
169
+ continue
165
170
  delivery = delivery_of(row)
166
171
  if delivery is None:
167
172
  continue
@@ -1,15 +1,45 @@
1
- """Durable DPV2 job state; API restarts never replay an execution attempt."""
1
+ """Durable DPV2 job state; API restarts never replay an execution attempt.
2
+
3
+ The schema, connection settings and legacy migration live in
4
+ ``ted_eda_tools.pdk.jobs_store`` because DPV1 and DPV2 share one jobs table: the
5
+ engine that settles a run and the supervisor that launches one write the same
6
+ database. This class only carries the DPV2 supervisor's job workflow on top of
7
+ that shared store.
8
+ """
2
9
  from contextlib import contextmanager
3
10
  import hashlib
4
11
  import json
5
12
  from pathlib import Path
6
13
  import re
7
14
  import secrets
8
- import sqlite3
9
15
  import time
16
+
17
+ try:
18
+ from ted_eda_tools.pdk import jobs_store
19
+ except ImportError: # pragma: no cover - the SDK-less DPV2 CLI load path
20
+ # The plugin CLI (`python -I plugin_cli.py`) must import without the TED SDK;
21
+ # actually opening the jobs table still requires it.
22
+ jobs_store = None
23
+
10
24
  from .installer import canonical, ContractError
11
25
 
12
26
 
27
+ def _shared_store():
28
+ if jobs_store is None:
29
+ raise ContractError('the shared jobs table requires the TED SDK')
30
+ return jobs_store
31
+
32
+
33
+ def shared_store_root(state_root, configured=None):
34
+ """The store root owning the one jobs table (see jobs_store.store_root)."""
35
+ return _shared_store().store_root(state_root, configured)
36
+
37
+
38
+ def shared_db_path(state_root, configured=None):
39
+ """The canonical ``jobs.sqlite3`` under a deployment's store root."""
40
+ return _shared_store().db_path(shared_store_root(state_root, configured))
41
+
42
+
13
43
  class Conflict(ContractError):
14
44
  pass
15
45
 
@@ -19,53 +49,33 @@ class NotFound(ContractError):
19
49
 
20
50
 
21
51
  class Jobs:
22
- def __init__(self, path):
52
+ def __init__(self, path, *, legacy_path=None):
23
53
  self.path = Path(path)
24
54
  self.path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
25
55
  if self.path.is_symlink():
26
56
  raise ContractError('job database cannot be a symlink')
57
+ store=_shared_store()
27
58
  with self.connection() as db:
28
- db.executescript('''
29
- CREATE TABLE IF NOT EXISTS jobs (
30
- id TEXT PRIMARY KEY, subject TEXT NOT NULL, workstation TEXT NOT NULL,
31
- request TEXT NOT NULL, state TEXT NOT NULL, attempt TEXT NOT NULL,
32
- version TEXT NOT NULL, result TEXT, checkpoint_schema TEXT, stopped INTEGER NOT NULL DEFAULT 0,
33
- created REAL NOT NULL, updated REAL NOT NULL);
34
- CREATE TABLE IF NOT EXISTS attempts (
35
- id TEXT PRIMARY KEY, job TEXT NOT NULL, version TEXT NOT NULL,
36
- request TEXT NOT NULL, state TEXT NOT NULL, result TEXT, created REAL NOT NULL);
37
- CREATE TABLE IF NOT EXISTS requests (
38
- subject TEXT NOT NULL, key TEXT NOT NULL, digest TEXT NOT NULL,
39
- job TEXT NOT NULL, attempt TEXT NOT NULL, PRIMARY KEY(subject,key));
40
- CREATE TABLE IF NOT EXISTS events (
41
- seq INTEGER PRIMARY KEY AUTOINCREMENT, job TEXT NOT NULL, attempt TEXT NOT NULL,
42
- body TEXT NOT NULL, created REAL NOT NULL);
43
- CREATE INDEX IF NOT EXISTS events_job ON events(job,seq);
44
- ''')
45
- # I01900 heartbeat lease columns. Databases written by older
46
- # releases upgrade in place: the base schema above is unchanged
47
- # and the lease columns are appended with defaults, so a
48
- # pre-I01900 worker and a post-I01900 worker can both keep
49
- # reading the same file.
50
- columns={row[1] for row in db.execute('PRAGMA table_info(jobs)')}
51
- if 'heartbeat' not in columns:
52
- db.execute('ALTER TABLE jobs ADD COLUMN heartbeat REAL NOT NULL DEFAULT 0')
53
- if 'lease_floor' not in columns:
54
- db.execute('ALTER TABLE jobs ADD COLUMN lease_floor REAL NOT NULL DEFAULT 0')
55
- self.path.chmod(0o600)
59
+ # Schema, lease columns and the unified client_key identity are the
60
+ # shared store's; this class never redefines them.
61
+ store.init_schema(db)
62
+ # A deployment that relocated the jobs table into a shared store
63
+ # imports the old state_root database once; the legacy file stays
64
+ # on disk untouched and re-running is a no-op.
65
+ if legacy_path is not None:
66
+ store.migrate_legacy(db, legacy_path)
67
+ if self.path.parent.stat().st_mode & 0o2000:
68
+ # A deployment-managed shared root uses inherited named ACLs.
69
+ # chmod(600) would erase their mask or fail for the other owner.
70
+ if self.path.stat().st_mode & 0o077 != 0o060:
71
+ raise ContractError('shared jobs database requires a provisioned private read/write ACL mask')
72
+ else:
73
+ self.path.chmod(0o600)
56
74
 
57
75
  @contextmanager
58
76
  def connection(self):
59
- db=sqlite3.connect(self.path,timeout=30)
60
- db.row_factory=sqlite3.Row
61
- db.execute('PRAGMA journal_mode=WAL')
62
- db.execute('PRAGMA synchronous=FULL')
63
- try:
77
+ with _shared_store().connect(self.path) as db:
64
78
  yield db
65
- db.commit()
66
- except BaseException:
67
- db.rollback();raise
68
- finally:db.close()
69
79
 
70
80
  @staticmethod
71
81
  def event(db,job,attempt,body):
@@ -121,8 +131,8 @@ class Jobs:
121
131
  db.execute('UPDATE jobs SET request=?,state=?,attempt=?,version=?,result=NULL,stopped=0,updated=? WHERE id=?',
122
132
  (encoded,'ACCEPTED',attempt,version,now,job))
123
133
  else:
124
- db.execute('INSERT INTO jobs(id,subject,workstation,request,state,attempt,version,created,updated) VALUES(?,?,?,?,?,?,?,?,?)',
125
- (job,subject,workstation,encoded,'ACCEPTED',attempt,version,now,now))
134
+ db.execute('INSERT INTO jobs(id,subject,workstation,request,state,attempt,version,created,updated,client_key) VALUES(?,?,?,?,?,?,?,?,?,?)',
135
+ (job,subject,workstation,encoded,'ACCEPTED',attempt,version,now,now,_shared_store().client_key(subject)))
126
136
  db.execute('INSERT INTO requests VALUES(?,?,?,?,?)',(subject,key,fingerprint,job,attempt))
127
137
  self.event(db,job,attempt,{'event':'accepted','plugin_version':version})
128
138
  return dict(self.public(db.execute('SELECT * FROM jobs WHERE id=?',(job,)).fetchone()),replayed=False,submission_attempt=attempt)
@@ -274,18 +284,10 @@ class Jobs:
274
284
  return dict(self.get(subject,row['job']),submission_attempt=row['attempt'])
275
285
 
276
286
  def latest_delivery(self,subject,alias):
277
- """Latest confirmed INSTALLED delivery this subject owns for the alias.
287
+ """Latest confirmed INSTALLED delivery for the alias from the shared table.
278
288
 
279
- The old check action needs a reuse answer. DPV2 keeps server-side
280
- cross-subject reuse closed, so the only honest reusable asset is this
281
- subject's own completed adaptation history.
289
+ The row may have been written by this supervisor or settled by the same
290
+ engine DPV1 runs; both live in the one jobs database, so the reuse check
291
+ reads a single place.
282
292
  """
283
- with self.connection() as db:
284
- rows=db.execute("SELECT * FROM jobs WHERE subject=? AND state='SUCCEEDED' ORDER BY updated DESC",(subject,)).fetchall()
285
- for row in rows:
286
- if json.loads(row['request']).get('alias')!=alias:continue
287
- result=json.loads(row['result']) if row['result'] else None
288
- delivery=(result or {}).get('delivery') or {}
289
- if delivery.get('status')=='INSTALLED':
290
- return dict(self.public(row),delivery=delivery)
291
- return None
293
+ return _shared_store().latest_delivery(self.path,subject,alias)
@@ -23,6 +23,7 @@ import sys
23
23
  import time
24
24
  from .installer import ContractError, atomic, canonical, loads
25
25
  from .executor import live
26
+ from .jobs import shared_db_path
26
27
  from .worker import Worker
27
28
 
28
29
 
@@ -131,13 +132,13 @@ def reap(state_root,config,apply=False):
131
132
  report=survey(state_root,config)
132
133
  if not apply:return dict(report,applied=False)
133
134
  target=Path(state_root).absolute()
134
- database=target/'jobs.sqlite3'
135
+ database=shared_db_path(target,config.get('delivery_store_root'))
135
136
  if not database.is_file():raise ContractError('jobs database missing; refusing to apply')
136
137
  worker=open_worker(target,config)
137
138
  reapable=[row for row in report['attempts'] if row['reapable']]
138
139
  with (target/'.ops-reap.lock').open('a') as stream:
139
140
  fcntl.flock(stream,fcntl.LOCK_EX)
140
- backup=_backup(database,target)
141
+ backup=_backup(database,database.parent)
141
142
  results=[]
142
143
  with worker.jobs.connection() as db:
143
144
  full={row['id']:dict(row) for row in
@@ -25,6 +25,8 @@ import sys
25
25
  import time
26
26
  from pathlib import Path
27
27
 
28
+ from .jobs import shared_db_path
29
+
28
30
  from .handoff import IDENTIFIER, SUBJECT
29
31
 
30
32
  TERMINAL_STATES = frozenset({'SUCCEEDED', 'FAILED', 'CANCELLED'})
@@ -79,7 +81,7 @@ def plan(state_root, retention_days):
79
81
  """
80
82
  state = Path(state_root)
81
83
  engine = state / 'engine' / 'dpv2' / 'clients'
82
- db_path = state / 'jobs.sqlite3'
84
+ db_path = shared_db_path(state)
83
85
  if not engine.is_dir() or not db_path.is_file():
84
86
  raise SystemExit('engine store or jobs database missing under ' + str(state))
85
87
  cutoff = time.time() - retention_days * 86400
@@ -18,7 +18,7 @@ import urllib.error
18
18
  import urllib.parse
19
19
  import urllib.request
20
20
  from .installer import ContractError, NoRedirect, canonical, endpoint, loads, manifest, TARGETS,tls_context
21
- from .jobs import Jobs, Conflict, NotFound
21
+ from .jobs import Jobs, Conflict, NotFound, shared_db_path
22
22
  from .sessions import Sessions, check_secret
23
23
  from .workstations import Workstations, EnrollmentReader, Unavailable
24
24
 
@@ -83,12 +83,19 @@ class Application:
83
83
  self.candidate=candidate
84
84
  self.state=Path(config['state_root']).absolute()
85
85
  self.state.mkdir(parents=True,exist_ok=True,mode=0o700)
86
- self.jobs=Jobs(self.state/'jobs.sqlite3')
86
+ # The jobs table is the single history both faces share. A deployment
87
+ # that keeps it in a shared PDK store sets delivery_store_root; otherwise
88
+ # the service state root owns it. The old state_root file is migrated once.
89
+ jobs_path=shared_db_path(self.state,config.get('delivery_store_root'))
90
+ legacy_jobs=self.state/'jobs.sqlite3'
91
+ self.jobs=Jobs(jobs_path,legacy_path=legacy_jobs if jobs_path!=legacy_jobs else None)
87
92
  self.workstations=Workstations(self.state/'workstations.sqlite3')
88
93
  self.sessions=Sessions(self.state/'sessions.sqlite3') if config.get('session_secret_file') else None
89
94
  self.auth=Auth(self.state/'auth.sqlite3',config['account'])
90
95
  self.public=Path(config['public_root']).resolve()
91
96
  self.releases=Path(config['releases_root']).resolve()
97
+ # I02195: same store-root resolver as readiness/engine; tests may pin it.
98
+ self.home=Path(config.get('store_root_home') or Path.home())
92
99
 
93
100
  def version(self,target):
94
101
  if target not in TARGETS:raise ContractError('unsupported client target')
@@ -102,14 +109,33 @@ class Application:
102
109
  return self.workstations.get(subject,identifier)
103
110
 
104
111
  def check(self,subject,request):
105
- """Old check face over DPV2's own durable history; never starts work.
112
+ """Old check face over the one shared adaptation history; never starts work.
106
113
 
107
114
  DPV1 semantics kept where the state exists: REUSED needs the caller to
108
115
  confirm the installed delivery digest via use_client_revision, because
109
116
  DPV2 has no client back-channel to compare the vendor content itself.
117
+
118
+ DPV1 and DPV2 run the same adaptation engine and write one jobs table,
119
+ so ownership history is read from that single place (I02179).
110
120
  """
111
121
  alias=request['alias'];mode=request['mode'];vendor=request.get('vendor_dir','')
112
- found=self.jobs.latest_delivery(subject,alias)
122
+ revision=request.get('use_client_revision','')
123
+ found=self.engine_delivery(subject,alias,revision=revision,
124
+ allow_follow=bool(self.config.get('store_root_follow',False)))
125
+ if found is not None and found.get('status')=='STORE_ROOT_MOVED':
126
+ # I02195: the record exists in another store root; do not disguise
127
+ # this as "not adapted" or silently fall back to the jobs table.
128
+ return {'ok':False,'status':'STORE_ROOT_MOVED','pdk_id':alias,'mode':mode,
129
+ 'configured_root':found.get('configured_root'),
130
+ 'recorded_root':found.get('recorded_root'),
131
+ 'reason':found.get('reason'),
132
+ 'reuse_available':False,'adaptation_started':False,
133
+ 'next_action':'align_store_root',
134
+ 'message':'该账号的适配交付记录位于另一个 PDK store 根(configured=%s, recorded=%s);'
135
+ '请统一 TEDBRAIN_PDK_STORE_ROOT,或显式开启受控跟随并提交匹配的客户端摘要。'
136
+ % (found.get('configured_root'),found.get('recorded_root'))}
137
+ if found is None:
138
+ found=self.jobs.latest_delivery(subject,alias)
113
139
  if found is None:
114
140
  if vendor:
115
141
  return {'ok':False,'status':'ADAPTATION_REQUIRED','pdk_id':alias,'mode':mode,
@@ -120,20 +146,56 @@ class Application:
120
146
  'message':'DPV2 未启用公共工艺复用,也没有该账号的既有交付;请提供原始 PDK 目录进行适配。'}
121
147
  delivery=found['delivery'];tree=delivery.get('tree_sha256','')
122
148
  revision=request.get('use_client_revision','')
149
+ origin=found.get('origin','dpv2-history');completed_mode=found.get('completed_mode') or 'full'
123
150
  if tree and revision==tree:
124
151
  return {'ok':True,'status':'REUSED','job_status':'REUSED','pdk_id':alias,'mode':mode,
125
152
  'adaptation_started':False,'run_id':found['job_id'],'workstation_id':found['workstation_id'],
126
- 'origin':'dpv2-history','version':tree,'match_method':'client_revision','completed_mode':'full'}
153
+ 'origin':origin,'version':tree,'match_method':'client_revision','completed_mode':completed_mode}
127
154
  if revision:
128
155
  return {'ok':False,'status':'ADAPTATION_REQUIRED','pdk_id':alias,'mode':mode,'adaptation_started':False,
129
- 'previous_run_id':found['job_id'],
130
- 'message':'确认的安装摘要与既有 DPV2 交付不一致;请核实当前安装的交付摘要,或以原始 PDK 目录重新适配。'}
156
+ 'previous_run_id':found['job_id'],'origin':origin,
157
+ 'message':'确认的安装摘要与既有交付不一致;请核实当前安装的交付摘要,或以原始 PDK 目录重新适配。'}
131
158
  return {'ok':False,'status':'CLIENT_CONFIRMATION_REQUIRED','pdk_id':alias,'mode':mode,'adaptation_started':False,
132
159
  'run_id':found['job_id'],'workstation_id':found['workstation_id'],'delivery_tree_sha256':tree,
133
- 'next_action':'confirm_revision_or_start_adaptation',
134
- 'message':'已有 DPV2 交付(run_id=%s)。请用 --use-client-revision 提交当前安装的交付摘要以确认复用,'
160
+ 'origin':origin,'next_action':'confirm_revision_or_start_adaptation',
161
+ 'message':'已有适配交付(run_id=%s)。请用 --use-client-revision 提交当前安装的交付摘要以确认复用,'
135
162
  '或提供 --vendor-dir 重新适配。'%found['job_id']}
136
163
 
164
+ def engine_delivery(self,subject,alias,*,revision=None,allow_follow=False):
165
+ """Installed delivery the shared adaptation engine recorded for this subject.
166
+
167
+ The engine settles runs below ``<store>/mcp/clients/<client_key>/``, the
168
+ one place both faces write to. Reading it here keeps DPV2 independent of
169
+ the DPV1 process while sharing its records (I02165). No record is trusted
170
+ on its own: reuse still needs the client-confirmed revision to match.
171
+
172
+ I02195: the configured root and the root recorded in the delivery are
173
+ compared; a delivery only found under another recorded root returns a
174
+ ``STORE_ROOT_MOVED`` decision, or a controlled follow when explicitly
175
+ enabled, the subject matches and the client revision equals the digest.
176
+ """
177
+ try:
178
+ from ted_eda_tools.pdk import store_root
179
+ configured,_=store_root.resolve(self.config.get('delivery_store_root'),
180
+ environ=os.environ,home=self.home)
181
+ located=store_root.locate(configured,self.home,subject,alias)
182
+ except (ImportError,OSError,ValueError):
183
+ return None
184
+ if not located:
185
+ return None
186
+ root,recorded,found=located
187
+ delivery=dict(found['delivery'],status='INSTALLED')
188
+ if not store_root.same(root,configured):
189
+ decision=store_root.classify(configured,recorded,subject=subject,
190
+ request_subject=subject,revision=revision,
191
+ digest=delivery.get('tree_sha256'),
192
+ allow_follow=allow_follow)
193
+ if decision.get('status')!='follow':
194
+ return decision
195
+ return {'job_id':found.get('run_id'),'workstation_id':None,'origin':'engine-delivery',
196
+ 'delivery':delivery,'completed_mode':found.get('mode'),
197
+ 'store_root':recorded}
198
+
137
199
  def worker(self):
138
200
  if self.candidate:
139
201
  release=self.config.get('candidate_worker')
@@ -159,7 +221,10 @@ class Application:
159
221
  raise ContractError('session request must name subject, workstation_id, plugin, job and ttl')
160
222
  subject=body['subject']
161
223
  station=self.workstations.get(subject,body['workstation_id'])
162
- token=Path(self.config['serve_token_file']).read_text().strip()
224
+ token_path=Path(self.config.get('transport',{}).get('serve_token_file',''))
225
+ if not token_path.is_absolute() or not token_path.is_file() or token_path.is_symlink() or token_path.stat().st_mode&0o077:
226
+ raise ContractError('private workstation serve credential is not configured')
227
+ token=token_path.read_text().strip()
163
228
  executor=self.config.get('executor_contracts',{}).get(station['release_sha256'])
164
229
  if not executor or not executor.get('components'):
165
230
  raise ContractError('the workstation runtime has no executor contract')
@@ -16,6 +16,7 @@ import time
16
16
 
17
17
  from .installer import ContractError, atomic, canonical, loads
18
18
  from .worker import Worker
19
+ from .jobs import shared_db_path
19
20
 
20
21
 
21
22
  class VersionWorker(Worker):
@@ -55,6 +56,9 @@ def load_registry(path):
55
56
  rows = spec.get('versions')
56
57
  if not isinstance(rows, list) or not rows:
57
58
  raise ContractError('explicit pinned worker configurations required')
59
+ shared=spec.get('delivery_store_root')
60
+ if shared is not None and (not isinstance(shared,str) or not Path(shared).is_absolute() or '..' in Path(shared).parts or Path(shared).is_symlink()):
61
+ raise ContractError('real absolute shared jobs store required')
58
62
  configs = {}
59
63
  for row in rows:
60
64
  version = row.get('version', '')
@@ -74,7 +78,8 @@ def load_registry(path):
74
78
  raise ContractError('worker version/state differs from registry')
75
79
  # Engine executable, SDK, runtime, transport and original configuration
76
80
  # remain pinned. Only dispatcher admission budgets are centrally set.
77
- configs[version] = dict(config, max_active_jobs=per, max_total_jobs=total)
81
+ configs[version] = dict(config, max_active_jobs=per, max_total_jobs=total,
82
+ **({'delivery_store_root':shared} if shared is not None else {}))
78
83
  return spec, configs
79
84
 
80
85
 
@@ -109,7 +114,7 @@ class Supervisor:
109
114
  def tick(self):
110
115
  if not self.acquired:
111
116
  raise ContractError('supervisor version locks are not held')
112
- with sqlite3.connect('file:' + str(self.state / 'jobs.sqlite3') + '?mode=ro', uri=True) as db:
117
+ with sqlite3.connect('file:' + str(shared_db_path(self.state,self.spec.get('delivery_store_root'))) + '?mode=ro', uri=True) as db:
113
118
  active = {row[0] for row in db.execute(
114
119
  "SELECT DISTINCT version FROM jobs WHERE state IN ('ACCEPTED','RUNNING','CANCELLING','UNKNOWN')")}
115
120
  missing = active - set(self.workers)
@@ -14,7 +14,7 @@ import subprocess
14
14
  import sys
15
15
  import time
16
16
  from .installer import ContractError, atomic, canonical, loads
17
- from .jobs import Conflict, Jobs
17
+ from .jobs import Conflict, Jobs, shared_db_path
18
18
  from .workstations import Workstations
19
19
  from .executor import live
20
20
  from .handoff import sync as sync_handoff
@@ -24,7 +24,10 @@ class Worker:
24
24
  def __init__(self, config):
25
25
  self.config=config
26
26
  self.state=Path(config['state_root']).absolute()
27
- self.jobs=Jobs(self.state/'jobs.sqlite3')
27
+ # The supervisor writes the same one jobs table the engine settles into.
28
+ jobs_path=shared_db_path(self.state,config.get('delivery_store_root'))
29
+ legacy_jobs=self.state/'jobs.sqlite3'
30
+ self.jobs=Jobs(jobs_path,legacy_path=legacy_jobs if jobs_path!=legacy_jobs else None)
28
31
  self.stations=Workstations(self.state/'workstations.sqlite3')
29
32
  self.root=self.state/'executions';self.root.mkdir(parents=True,exist_ok=True,mode=0o700)
30
33
  self.version=config['worker_version']