-
Notifications
You must be signed in to change notification settings - Fork 20
feat(schema): watchers — device_worker_id, agent_kind, notification, cooldown columns #811
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
Merged
Merged
Changes from all commits
Commits
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
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,78 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Adds the columns needed by the device-aware watcher dispatcher (see | ||
| -- lobu-ai/lobu#798 / #799): | ||
| -- | ||
| -- * device_worker_id — pin a watcher to a specific device worker | ||
| -- (when its inputs live on that device). | ||
| -- * agent_kind — overrides the owning agent's default kind for | ||
| -- this watcher (e.g. "background", "notifier"). | ||
| -- * notification_channel — where firings surface: canvas, OS notification, | ||
| -- or both. | ||
| -- * notification_priority — priority class used by the dispatcher's | ||
| -- interrupt budget. | ||
| -- * min_cooldown_seconds — minimum seconds between two firings of the | ||
| -- same watcher (0 = no cooldown). | ||
| -- * last_fired_at — last time this watcher actually dispatched | ||
| -- a notification/canvas item. | ||
| -- | ||
| -- Also adds device_workers.notification_budget_per_day for the per-device | ||
| -- global interrupt budget. 10/day is a placeholder default; tune later. | ||
|
|
||
| ALTER TABLE public.watchers | ||
| ADD COLUMN device_worker_id uuid REFERENCES public.device_workers(id), | ||
| ADD COLUMN agent_kind text, | ||
| ADD COLUMN notification_channel text NOT NULL DEFAULT 'canvas', | ||
| ADD COLUMN notification_priority text NOT NULL DEFAULT 'normal', | ||
| ADD COLUMN min_cooldown_seconds integer NOT NULL DEFAULT 0, | ||
| ADD COLUMN last_fired_at timestamp with time zone; | ||
|
|
||
| ALTER TABLE public.watchers | ||
| ADD CONSTRAINT watchers_notification_channel_check | ||
| CHECK (notification_channel IN ('canvas', 'notification', 'both')); | ||
|
|
||
| ALTER TABLE public.watchers | ||
| ADD CONSTRAINT watchers_notification_priority_check | ||
| CHECK (notification_priority IN ('low', 'normal', 'high')); | ||
|
|
||
| ALTER TABLE public.watchers | ||
| ADD CONSTRAINT watchers_min_cooldown_seconds_nonneg | ||
| CHECK (min_cooldown_seconds >= 0); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_watchers_device_worker_id | ||
| ON public.watchers (device_worker_id) | ||
| WHERE device_worker_id IS NOT NULL; | ||
|
|
||
| ALTER TABLE public.device_workers | ||
| ADD COLUMN notification_budget_per_day integer NOT NULL DEFAULT 10; | ||
|
|
||
| ALTER TABLE public.device_workers | ||
| ADD CONSTRAINT device_workers_notification_budget_per_day_nonneg | ||
| CHECK (notification_budget_per_day >= 0); | ||
|
|
||
| -- migrate:down | ||
|
|
||
| ALTER TABLE public.device_workers | ||
| DROP CONSTRAINT IF EXISTS device_workers_notification_budget_per_day_nonneg; | ||
|
|
||
| ALTER TABLE public.device_workers | ||
| DROP COLUMN IF EXISTS notification_budget_per_day; | ||
|
|
||
| DROP INDEX IF EXISTS public.idx_watchers_device_worker_id; | ||
|
|
||
| ALTER TABLE public.watchers | ||
| DROP CONSTRAINT IF EXISTS watchers_min_cooldown_seconds_nonneg; | ||
|
|
||
| ALTER TABLE public.watchers | ||
| DROP CONSTRAINT IF EXISTS watchers_notification_priority_check; | ||
|
|
||
| ALTER TABLE public.watchers | ||
| DROP CONSTRAINT IF EXISTS watchers_notification_channel_check; | ||
|
|
||
| ALTER TABLE public.watchers | ||
| DROP COLUMN IF EXISTS last_fired_at, | ||
| DROP COLUMN IF EXISTS min_cooldown_seconds, | ||
| DROP COLUMN IF EXISTS notification_priority, | ||
| DROP COLUMN IF EXISTS notification_channel, | ||
| DROP COLUMN IF EXISTS agent_kind, | ||
| DROP COLUMN IF EXISTS device_worker_id; |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When callers set
device_worker_idon a watcher, the pin is only stored onwatchers;createWatcherRun()still buildsruns.approved_inputwithout that field, while the server dispatcher only skips device-bound watcher runs by checkingapproved_input->>'device_worker_id'. As a result, scheduled or manually triggered runs for a pinned watcher are still claimed and executed by the server-side dispatcher instead of being left for the user's device worker.Useful? React with 👍 / 👎.