today_ai_weather/app/admin/sidekiq_jobs.rb
songtianlun 2a0226eb68 feat: update sidekiq tasks manager for clarity
- Rename task label from 'Batch Generate Weather Arts' to 'Generate Weather Arts' for better understanding.
- Add a new button for manual task execution of 'BatchGenerateWeatherArts'.
- Update task value in form submissions to be more descriptive, enhancing maintainability.

These changes improve the usability of the Sidekiq tasks management interface, making it more intuitive for users to identify and execute tasks. The renamed button and the clear distinction between tasks aim to reduce confusion and assist in better workflow management.
2025-01-28 01:32:56 +08:00

101 lines
3.3 KiB
Ruby

# app/admin/sidekiq_tasks.rb
ActiveAdmin.register_page "Sidekiq Tasks" do
# menu label: "Sidekiq Tasks", priority: 99
menu label: "Sidekiq Tasks Manager", parent: "系统管理"
content title: "Sidekiq Tasks Management" do
div class: "sidekiq-tasks" do
panel "Manual Task Execution" do
div class: "task-buttons" do
div class: "task-button" do
h3 "Generate Weather Arts"
form action: admin_sidekiq_tasks_run_task_path, method: :post do
input type: "hidden", name: "authenticity_token", value: form_authenticity_token
input type: "hidden", name: "task", value: "GenerateWeatherArtsWorker"
select name: "city_id" do
City.all.map do |city|
option city.name, value: city.id
end
end
input type: "submit", value: "Run Task", class: "button"
end
end
div class: "task-button" do
h3 "Batch Generate Weather Arts"
form action: admin_sidekiq_tasks_run_task_path, method: :post do
input type: "hidden", name: "authenticity_token", value: form_authenticity_token
input type: "hidden", name: "task", value: "BatchGenerateWeatherArts"
input type: "submit", value: "Run Task", class: "button"
end
end
div class: "task-button" do
h3 "Refresh Sitemap"
form action: admin_sidekiq_tasks_run_task_path, method: :post do
input type: "hidden", name: "authenticity_token", value: form_authenticity_token
input type: "hidden", name: "task", value: "RefreshSitemapWorker"
input type: "submit", value: "Run Task", class: "button"
end
end
div class: "task-button" do
h3 "Clean Ahoy Data"
form action: admin_sidekiq_tasks_run_task_path, method: :post do
input type: "hidden", name: "authenticity_token", value: form_authenticity_token
input type: "hidden", name: "task", value: "CleanAhoyDataWorker"
input type: "submit", value: "Run Task", class: "button"
end
end
end
end
panel "Sidekiq Statistics" do
stats = Sidekiq::Stats.new
table class: "sidekiq-stats" do
tr do
th "Processed Jobs"
td stats.processed
end
tr do
th "Failed Jobs"
td stats.failed
end
tr do
th "Enqueued Jobs"
td stats.enqueued
end
tr do
th "Scheduled Jobs"
td stats.scheduled_size
end
tr do
th "Retry Set Size"
td stats.retry_size
end
end
end
end
end
page_action :run_task, method: :post do
task_name = params[:task]
city_id = params[:city_id]
case task_name
when "BatchGenerateWeatherArts"
BatchGenerateWeatherArtsWorker.perform_async
when "GenerateWeatherArtsWorker"
GenerateWeatherArtWorker.perform_async(city_id)
when "RefreshSitemapWorker"
RefreshSitemapWorker.perform_async
when "CleanAhoyDataWorker"
CleanAhoyDataWorker.perform_async
end
redirect_to admin_sidekiq_tasks_path, notice: "Task #{task_name} has been queued"
end
end