-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
181 additions
and
15 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module CopyTunerClient | ||
class KeyAccessLog | ||
class NullLog | ||
def add(key) | ||
end | ||
|
||
def flush | ||
end | ||
end | ||
|
||
def initialize(client) | ||
@client = client | ||
@entries = {} | ||
@mutex = Mutex.new | ||
end | ||
|
||
def add(key_with_locale) | ||
return if key_with_locale.nil? || key_with_locale.empty? | ||
|
||
key = key_with_locale.split('.', 2)[1] | ||
return if key.nil? || key.empty? | ||
|
||
lock do | ||
@entries[key] = Time.now.to_i | ||
end | ||
end | ||
|
||
def flush | ||
to_be_uploaded = nil | ||
lock do | ||
to_be_uploaded = @entries | ||
@entries = {} | ||
end | ||
|
||
return if to_be_uploaded.empty? | ||
|
||
client.upload_key_acess_log(to_be_uploaded) | ||
end | ||
|
||
private | ||
|
||
attr_reader :client | ||
|
||
def lock(&block) | ||
@mutex.synchronize &block | ||
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
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
Oops, something went wrong.