Skip to content

Commit

Permalink
Add a makara flag to enable usage with makara to hit the primary
Browse files Browse the repository at this point in the history
  • Loading branch information
anoldguy committed May 10, 2022
1 parent d673384 commit 57f4be5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/easymon/checks/active_record_mysql_writeable_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module Easymon
class ActiveRecordMysqlWriteableCheck
attr_accessor :klass

def initialize(klass)
def initialize(klass, makara = false)
self.klass = klass
@query = "SELECT @@read_only"
# Trick makara into using the primary db
@query += " for UPDATE" if makara
end

def check
Expand All @@ -18,7 +21,7 @@ def check

private
def database_writeable?
klass.connection.execute("SELECT @@read_only").entries.flatten.first == 0
klass.connection.execute(@query).entries.flatten.first == 0
rescue
false
end
Expand Down

0 comments on commit 57f4be5

Please sign in to comment.