remove distributed mutex for emojis (not working)
This commit is contained in:
parent
96c19ed8b6
commit
324a3da723
|
@ -1,8 +1,6 @@
|
||||||
class Emoji
|
class Emoji
|
||||||
include ActiveModel::SerializerSupport
|
include ActiveModel::SerializerSupport
|
||||||
|
|
||||||
EMOJIS_CUSTOM_LOCK ||= "_emojis_custom_lock_".freeze
|
|
||||||
|
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
attr_accessor :name, :url
|
attr_accessor :name, :url
|
||||||
|
|
||||||
|
@ -15,12 +13,9 @@ class Emoji
|
||||||
|
|
||||||
def remove
|
def remove
|
||||||
return if path.blank?
|
return if path.blank?
|
||||||
|
if File.exists?(path)
|
||||||
DistributedMutex.new(EMOJIS_CUSTOM_LOCK).synchronize do
|
File.delete(path) rescue nil
|
||||||
if File.exists?(path)
|
Emoji.clear_cache
|
||||||
File.delete(path) rescue nil
|
|
||||||
Emoji.clear_cache
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,14 +60,11 @@ class Emoji
|
||||||
extension = File.extname(file.original_filename)
|
extension = File.extname(file.original_filename)
|
||||||
path = "#{Emoji.base_directory}/#{name}#{extension}"
|
path = "#{Emoji.base_directory}/#{name}#{extension}"
|
||||||
|
|
||||||
DistributedMutex.new(EMOJIS_CUSTOM_LOCK).synchronize do
|
# store the emoji
|
||||||
# store the emoji
|
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
||||||
FileUtils.mkdir_p(Pathname.new(path).dirname)
|
File.open(path, "wb") { |f| f << file.tempfile.read }
|
||||||
File.open(path, "wb") { |f| f << file.tempfile.read }
|
# clear the cache
|
||||||
# clear the cache
|
Emoji.clear_cache
|
||||||
Emoji.clear_cache
|
|
||||||
end
|
|
||||||
|
|
||||||
# launch resize job
|
# launch resize job
|
||||||
Jobs.enqueue(:resize_emoji, path: path)
|
Jobs.enqueue(:resize_emoji, path: path)
|
||||||
# return created emoji
|
# return created emoji
|
||||||
|
|
Loading…
Reference in New Issue