Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# Git worktrees for parallel development
.worktrees/

# Claude Code personal workflows (local only)
.claude/
CLAUDE.md
5 changes: 3 additions & 2 deletions app/controllers/solid_queue_monitor/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def paginate(relation)
PaginationService.new(relation, current_page, per_page).paginate
end

def render_page(title, content)
def render_page(title, content, search_query: nil)
# Get flash message from instance variable (set by set_flash_message) or session
message = @flash_message
message_type = @flash_type
Expand All @@ -27,7 +27,8 @@ def render_page(title, content)
title: title,
content: content,
message: message,
message_type: message_type
message_type: message_type,
search_query: search_query
).generate

render html: html.html_safe
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/solid_queue_monitor/search_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module SolidQueueMonitor
class SearchController < BaseController
def index
query = params[:q]
results = SearchService.new(query).search

render_page('Search', SearchResultsPresenter.new(query, results).render, search_query: query)
end
end
end
190 changes: 190 additions & 0 deletions app/presenters/solid_queue_monitor/search_results_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# frozen_string_literal: true

module SolidQueueMonitor
class SearchResultsPresenter < BasePresenter
def initialize(query, results)
@query = query
@results = results
end

def render
section_wrapper('Search Results', generate_content)
end

private

def generate_content
if @query.blank?
generate_empty_query_message
elsif total_count.zero?
generate_no_results_message
else
generate_results_summary + generate_all_sections
end
end

def generate_empty_query_message
<<-HTML
<div class="empty-state">
<p>Enter a search term in the header to find jobs across all categories.</p>
</div>
HTML
end

def generate_no_results_message
<<-HTML
<div class="empty-state">
<p>No results found for "#{escape_html(@query)}"</p>
<p class="results-summary">0 results</p>
</div>
HTML
end

def generate_results_summary
<<-HTML
<div class="results-summary">
<p>Found #{total_count} #{total_count == 1 ? 'result' : 'results'} for "#{escape_html(@query)}"</p>
</div>
HTML
end

def generate_all_sections
sections = []
sections << generate_ready_section if @results[:ready].any?
sections << generate_scheduled_section if @results[:scheduled].any?
sections << generate_failed_section if @results[:failed].any?
sections << generate_in_progress_section if @results[:in_progress].any?
sections << generate_completed_section if @results[:completed].any?
sections << generate_recurring_section if @results[:recurring].any?
sections.join
end

def generate_ready_section
generate_section('Ready Jobs', @results[:ready]) do |execution|
generate_job_row(execution.job, execution.queue_name, execution.created_at)
end
end

def generate_scheduled_section
generate_section('Scheduled Jobs', @results[:scheduled]) do |execution|
generate_job_row(execution.job, execution.queue_name, execution.scheduled_at, 'Scheduled for')
end
end

def generate_failed_section
generate_section('Failed Jobs', @results[:failed]) do |execution|
generate_failed_row(execution)
end
end

def generate_in_progress_section
generate_section('In Progress Jobs', @results[:in_progress]) do |execution|
generate_job_row(execution.job, execution.job.queue_name, execution.created_at, 'Started at')
end
end

def generate_completed_section
generate_section('Completed Jobs', @results[:completed]) do |job|
generate_completed_row(job)
end
end

def generate_recurring_section
generate_section('Recurring Tasks', @results[:recurring]) do |task|
generate_recurring_row(task)
end
end

def generate_section(title, items, &block)
<<-HTML
<div class="search-results-section">
<h3>#{title} (#{items.size})</h3>
<div class="table-container">
<table>
<thead>
<tr>
#{section_headers(title)}
</tr>
</thead>
<tbody>
#{items.map(&block).join}
</tbody>
</table>
</div>
</div>
HTML
end

def section_headers(title)
case title
when 'Recurring Tasks'
'<th>Key</th><th>Class</th><th>Schedule</th><th>Queue</th>'
when 'Failed Jobs'
'<th>Job</th><th>Queue</th><th>Error</th><th>Failed At</th>'
when 'Completed Jobs'
'<th>Job</th><th>Queue</th><th>Arguments</th><th>Completed At</th>'
else
'<th>Job</th><th>Queue</th><th>Arguments</th><th>Time</th>'
end
end

def generate_job_row(job, queue_name, time, time_label = 'Created at')
<<-HTML
<tr>
<td><a href="#{job_path(job)}" class="job-class-link">#{job.class_name}</a></td>
<td>#{queue_link(queue_name)}</td>
<td>#{format_arguments(job.arguments)}</td>
<td>
<span class="job-timestamp">#{time_label}: #{format_datetime(time)}</span>
</td>
</tr>
HTML
end

def generate_failed_row(execution)
job = execution.job
<<-HTML
<tr>
<td><a href="#{job_path(job)}" class="job-class-link">#{job.class_name}</a></td>
<td>#{queue_link(job.queue_name)}</td>
<td><div class="error-message">#{escape_html(execution.error.to_s.truncate(100))}</div></td>
<td>
<span class="job-timestamp">#{format_datetime(execution.created_at)}</span>
</td>
</tr>
HTML
end

def generate_completed_row(job)
<<-HTML
<tr>
<td><a href="#{job_path(job)}" class="job-class-link">#{job.class_name}</a></td>
<td>#{queue_link(job.queue_name)}</td>
<td>#{format_arguments(job.arguments)}</td>
<td>
<span class="job-timestamp">#{format_datetime(job.finished_at)}</span>
</td>
</tr>
HTML
end

def generate_recurring_row(task)
<<-HTML
<tr>
<td><strong>#{task.key}</strong></td>
<td>#{task.class_name || '-'}</td>
<td><code>#{task.schedule}</code></td>
<td>#{queue_link(task.queue_name)}</td>
</tr>
HTML
end

def total_count
@total_count ||= @results.values.sum(&:size)
end

def escape_html(text)
text.to_s.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;').gsub('"', '&quot;')
end
end
end
25 changes: 23 additions & 2 deletions app/services/solid_queue_monitor/html_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class HtmlGenerator
include Rails.application.routes.url_helpers
include SolidQueueMonitor::Engine.routes.url_helpers

def initialize(title:, content:, message: nil, message_type: nil)
def initialize(title:, content:, message: nil, message_type: nil, search_query: nil)
@title = title
@content = content
@message = message
@message_type = message_type
@search_query = search_query
end

def generate
Expand Down Expand Up @@ -107,7 +108,8 @@ def generate_header
<<-HTML
<header>
<div class="header-top">
<h1>Solid Queue Monitor</h1>
<h1><a href="#{root_path}" class="header-title-link">Solid Queue Monitor</a></h1>
#{generate_search_box}
<div class="header-controls">
#{generate_auto_refresh_controls}
#{generate_theme_toggle}
Expand All @@ -128,6 +130,25 @@ def generate_footer
HTML
end

def generate_search_box
search_value = @search_query ? escape_html(@search_query) : ''
<<-HTML
<form method="get" action="#{search_path}" class="header-search-form">
<input type="text" name="q" value="#{search_value}" placeholder="Search by class, queue, job ID, or error..." class="header-search-input">
<button type="submit" class="header-search-button" title="Search">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
</form>
HTML
end

def escape_html(text)
text.to_s.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;').gsub('"', '&quot;')
end

def generate_auto_refresh_controls
return '' unless SolidQueueMonitor.auto_refresh_enabled

Expand Down
Loading