mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: s/\$redis/Discourse\.redis (#8431)
This commit also adds a rubocop rule to prevent global variables.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
module Jobs
|
||||
class CleanUpSidekiqStatistic < ::Jobs::Onceoff
|
||||
def execute_onceoff(args)
|
||||
$redis.without_namespace.del('sidekiq:sidekiq:statistic')
|
||||
Discourse.redis.without_namespace.del('sidekiq:sidekiq:statistic')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ class Jobs::Onceoff < ::Jobs::Base
|
||||
# Pass `force: true` to force it happen again
|
||||
def execute(args)
|
||||
job_name = self.class.name_for(self.class)
|
||||
has_lock = $redis.setnx(running_key_name, Time.now.to_i)
|
||||
has_lock = Discourse.redis.setnx(running_key_name, Time.now.to_i)
|
||||
|
||||
# If we can't get a lock, just noop
|
||||
if args[:force] || has_lock
|
||||
@@ -25,7 +25,7 @@ class Jobs::Onceoff < ::Jobs::Base
|
||||
execute_onceoff(args)
|
||||
OnceoffLog.create!(job_name: job_name)
|
||||
ensure
|
||||
$redis.del(running_key_name) if has_lock
|
||||
Discourse.redis.del(running_key_name) if has_lock
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ module Jobs
|
||||
end
|
||||
|
||||
def execute(args)
|
||||
$redis.set(self.class.heartbeat_key, Time.new.to_i.to_s)
|
||||
Discourse.redis.set(self.class.heartbeat_key, Time.new.to_i.to_s)
|
||||
end
|
||||
|
||||
def self.last_heartbeat
|
||||
$redis.get(heartbeat_key).to_i
|
||||
Discourse.redis.get(heartbeat_key).to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -96,16 +96,16 @@ module Jobs
|
||||
end
|
||||
|
||||
def last_cleanup=(v)
|
||||
$redis.setex(last_cleanup_key, 7.days.to_i, v.to_s)
|
||||
Discourse.redis.setex(last_cleanup_key, 7.days.to_i, v.to_s)
|
||||
end
|
||||
|
||||
def last_cleanup
|
||||
v = $redis.get(last_cleanup_key)
|
||||
v = Discourse.redis.get(last_cleanup_key)
|
||||
v ? v.to_i : v
|
||||
end
|
||||
|
||||
def reset_last_cleanup!
|
||||
$redis.del(last_cleanup_key)
|
||||
Discourse.redis.del(last_cleanup_key)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -33,11 +33,11 @@ module Jobs
|
||||
end
|
||||
|
||||
def last_notified_id
|
||||
(i = $redis.get(self.class.last_notified_key)) && i.to_i
|
||||
(i = Discourse.redis.get(self.class.last_notified_key)) && i.to_i
|
||||
end
|
||||
|
||||
def last_notified_id=(arg)
|
||||
$redis.set(self.class.last_notified_key, arg)
|
||||
Discourse.redis.set(self.class.last_notified_key, arg)
|
||||
end
|
||||
|
||||
def self.last_notified_key
|
||||
|
||||
@@ -37,11 +37,11 @@ module Jobs
|
||||
end
|
||||
|
||||
def self.last_notified_id
|
||||
$redis.get(last_notified_key).to_i
|
||||
Discourse.redis.get(last_notified_key).to_i
|
||||
end
|
||||
|
||||
def self.last_notified_id=(arg)
|
||||
$redis.set(last_notified_key, arg)
|
||||
Discourse.redis.set(last_notified_key, arg)
|
||||
end
|
||||
|
||||
def self.last_notified_key
|
||||
@@ -49,7 +49,7 @@ module Jobs
|
||||
end
|
||||
|
||||
def self.clear_key
|
||||
$redis.del(last_notified_key)
|
||||
Discourse.redis.del(last_notified_key)
|
||||
end
|
||||
|
||||
def active_moderator_usernames
|
||||
|
||||
@@ -50,11 +50,11 @@ module Jobs
|
||||
end
|
||||
|
||||
def previous_newest_username
|
||||
$redis.get previous_newest_username_cache_key
|
||||
Discourse.redis.get previous_newest_username_cache_key
|
||||
end
|
||||
|
||||
def previous_newest_username=(username)
|
||||
$redis.setex previous_newest_username_cache_key, 7.days, username
|
||||
Discourse.redis.setex previous_newest_username_cache_key, 7.days, username
|
||||
end
|
||||
|
||||
def previous_newest_username_cache_key
|
||||
|
||||
@@ -43,15 +43,15 @@ module Jobs
|
||||
end
|
||||
end
|
||||
rescue Net::OpenTimeout => e
|
||||
count = $redis.incr(POLL_MAILBOX_TIMEOUT_ERROR_KEY).to_i
|
||||
count = Discourse.redis.incr(POLL_MAILBOX_TIMEOUT_ERROR_KEY).to_i
|
||||
|
||||
$redis.expire(
|
||||
Discourse.redis.expire(
|
||||
POLL_MAILBOX_TIMEOUT_ERROR_KEY,
|
||||
SiteSetting.pop3_polling_period_mins.minutes * 3
|
||||
) if count == 1
|
||||
|
||||
if count > 3
|
||||
$redis.del(POLL_MAILBOX_TIMEOUT_ERROR_KEY)
|
||||
Discourse.redis.del(POLL_MAILBOX_TIMEOUT_ERROR_KEY)
|
||||
mark_as_errored!
|
||||
add_admin_dashboard_problem_message('dashboard.poll_pop3_timeout')
|
||||
Discourse.handle_job_exception(e, error_context(@args, "Connecting to '#{SiteSetting.pop3_polling_host}' for polling emails."))
|
||||
@@ -65,13 +65,13 @@ module Jobs
|
||||
POLL_MAILBOX_ERRORS_KEY ||= "poll_mailbox_errors".freeze
|
||||
|
||||
def self.errors_in_past_24_hours
|
||||
$redis.zremrangebyscore(POLL_MAILBOX_ERRORS_KEY, 0, 24.hours.ago.to_i)
|
||||
$redis.zcard(POLL_MAILBOX_ERRORS_KEY).to_i
|
||||
Discourse.redis.zremrangebyscore(POLL_MAILBOX_ERRORS_KEY, 0, 24.hours.ago.to_i)
|
||||
Discourse.redis.zcard(POLL_MAILBOX_ERRORS_KEY).to_i
|
||||
end
|
||||
|
||||
def mark_as_errored!
|
||||
now = Time.now.to_i
|
||||
$redis.zadd(POLL_MAILBOX_ERRORS_KEY, now, now.to_s)
|
||||
Discourse.redis.zadd(POLL_MAILBOX_ERRORS_KEY, now, now.to_s)
|
||||
end
|
||||
|
||||
def add_admin_dashboard_problem_message(i18n_key)
|
||||
|
||||
Reference in New Issue
Block a user