mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-15 23:20:49 +08:00
Wait for workspaceRegistry before provisioning user workspaces.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
e9040224fb
commit
f98d283118
3 changed files with 72 additions and 8 deletions
|
|
@ -699,13 +699,50 @@ function installSettingsSection(ctx, entry, hooks) {
|
|||
|
||||
|
||||
let _workspaceRegistry = null
|
||||
let _workspaceRegistryWaiters = []
|
||||
|
||||
function notifyWorkspaceRegistryReady(registry) {
|
||||
_workspaceRegistry = registry || null
|
||||
const waiters = _workspaceRegistryWaiters.splice(0)
|
||||
for (const w of waiters) {
|
||||
try { clearTimeout(w.timer) } catch { /* ignore */ }
|
||||
try { w.resolve(_workspaceRegistry) } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
/** Wait until workspaceRegistry inject fires (or timeout). */
|
||||
function whenWorkspaceRegistry(timeoutMs = 30000) {
|
||||
if (_workspaceRegistry) return Promise.resolve(_workspaceRegistry)
|
||||
return new Promise((resolve) => {
|
||||
const entry = {
|
||||
resolve,
|
||||
timer: setTimeout(() => {
|
||||
const i = _workspaceRegistryWaiters.indexOf(entry)
|
||||
if (i >= 0) _workspaceRegistryWaiters.splice(i, 1)
|
||||
resolve(_workspaceRegistry || null)
|
||||
}, timeoutMs),
|
||||
}
|
||||
_workspaceRegistryWaiters.push(entry)
|
||||
})
|
||||
}
|
||||
|
||||
async function ensureUserWorkspace(empNo) {
|
||||
if (!_userWorkspaces) return null
|
||||
try {
|
||||
let registry = _workspaceRegistry
|
||||
if (!registry) {
|
||||
registry = await whenWorkspaceRegistry(30000)
|
||||
}
|
||||
const root = _currentConfig?.workspaceRoot
|
||||
if (!registry) {
|
||||
console.warn(
|
||||
'[uds-auth] workspaceRegistry still unavailable after wait; mkdir only under',
|
||||
root || '(default $DSH_HOME/user-workspaces)',
|
||||
)
|
||||
}
|
||||
return await _userWorkspaces.ensureUserWorkspace(
|
||||
{ workspaceRegistryHandle: _workspaceRegistry },
|
||||
_currentConfig?.workspaceRoot,
|
||||
{ workspaceRegistryHandle: registry },
|
||||
root,
|
||||
empNo,
|
||||
)
|
||||
} catch (err) {
|
||||
|
|
@ -714,6 +751,21 @@ async function ensureUserWorkspace(empNo) {
|
|||
}
|
||||
}
|
||||
|
||||
async function rebindPendingUserWorkspaces() {
|
||||
if (!_userWorkspaces || !_workspaceRegistry) return
|
||||
try {
|
||||
const users = _userWorkspaces._map
|
||||
if (!users || typeof users.keys !== 'function') return
|
||||
for (const empNo of users.keys()) {
|
||||
const row = users.get(empNo)
|
||||
if (row && row.workspaceId) continue
|
||||
try { await ensureUserWorkspace(empNo) } catch { /* ignore */ }
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[uds-auth] rebindPendingUserWorkspaces failed:', err.message)
|
||||
}
|
||||
}
|
||||
|
||||
export async function apply(ctx, config = {}) {
|
||||
let source = () => mergeConfig(config)
|
||||
_currentConfig = source()
|
||||
|
|
@ -809,8 +861,9 @@ async function initServices(ctx, config) {
|
|||
})
|
||||
|
||||
ctx.inject(['workspaceRegistry'], (wctx) => {
|
||||
_workspaceRegistry = wctx.workspaceRegistry
|
||||
notifyWorkspaceRegistryReady(wctx.workspaceRegistry)
|
||||
ctx.logger?.info?.('[uds-auth] workspaceRegistry ready')
|
||||
void rebindPendingUserWorkspaces()
|
||||
})
|
||||
|
||||
installDshAcl(ctx, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue