Skip to content

Commit

Permalink
make the retryt method generic for all submission state machines
Browse files Browse the repository at this point in the history
  • Loading branch information
nid90 committed Jan 14, 2025
1 parent c0dc352 commit e33bdc2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/models/app_store_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class AppStoreSubmission < StoreSubmission

after_create_commit :poll_external_status

def retryable? = failed?

def pre_review? = PRE_PREPARE_STATES.include?(status)

def change_build? = CHANGEABLE_STATES.include?(status) && editable?
Expand Down
2 changes: 2 additions & 0 deletions app/models/google_firebase_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class GoogleFirebaseSubmission < StoreSubmission
end
end

def retryable? = failed?

def trigger!
return unless actionable?
return unless may_prepare?
Expand Down
12 changes: 1 addition & 11 deletions app/models/play_store_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,8 @@ def trigger!
end

def retry!
return unless retryable?
return check_manual_upload if failed_with_action_required?
raise "Not retryable" if last_stable_status.blank?

case last_stable_status.to_sym
when :preprocessing
trigger!
when :preparing
start_prepare!
else
raise "Not retryable"
end
super
end

def upload_build!
Expand Down
17 changes: 16 additions & 1 deletion app/models/store_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StoreSubmission < ApplicationRecord
belongs_to :release_platform_run
belongs_to :parent_release, polymorphic: true
# rubocop:disable Rails/InverseOf
belongs_to :production_release, -> { where(store_submissions: {parent_release_type: "ProductionRelease"}) }, foreign_key: "parent_release_id", optional: true
belongs_to :production_release, -> { where(store_submissions: { parent_release_type: "ProductionRelease" }) }, foreign_key: "parent_release_id", optional: true

Check failure on line 40 in app/models/store_submission.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 40 in app/models/store_submission.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.
# rubocop:enable Rails/InverseOf
belongs_to :build

Expand Down Expand Up @@ -159,6 +159,21 @@ def last_failed_event
passports.where(reason: "failed").last
end

def retry!
return unless retryable?
target_state = last_stable_status&.to_sym
raise "Not retryable" if target_state.blank?

permitted_transitions = aasm.permitted_transitions
permitted_event = permitted_transitions.find { |t| t[:state] == target_state }&.dig(:event)

if permitted_event
public_send :"#{permitted_event}!"
else
raise "No retries available from the failed state - #{target_state}"
end
end

protected

def reset_store_info!
Expand Down
2 changes: 2 additions & 0 deletions app/models/test_flight_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class TestFlightSubmission < StoreSubmission
end
end

def retryable? = failed?

def internal_channel?
submission_channel.internal?
end
Expand Down

0 comments on commit e33bdc2

Please sign in to comment.