Skip to content

Commit

Permalink
Fix the way we call async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
etagwerker committed Sep 11, 2024
1 parent 3807c68 commit c8cc6c4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/github_notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create
branch: data.dig("check_run", "check_suite", "head_branch")
)

GithubNotifications::Process.perform_async github_notification
GithubNotifications::Process.perform_async github_notification.id

head :ok
end
Expand Down
12 changes: 11 additions & 1 deletion app/models/compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ class Compat < ApplicationRecord
has_many :github_notifications

validates :status, presence: true, inclusion: { in: %w(pending), if: :unchecked?, message: "must be pending if unchecked" }
validates :dependencies, uniqueness: { scope: :rails_release }

validate :unique_dependencies_for_rails_release

def unique_dependencies_for_rails_release
if Compat.where(rails_release: rails_release)
.where("dependencies::jsonb = ?", dependencies.to_json)
.exists?
errors.add(:dependencies, "must be unique for the given Rails release")
end
end

validates :status_determined_by, presence: { unless: :pending? },
absence: { if: :pending? }

Expand Down
2 changes: 1 addition & 1 deletion app/services/check_git_branches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def call
External::Github.delete_branch(compat.id)

if RailsRelease.latest_major.include?(compat.rails_release)
Compats::Check.perform_async compat
Compats::Check.perform_async compat.id
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/gemmies/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def call(name)

gemmy = Gemmy.create!(name: name)

Process.perform_async gemmy
Process.perform_async gemmy.id

gemmy
end
Expand Down
3 changes: 2 additions & 1 deletion app/services/gemmies/process.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Gemmies
class Process < Baseline::Service
def call(gemmy)
def call(gemmy_id)
gemmy = Gemmy.find(gemmy_id)
UpdateDependenciesAndVersions.call(gemmy)
UpdateCompats.call(gemmy)

Expand Down
3 changes: 2 additions & 1 deletion app/services/github_notifications/process.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module GithubNotifications
class Process < Baseline::Service
def call(github_notification)
def call(github_notification_id)
github_notification = GithubNotification.find(github_notification_id)
if github_notification.processed?
raise Error, "GitHub Notification #{github_notification.id} has already been processed."
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/rails_releases/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def call(version)

rails_release = RailsRelease.create!(version: major_minor_version)

Process.perform_async rails_release
Process.perform_async rails_release.id

rails_release
end
Expand Down

0 comments on commit c8cc6c4

Please sign in to comment.