refactor: rename workers to jobs

- Change class names from Worker to Job for better alignment
  with Rails convention.
- Includes changes in BatchGenerateWeatherArtsJob,
  CleanAhoyDataJob, GenerateWeatherArtJob, and
  RefreshSitemapJob classes.

This refactoring improves the clarity and consistency of the
codebase by adhering to established naming conventions,
making it easier for new developers to understand the
role of these classes within the application.
This commit is contained in:
songtianlun 2025-01-28 01:16:17 +08:00
parent ce5d09b621
commit bf2ff282bb
4 changed files with 13 additions and 14 deletions

View File

@ -1,5 +1,6 @@
class BatchGenerateWeatherArtsWorker
include Sidekiq::Worker
# app/jobs/batch_generate_weather_arts_job.rb
class BatchGenerateWeatherArtsJob < ApplicationJob
queue_as :default
GENERATION_INTERVAL = 24.hours
MAX_DURATION = 50.minutes
@ -14,7 +15,7 @@ class BatchGenerateWeatherArtsWorker
break if Time.current - start_time > MAX_DURATION
Rails.logger.info "Generating weather art for #{city.name}"
GenerateWeatherArtWorker.perform_async(city.id)
GenerateWeatherArtJob.perform_later(city.id)
sleep SLEEP_DURATION
end
end

View File

@ -1,8 +1,6 @@
# app/workers/clean_ahoy_data_worker.rb
class CleanAhoyDataWorker
include Sidekiq::Worker
sidekiq_options queue: :default, retry: false
# app/jobs/clean_ahoy_data_job.rb
class CleanAhoyDataJob < ApplicationJob
queue_as :default
def perform
cleanup_old_events

View File

@ -1,5 +1,5 @@
class GenerateWeatherArtWorker
include Sidekiq::Worker
class GenerateWeatherArtJob < ApplicationJob
queue_as :default
def perform(city_id)
@city = City.find(city_id)

View File

@ -1,5 +1,5 @@
class RefreshSitemapWorker
include Sidekiq::Worker
class RefreshSitemapJob < ApplicationJob
queue_as :default
def perform
host = Rails.env.production? ? "https://todayaiweather.com" : "http://127.0.0.1:3000"