-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor pipeline and episode status for use in multiple integrations
- Loading branch information
Showing
25 changed files
with
313 additions
and
203 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
class Feeds::MegaphoneFeed < Feed | ||
has_one :megaphone_config, class_name: "::Megaphone::Config", inverse_of: :feed | ||
|
||
alias_method :config, :megaphone_config | ||
|
||
def self.model_name | ||
Feed.model_name | ||
end | ||
|
||
def integration_type | ||
:megaphone | ||
end | ||
|
||
def publish_integration? | ||
megaphone_config&.publish_to_megaphone? | ||
end | ||
|
||
def publish_integration! | ||
if publish_integration? | ||
megaphone_config.build_publisher.publish! | ||
end | ||
end | ||
|
||
def mark_as_not_delivered!(episode) | ||
episode.episode_delivery_statuses.megaphone.first&.mark_as_not_delivered! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Integrations | ||
def self.table_name_prefix | ||
"integrations_" | ||
end | ||
|
||
INTEGRATIONS = %i[apple megaphone] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Integrations | ||
class EpisodeDeliveryStatus < ApplicationRecord | ||
belongs_to :episode, -> { with_deleted }, class_name: "::Episode" | ||
|
||
enum :integration, Integrations::INTEGRATIONS | ||
|
||
def self.update_status(integration, episode, attrs) | ||
new_status = (episode.episode_delivery_status(integration)&.dup || default_status(integration, episode)) | ||
attrs[:integration] = integration | ||
new_status.assign_attributes(attrs) | ||
new_status.save! | ||
episode.episode_delivery_statuses.reset | ||
new_status | ||
end | ||
|
||
def self.default_status(integration, episode) | ||
new(episode: episode, integration: integration) | ||
end | ||
|
||
def increment_asset_wait | ||
self.class.update_status(integration, episode, asset_processing_attempts: (asset_processing_attempts || 0) + 1) | ||
end | ||
|
||
def reset_asset_wait | ||
self.class.update_status(integration, episode, asset_processing_attempts: 0) | ||
end | ||
|
||
def mark_as_uploaded! | ||
self.class.update_status(integration, episode, uploaded: true) | ||
end | ||
|
||
def mark_as_not_uploaded! | ||
self.class.update_status(integration, episode, uploaded: false) | ||
end | ||
|
||
# Whether the media file has been uploaded to the Integration | ||
# is a subset of whether the episode has been delivered | ||
def mark_as_delivered! | ||
self.class.update_status(integration, episode, delivered: true, uploaded: true) | ||
end | ||
|
||
def mark_as_not_delivered! | ||
self.class.update_status(integration, episode, delivered: false, uploaded: false) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "active_support/concern" | ||
|
||
module Integrations::EpisodeIntegrations | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_many :episode_delivery_statuses, -> { order(created_at: :desc) }, class_name: "Integrations::EpisodeDeliveryStatus" | ||
end | ||
|
||
def episode_delivery_status(integration) | ||
episode_delivery_statuses.order(created_at: :desc).send(integration.intern).first | ||
end | ||
|
||
def update_episode_delivery_status(integration, attrs) | ||
Integrations::EpisodeDeliveryStatus.update_status(integration, self, attrs) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Megaphone | ||
class Publisher < Integrations::Base::Publisher | ||
def publish! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.