songtianlun
f0f94de528
- Simplify query for most popular inactive cities in City model - Minor layout changes in Admin Dashboards for Ahoy and Sidekiq tasks This refactoring improves code organization, reducing complexity in the City model and making it easier to read. Additionally, the Admin dashboard layouts have been simplified for a better user experience.
99 lines
3.3 KiB
Ruby
99 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
|