2025-01-28 01:24:49 +08:00
|
|
|
# app/admin/sidekiq_tasks.rb
|
|
|
|
ActiveAdmin.register_page "Sidekiq Tasks" do
|
2025-01-28 01:32:56 +08:00
|
|
|
# menu label: "Sidekiq Tasks", priority: 99
|
|
|
|
menu label: "Sidekiq Tasks Manager", parent: "系统管理"
|
2025-01-28 01:03:06 +08:00
|
|
|
|
2025-01-28 01:24:49 +08:00
|
|
|
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
|
2025-01-28 01:32:56 +08:00
|
|
|
h3 "Generate Weather Arts"
|
2025-01-28 01:24:49 +08:00
|
|
|
form action: admin_sidekiq_tasks_run_task_path, method: :post do
|
|
|
|
input type: "hidden", name: "authenticity_token", value: form_authenticity_token
|
2025-01-28 01:32:56 +08:00
|
|
|
input type: "hidden", name: "task", value: "GenerateWeatherArtsWorker"
|
2025-01-28 01:24:49 +08:00
|
|
|
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"
|
2025-01-28 01:03:06 +08:00
|
|
|
end
|
2025-01-28 01:24:49 +08:00
|
|
|
end
|
|
|
|
|
2025-01-28 01:32:56 +08:00
|
|
|
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
|
|
|
|
|
2025-01-28 01:24:49 +08:00
|
|
|
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"
|
2025-01-28 01:03:06 +08:00
|
|
|
end
|
2025-01-28 01:24:49 +08:00
|
|
|
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"
|
2025-01-28 01:03:06 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-01-28 01:24:49 +08:00
|
|
|
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
|
2025-01-28 01:03:06 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-01-28 01:24:49 +08:00
|
|
|
page_action :run_task, method: :post do
|
|
|
|
task_name = params[:task]
|
|
|
|
city_id = params[:city_id]
|
2025-01-28 01:03:06 +08:00
|
|
|
|
2025-01-28 01:24:49 +08:00
|
|
|
case task_name
|
2025-01-28 01:32:56 +08:00
|
|
|
when "BatchGenerateWeatherArts"
|
|
|
|
BatchGenerateWeatherArtsWorker.perform_async
|
|
|
|
when "GenerateWeatherArtsWorker"
|
2025-01-28 01:24:49 +08:00
|
|
|
GenerateWeatherArtWorker.perform_async(city_id)
|
|
|
|
when "RefreshSitemapWorker"
|
|
|
|
RefreshSitemapWorker.perform_async
|
|
|
|
when "CleanAhoyDataWorker"
|
|
|
|
CleanAhoyDataWorker.perform_async
|
2025-01-28 01:03:06 +08:00
|
|
|
end
|
|
|
|
|
2025-01-28 01:24:49 +08:00
|
|
|
redirect_to admin_sidekiq_tasks_path, notice: "Task #{task_name} has been queued"
|
2025-01-28 01:03:06 +08:00
|
|
|
end
|
|
|
|
end
|