forked from wallace/resque-lonely_job
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresque-unique_at_runtime.rb
49 lines (38 loc) · 1.22 KB
/
resque-unique_at_runtime.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
require 'resque/unique_at_runtime/version'
# Ruby Std Lib
require 'digest/md5'
# External Gems
require 'colorized_string'
require 'resque'
# This Gem
require 'resque/plugins/unique_at_runtime'
require 'resque/unique_at_runtime/resque_ext/resque'
require 'resque/unique_at_runtime/configuration'
# See lib/resque/plugins/unique_at_runtime.rb for the actual plugin
#
# This is not that ^. Rather, it is an API used by the plugin or as tools by a
# developer. These methods are not intended to be included/extended into
# Resque, Resque::Job, or Resque::Queue.
module Resque
module UniqueAtRuntime
PLUGIN_TAG = (ColorizedString['[R-UAR] '].blue).freeze
def log(message)
configuration.logger&.send(configuration.log_level, message) if configuration.logger
end
def debug(message)
configuration.logger&.debug("#{PLUGIN_TAG}#{message}") if configuration.debug_mode
end
# For per-class config with a block
def configure
yield(@configuration)
end
#### CONFIG ####
class << self
attr_accessor :configuration
end
self.configuration = Configuration.instance # setup defaults
module_function(:log,
:debug)
end
end