8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/fosm/admin/apps_controller.rb', line 8
def show
@slug = params[:slug]
@model_class = Fosm::Registry.find(@slug)
return render plain: "FOSM app '#{@slug}' not found", status: :not_found unless @model_class
@lifecycle = @model_class.fosm_lifecycle
@diagram_data = @lifecycle.to_diagram_data
@state_counts = @lifecycle.state_names.index_with { |s| @model_class.where(state: s).count }
@recent_transitions = Fosm::TransitionLog.for_app(@model_class).recent.limit(20)
@total = @model_class.count
non_terminal_states = @lifecycle.states.reject(&:terminal?).map { |s| s.name.to_s }
pk_type = @model_class.columns_hash[@model_class.primary_key]&.sql_type_metadata&.type
stuck_ids = Fosm::TransitionLog.for_app(@model_class)
.where("created_at < ?", 7.days.ago)
.distinct
.pluck(:record_id)
stuck_ids = stuck_ids.map(&:to_i) if pk_type == :integer
@stuck_count = @model_class.where(state: non_terminal_states).where.not(id: stuck_ids).count
end
|