allow forcing the creation of an e621 status change
This commit is contained in:
parent
e7518a5c0f
commit
107acfb155
@ -1,15 +1,15 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module E621StatusUpdater
|
module E621StatusUpdater
|
||||||
def self.run
|
def self.run(force: E621Status.count == 0)
|
||||||
return if Rails.env.development?
|
return if Rails.env.development?
|
||||||
status = Requests::E621.status
|
status = Requests::E621.status
|
||||||
previous_status = Cache.redis.get("e621_status:current").to_i
|
previous_status = Cache.redis.get("e621_status:current").to_i
|
||||||
last_change_time = Cache.redis.get("e621_status:last_change_time")
|
last_change_time = Cache.redis.get("e621_status:last_change_time")
|
||||||
last_change_time = Time.parse(last_change_time) if last_change_time.present?
|
last_change_time = Time.parse(last_change_time) if last_change_time.present?
|
||||||
if previous_status == status
|
if previous_status == status && !force
|
||||||
Cache.redis.set("e621_status:last_change_time", (Time.now - 2.seconds).to_s)
|
Cache.redis.set("e621_status:last_change_time", (Time.now - 2.seconds).to_s)
|
||||||
elsif last_change_time.nil? || (Time.now - last_change_time) >= 3.minutes
|
elsif last_change_time.nil? || (Time.now - last_change_time) >= 3.minutes || force
|
||||||
Rails.logger.debug { "Updating status: #{previous_status} -> #{status}" }
|
Rails.logger.debug { "Updating status: #{previous_status} -> #{status}" }
|
||||||
Cache.redis.set("e621_status:current", status.to_s)
|
Cache.redis.set("e621_status:current", status.to_s)
|
||||||
Cache.redis.set("e621_status:last_change_time", (Time.now - 2.seconds).to_s)
|
Cache.redis.set("e621_status:last_change_time", (Time.now - 2.seconds).to_s)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RequestExtension
|
module RequestExtension
|
||||||
def forwarded_host
|
def forwarded_host
|
||||||
headers["X-Forwarded-Host"] || host
|
headers["X-Forwarded-Host"] || host
|
||||||
|
@ -37,7 +37,6 @@ module E621WsRoutes
|
|||||||
get(:browserconfig, constraints: { format: "xml" })
|
get(:browserconfig, constraints: { format: "xml" })
|
||||||
root(action: :index)
|
root(action: :index)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CustomStaticMiddleware
|
class CustomStaticMiddleware
|
||||||
def initialize(app, domain_map)
|
def initialize(app, domain_map)
|
||||||
@app = app
|
@app = app
|
||||||
|
@ -7,7 +7,7 @@ namespace :e621 do
|
|||||||
end
|
end
|
||||||
|
|
||||||
task remove_timeouts: :environment do
|
task remove_timeouts: :environment do
|
||||||
E621Thumbnail.where(status: "timeout", created_at: ..10.minutes.ago).find_each do |entry|
|
E621Thumbnail.where(status: "timeout", created_at: ..5.minutes.ago).find_each do |entry|
|
||||||
puts "Removing timed out generation for post #{entry.post_id} (#{entry.stripped_md5}"
|
puts "Removing timed out generation for post #{entry.post_id} (#{entry.stripped_md5}"
|
||||||
entry.destroy
|
entry.destroy
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user