replace urgency priority queue with strict FIFO
Drop the urgency score and interrupt/preempt decisions: intake is now idle -> dispatch, busy -> append to a bounded FIFO queue (RequestQueue). The running process always finishes before the next queued request. - queue.py: UrgencyQueue -> RequestQueue (deque, no weight/age/recency) - scheduler.py: remove _priority_score, _interrupt_choice, urgency constants, and the weight threaded through dispatch/authoring/requeue - dashboard/static/gateway: drop weight + preempted handling - tests + docs updated; flow-main.svg regenerated
This commit is contained in:
1 parent
a354958599
commit
1dc0550659
18 files changed
+173
-341
No files matched your search
+23
-58
@@ -1,74 +1,39 @@
|
||||
import pytest
|
||||
|
||||
from semif_agent.queue import UrgencyQueue
|
||||
from semif_agent.queue import RequestQueue
|
||||
from semif_agent.decisions import Request
|
||||
|
||||
|
||||
def make(text, weight):
|
||||
return Request(text=text), weight
|
||||
def make(text):
|
||||
return Request(text=text)
|
||||
|
||||
|
||||
def test_order_by_weight_desc():
|
||||
q = UrgencyQueue()
|
||||
req_a, _ = make("low", 0.25)
|
||||
req_c, _ = make("critical", 1.0)
|
||||
req_h, _ = make("high", 0.75)
|
||||
q.push(req_a, 0.25)
|
||||
q.push(req_c, 1.0)
|
||||
q.push(req_h, 0.75)
|
||||
assert q.pop().text == "critical"
|
||||
assert q.pop().text == "high"
|
||||
assert q.pop().text == "low"
|
||||
def test_fifo_order():
|
||||
q = RequestQueue()
|
||||
q.push(make("first"))
|
||||
q.push(make("second"))
|
||||
q.push(make("third"))
|
||||
assert q.pop().text == "first"
|
||||
assert q.pop().text == "second"
|
||||
assert q.pop().text == "third"
|
||||
assert q.pop() is None
|
||||
|
||||
|
||||
def test_fifo_tiebreak():
|
||||
q = UrgencyQueue()
|
||||
req_a, _ = make("first", 0.5)
|
||||
req_b, _ = make("second", 0.5)
|
||||
q.push(req_a, 0.5)
|
||||
q.push(req_b, 0.5)
|
||||
assert q.pop().text == "first"
|
||||
assert q.pop().text == "second"
|
||||
|
||||
|
||||
def test_fifo_beats_recency():
|
||||
q = UrgencyQueue()
|
||||
old, _ = make("older", 0.5)
|
||||
new, _ = make("newer", 0.5)
|
||||
q.push(old, 0.5, recency=1.0)
|
||||
q.push(new, 0.5, recency=2.0)
|
||||
assert q.pop().text == "older"
|
||||
|
||||
|
||||
def test_peek_does_not_remove():
|
||||
q = UrgencyQueue()
|
||||
req, _ = make("peek", 0.9)
|
||||
q.push(req, 0.9)
|
||||
q = RequestQueue()
|
||||
q.push(make("peek"))
|
||||
assert q.peek().text == "peek"
|
||||
assert len(q) == 1
|
||||
|
||||
|
||||
def test_bounds_reject():
|
||||
q = UrgencyQueue(max_size=2)
|
||||
assert q.push(make("a", 1.0)[0], 1.0)
|
||||
assert q.push(make("b", 1.0)[0], 1.0)
|
||||
assert not q.push(make("c", 1.0)[0], 1.0)
|
||||
q = RequestQueue(max_size=2)
|
||||
assert q.push(make("a"))
|
||||
assert q.push(make("b"))
|
||||
assert not q.push(make("c"))
|
||||
|
||||
|
||||
def test_age_raises_priority():
|
||||
q = UrgencyQueue(age_rate=1.0)
|
||||
old, _ = make("aging", 0.2)
|
||||
new, _ = make("busy", 1.0)
|
||||
q.push(old, 0.2)
|
||||
q.push(new, 1.0)
|
||||
q.age(dt=10.0)
|
||||
assert q.peek().text == "aging"
|
||||
|
||||
|
||||
def test_items_sorted():
|
||||
q = UrgencyQueue()
|
||||
q.push(make("b", 0.5)[0], 0.5)
|
||||
q.push(make("a", 1.0)[0], 1.0)
|
||||
weights = [weight for weight, _ in q.items()]
|
||||
assert weights == [1.0, 0.5]
|
||||
def test_items_in_arrival_order():
|
||||
q = RequestQueue()
|
||||
q.push(make("b"))
|
||||
q.push(make("a"))
|
||||
texts = [request.text for request in q.items()]
|
||||
assert texts == ["b", "a"]
|
||||
Reference in new issue
Block a user