-
Notifications
You must be signed in to change notification settings - Fork 27
feat(fleet): MothershipClient rename, WorkQueueService skeleton & server wiring #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OgnjenGligoric
wants to merge
3
commits into
andresharpe:releases/4.1.0
Choose a base branch
from
OgnjenGligoric:feat/544-fleet-server-mothership-client-4.1
base: releases/4.1.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Compatibility shim for runtime-owned notification/mothership helpers. | ||
|
|
||
| .DESCRIPTION | ||
| Mothership client logic lives in Dotbot.Notification. Existing MCP and UI | ||
| callers can import this module — it forwards to Dotbot.Notification via a | ||
| global import so the same function names remain available. | ||
| #> | ||
|
|
||
| $notifModule = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'runtime' 'Modules' 'Dotbot.Notification' 'Dotbot.Notification.psd1' | ||
| if (-not (Get-Module Dotbot.Notification)) { | ||
| Import-Module $notifModule -DisableNameChecking -Global | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,10 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Compatibility shim for runtime-owned notification helpers. | ||
| Deprecated: use MothershipClient.psm1 instead. | ||
|
|
||
| .DESCRIPTION | ||
| Notification client logic now lives in Dotbot.Notification. Existing MCP and | ||
| UI callers can keep importing this module — it forwards to Dotbot.Notification | ||
| via a global import so the same function names remain available. | ||
| This shim is kept for backward compatibility. It forwards to MothershipClient.psm1. | ||
| New callers should import MothershipClient.psm1 directly. | ||
| #> | ||
|
|
||
| $notifModule = Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) 'runtime' 'Modules' 'Dotbot.Notification' 'Dotbot.Notification.psd1' | ||
| if (-not (Get-Module Dotbot.Notification)) { | ||
| Import-Module $notifModule -DisableNameChecking -Global | ||
| } | ||
| Import-Module (Join-Path $PSScriptRoot 'MothershipClient.psm1') -Force -Global |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Work queue service skeleton for fleet task dispatch (Phase 10 / Drone). | ||
|
|
||
| .DESCRIPTION | ||
| Provides a file-based work queue that the Mothership uses to dispatch tasks to | ||
| registered drone runtimes. Storage mirrors FleetAPI.psm1: JSON files under | ||
| fleet/queue/<RuntimeId>/. | ||
|
|
||
| This is a skeleton — function signatures are stable and importable by #96 | ||
| (Drone agent), but full dispatch logic is deferred to the Drone phase. | ||
| #> | ||
|
|
||
| $script:QueueConfig = @{ | ||
| ControlDir = $null | ||
| } | ||
|
|
||
| function Initialize-WorkQueueService { | ||
| <# | ||
| .SYNOPSIS | ||
| Sets up the work queue storage directory. Call once at server startup. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)][string]$ControlDir | ||
| ) | ||
| $script:QueueConfig.ControlDir = $ControlDir | ||
| $queueRoot = _Get-QueueRoot | ||
| if (-not (Test-Path -LiteralPath $queueRoot)) { | ||
| New-Item -ItemType Directory -Path $queueRoot -Force | Out-Null | ||
| } | ||
| } | ||
|
|
||
| function Enqueue-WorkItem { | ||
| <# | ||
| .SYNOPSIS | ||
| Adds a work item to a runtime's queue. | ||
| .PARAMETER RuntimeId | ||
| The target runtime that should process this item. | ||
| .PARAMETER TaskId | ||
|
OgnjenGligoric marked this conversation as resolved.
|
||
| The task ID to dispatch. | ||
| .PARAMETER Payload | ||
| Arbitrary hashtable of additional context (workflow name, run id, etc.). | ||
| .OUTPUTS | ||
| Hashtable with the new item's id and queued_at timestamp. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)][string]$RuntimeId, | ||
| [Parameter(Mandatory)][string]$TaskId, | ||
| [hashtable]$Payload = @{} | ||
| ) | ||
|
|
||
| $itemId = "wqi-$([guid]::NewGuid().ToString('N').Substring(0, 12))" | ||
| $item = [ordered]@{ | ||
| id = $itemId | ||
| runtime_id = $RuntimeId | ||
| task_id = $TaskId | ||
| payload = $Payload | ||
| status = 'pending' | ||
| queued_at = (Get-Date).ToUniversalTime().ToString('o') | ||
| } | ||
|
|
||
| $dir = _Get-RuntimeQueueDir -RuntimeId $RuntimeId | ||
| if (-not (Test-Path -LiteralPath $dir)) { | ||
| New-Item -ItemType Directory -Path $dir -Force | Out-Null | ||
| } | ||
| _Write-QueueJson -Path (Join-Path $dir "$itemId.json") -Value $item | ||
|
|
||
| return @{ id = $itemId; queued_at = $item.queued_at } | ||
| } | ||
|
|
||
| function Dequeue-WorkItem { | ||
| <# | ||
| .SYNOPSIS | ||
| Pops the next pending work item for a runtime (FIFO by queued_at). | ||
| Marks the item as 'leased' so it is not returned again. | ||
| Returns $null when the queue is empty. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)][string]$RuntimeId | ||
| ) | ||
|
|
||
| $dir = _Get-RuntimeQueueDir -RuntimeId $RuntimeId | ||
| $files = @(Get-ChildItem -LiteralPath $dir -Filter '*.json' -File -ErrorAction SilentlyContinue) | ||
|
|
||
| $nextFile = $null | ||
| $nextItem = $null | ||
| $nextQueuedAt = [DateTime]::MaxValue | ||
|
|
||
| foreach ($file in $files) { | ||
| $item = _Read-QueueJson -Path $file.FullName | ||
| if (-not $item -or $item['status'] -ne 'pending') { continue } | ||
|
|
||
| try { $queuedAt = [DateTime]::Parse([string]$item['queued_at']).ToUniversalTime() } catch { $queuedAt = [DateTime]::MaxValue } | ||
| if ($queuedAt -lt $nextQueuedAt) { | ||
| $nextQueuedAt = $queuedAt | ||
| $nextFile = $file | ||
| $nextItem = $item | ||
| } | ||
| } | ||
|
|
||
| if (-not $nextItem) { return $null } | ||
|
|
||
| $nextItem['status'] = 'leased' | ||
| $nextItem['leased_at'] = (Get-Date).ToUniversalTime().ToString('o') | ||
| _Write-QueueJson -Path $nextFile.FullName -Value $nextItem | ||
|
|
||
| return [ordered]@{ | ||
| id = $nextItem['id'] | ||
| runtime_id = $nextItem['runtime_id'] | ||
| task_id = $nextItem['task_id'] | ||
| payload = $nextItem['payload'] | ||
| queued_at = $nextItem['queued_at'] | ||
| leased_at = $nextItem['leased_at'] | ||
| } | ||
| } | ||
|
|
||
| function Get-WorkQueueDepth { | ||
| <# | ||
| .SYNOPSIS | ||
| Returns the count of pending (not yet leased) items for a runtime. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)][string]$RuntimeId | ||
| ) | ||
|
|
||
| $dir = _Get-RuntimeQueueDir -RuntimeId $RuntimeId | ||
| $count = 0 | ||
| foreach ($file in Get-ChildItem -LiteralPath $dir -Filter '*.json' -File -ErrorAction SilentlyContinue) { | ||
| $item = _Read-QueueJson -Path $file.FullName | ||
| if ($item -and $item['status'] -eq 'pending') { $count++ } | ||
| } | ||
| return $count | ||
| } | ||
|
|
||
| function Complete-WorkItem { | ||
| <# | ||
| .SYNOPSIS | ||
| Marks a leased work item as completed. Called by the drone after finishing. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)][string]$RuntimeId, | ||
| [Parameter(Mandatory)][string]$ItemId | ||
| ) | ||
|
|
||
| $path = Join-Path (_Get-RuntimeQueueDir -RuntimeId $RuntimeId) "$ItemId.json" | ||
| $item = _Read-QueueJson -Path $path | ||
| if (-not $item) { return @{ success = $false; error = 'item not found' } } | ||
| if ($item['status'] -ne 'leased') { | ||
| return @{ success = $false; error = "item is not leased (status=$($item['status']))" } | ||
| } | ||
|
|
||
| $item['status'] = 'completed' | ||
| $item['completed_at'] = (Get-Date).ToUniversalTime().ToString('o') | ||
| _Write-QueueJson -Path $path -Value $item | ||
|
|
||
| return @{ success = $true } | ||
| } | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Private helpers | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| function _Get-QueueRoot { | ||
| return Join-Path $script:QueueConfig.ControlDir 'fleet' 'queue' | ||
| } | ||
|
|
||
| function _Get-RuntimeQueueDir { | ||
| param([Parameter(Mandatory)][string]$RuntimeId) | ||
| $safe = $RuntimeId -replace '[^A-Za-z0-9_.-]', '_' | ||
| return Join-Path (_Get-QueueRoot) $safe | ||
| } | ||
|
|
||
| function _Read-QueueJson { | ||
| param([Parameter(Mandatory)][string]$Path) | ||
| if (-not (Test-Path -LiteralPath $Path)) { return $null } | ||
| try { return Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json -AsHashtable } catch { return $null } | ||
| } | ||
|
|
||
| function _Write-QueueJson { | ||
| param( | ||
| [Parameter(Mandatory)][string]$Path, | ||
| [Parameter(Mandatory)][object]$Value | ||
| ) | ||
| $tmp = "$Path.tmp" | ||
| [System.IO.File]::WriteAllText($tmp, ($Value | ConvertTo-Json -Depth 20), [System.Text.UTF8Encoding]::new($false)) | ||
| Move-Item -LiteralPath $tmp -Destination $Path -Force | ||
| } | ||
|
|
||
| Export-ModuleMember -Function @( | ||
| 'Initialize-WorkQueueService', | ||
| 'Enqueue-WorkItem', | ||
| 'Dequeue-WorkItem', | ||
| 'Get-WorkQueueDepth', | ||
| 'Complete-WorkItem' | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.