Module: Delayer
- Defined in:
- lib/delayer.rb,
lib/delayer/error.rb,
lib/delayer/extend.rb,
lib/delayer/version.rb,
lib/delayer/procedure.rb
Defined Under Namespace
Modules: Extend Classes: AlreadyCanceledError, AlreadyExecutedError, AlreadyRunningError, Bucket, Error, InvalidPriorityError, NoLowerLevelError, Procedure, RecursiveError, RemainJobsError, TooLate
Constant Summary collapse
- VERSION =
'1.0.1'
Class Attribute Summary collapse
-
.default ⇒ Object
Returns the value of attribute default.
Instance Attribute Summary collapse
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Class Method Summary collapse
-
.generate_class(options = {}) ⇒ Object
Generate new Delayer class.
- .included(klass) ⇒ Object
- .method_missing(*args, &proc) ⇒ Object
- .StateError(state) ⇒ Object
Instance Method Summary collapse
-
#cancel ⇒ Object
- Cancel this job ==== Exception Delayer::AlreadyExecutedError
-
if already called run() ==== Return self.
- #initialize(priority = self.class.instance_eval { @default_priority }, *_args, &proc) ⇒ Object
Class Attribute Details
.default ⇒ Object
Returns the value of attribute default.
10 11 12 |
# File 'lib/delayer.rb', line 10 def default @default end |
Instance Attribute Details
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
4 5 6 |
# File 'lib/delayer/extend.rb', line 4 def priority @priority end |
Class Method Details
.generate_class(options = {}) ⇒ Object
Generate new Delayer class.
Args
- options
-
Hash
- expire
-
processing expire (secs, 0=unlimited)
- priority
-
priorities
- default
-
default priotity
Return
A new class
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/delayer.rb', line 21 def generate_class( = {}) Class.new do include ::Delayer @expire = [:expire] || 0 if .has_key?(:priority) @priorities = [:priority] @default_priority = [:default] else @priorities = [:normal] @default_priority = :normal end end end |
.included(klass) ⇒ Object
16 17 18 19 20 |
# File 'lib/delayer/extend.rb', line 16 def self.included(klass) klass.class_eval do extend Extend end end |
.method_missing(*args, &proc) ⇒ Object
35 36 37 |
# File 'lib/delayer.rb', line 35 def method_missing(*args, &proc) (@default ||= generate_class).__send__(*args, &proc) end |
.StateError(state) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/delayer/error.rb', line 15 def self.StateError(state) case state when :run AlreadyRunningError when :done AlreadyExecutedError when :cancel AlreadyCanceledError end end |
Instance Method Details
#cancel ⇒ Object
Cancel this job
Exception
- Delayer::AlreadyExecutedError
-
if already called run()
Return
self
33 34 35 36 |
# File 'lib/delayer/extend.rb', line 33 def cancel @procedure.cancel self end |
#initialize(priority = self.class.instance_eval { @default_priority }, *_args, &proc) ⇒ Object
22 23 24 25 26 |
# File 'lib/delayer/extend.rb', line 22 def initialize(priority = self.class.instance_eval { @default_priority }, *_args, &proc) self.class.validate_priority priority @priority = priority @procedure = Procedure.new(self, &proc) end |