Class: Aidp::Watch::WorkItem

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/aidp/watch/work_item.rb

Overview

Value object representing a work item in the round-robin queue. Encapsulates issue/PR data with metadata needed for scheduling.

Constant Summary collapse

ITEM_TYPES =
%i[issue pr].freeze
PROCESSOR_TYPES =
%i[plan build auto_issue review ci_fix auto_pr change_request].freeze
PRIORITY_PLAN =

Priority levels for scheduling (lower = higher priority)

1
PRIORITY_NORMAL =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, item_type:, processor_type:, label:, data:, priority: nil) ⇒ WorkItem

Returns a new instance of WorkItem.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aidp/watch/work_item.rb', line 19

def initialize(number:, item_type:, processor_type:, label:, data:, priority: nil)
  validate_item_type!(item_type)
  validate_processor_type!(processor_type)

  @number = number
  @item_type = item_type
  @processor_type = processor_type
  @label = label
  @data = data
  @priority = priority || default_priority
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/aidp/watch/work_item.rb', line 17

def data
  @data
end

#item_typeObject (readonly)

Returns the value of attribute item_type.



17
18
19
# File 'lib/aidp/watch/work_item.rb', line 17

def item_type
  @item_type
end

#labelObject (readonly)

Returns the value of attribute label.



17
18
19
# File 'lib/aidp/watch/work_item.rb', line 17

def label
  @label
end

#numberObject (readonly)

Returns the value of attribute number.



17
18
19
# File 'lib/aidp/watch/work_item.rb', line 17

def number
  @number
end

#priorityObject (readonly)

Returns the value of attribute priority.



17
18
19
# File 'lib/aidp/watch/work_item.rb', line 17

def priority
  @priority
end

#processor_typeObject (readonly)

Returns the value of attribute processor_type.



17
18
19
# File 'lib/aidp/watch/work_item.rb', line 17

def processor_type
  @processor_type
end

Instance Method Details

#<=>(other) ⇒ Object

Comparison for sorting by priority



73
74
75
# File 'lib/aidp/watch/work_item.rb', line 73

def <=>(other)
  priority <=> other.priority
end

#issue?Boolean

Check if item is an issue (vs PR)

Returns:

  • (Boolean)


46
47
48
# File 'lib/aidp/watch/work_item.rb', line 46

def issue?
  item_type == :issue
end

#keyString

Unique key for this work item (used for queue tracking)

Returns:

  • (String)

    Unique identifier



33
34
35
# File 'lib/aidp/watch/work_item.rb', line 33

def key
  "#{item_type}_#{number}_#{processor_type}"
end

#plan?Boolean

Check if this is a high-priority plan item

Returns:

  • (Boolean)


58
59
60
# File 'lib/aidp/watch/work_item.rb', line 58

def plan?
  processor_type == :plan
end

#pr?Boolean

Check if item is a PR

Returns:

  • (Boolean)


52
53
54
# File 'lib/aidp/watch/work_item.rb', line 52

def pr?
  item_type == :pr
end

#same_entity?(other) ⇒ Boolean

Check if this work item is for the same issue/PR

Parameters:

  • other (WorkItem)

    Other work item to compare

Returns:

  • (Boolean)

    True if same entity



40
41
42
# File 'lib/aidp/watch/work_item.rb', line 40

def same_entity?(other)
  item_type == other.item_type && number == other.number
end

#to_hObject



62
63
64
65
66
67
68
69
70
# File 'lib/aidp/watch/work_item.rb', line 62

def to_h
  {
    number: number,
    item_type: item_type,
    processor_type: processor_type,
    label: label,
    priority: priority
  }
end