docbrown/app/workers/podcasts/get_episodes_worker.rb
Anna Buianova f05e5254bb
Fetch podcast's episodes from /internal (#6593) [deploy]
* Formalized and improved Podcasts::GetEpisodesWorker documentation

* Basic functionality for fetching podcasts episodes from /internal

* Improved notice on fetching

* Reorganized /internal/podcasts edit page
2020-03-11 17:25:12 -04:00

27 lines
1.1 KiB
Ruby

module Podcasts
class GetEpisodesWorker
include Sidekiq::Worker
sidekiq_options queue: :high_priority, retry: 10
# @param podcast_data [Hash]
# * :podcast_id [Integer]
# * :limit [Integer] (1_000) - number of episodes that will be fetched for this podcast
# * :force_update [Integer] (false) - if set to true, existing episodes' urls will be re-checked
# the episodes' `https` and `reachable` fields will be updated accordingly if needed
def perform(podcast_data = {})
# Sidekiq turns arguments into Strings so the Ruby keyword argument sorcery doesn't work here
# prevent any mismatch between String keys and Symbol keys
podcast_data.symbolize_keys!
podcast_id = podcast_data[:podcast_id]
limit = podcast_data[:limit] || 1_000
force_update = podcast_data[:force_update] || false
podcast = Podcast.find_by(id: podcast_id)
return unless podcast
Podcasts::Feed.new(podcast).get_episodes(limit: limit, force_update: force_update)
end
end
end