Class: Rage::Deferred::Context
- Inherits:
-
Object
- Object
- Rage::Deferred::Context
- Defined in:
- lib/rage/deferred/context.rb
Overview
Context for deferred tasks. The class encapsulates the context associated with a deferred task, and allows to store it without modifying the task instance.
Class Method Summary collapse
- .build(task, args, kwargs) ⇒ Object
-
.get_args(context) ⇒ Array?
Arguments the task was enqueued with.
-
.get_attempts(context) ⇒ Integer?
Number of attempts made to process the task.
-
.get_kwargs(context) ⇒ Hash?
Keyword arguments the task was enqueued with.
-
.get_log_context(context) ⇒ Hash?
Log context associated with the task.
-
.get_log_tags(context) ⇒ Array?
Log tags associated with the task.
-
.get_or_create_args(context) ⇒ Array
Arguments the task was enqueued with, creating it if it does not exist.
-
.get_or_create_kwargs(context) ⇒ Hash
Keyword arguments the task was enqueued with, creating it if it does not exist.
-
.get_or_create_user_context(context) ⇒ Hash
User context associated with the task, creating it if it does not exist.
-
.get_task(context) ⇒ Class
The task class.
-
.get_user_context(context) ⇒ Hash?
User context associated with the task.
-
.inc_attempts(context) ⇒ Object
Increments the number of attempts made to process the task.
Class Method Details
.build(task, args, kwargs) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rage/deferred/context.rb', line 8 def self.build(task, args, kwargs) logger = Thread.current[:rage_logger] [ task, args.empty? ? nil : args, kwargs.empty? ? nil : kwargs, nil, logger&.dig(:tags), logger&.dig(:context), nil ] end |
.get_args(context) ⇒ Array?
Returns arguments the task was enqueued with.
28 29 30 |
# File 'lib/rage/deferred/context.rb', line 28 def self.get_args(context) context[1] end |
.get_attempts(context) ⇒ Integer?
Returns number of attempts made to process the task.
48 49 50 |
# File 'lib/rage/deferred/context.rb', line 48 def self.get_attempts(context) context[3] end |
.get_kwargs(context) ⇒ Hash?
Returns keyword arguments the task was enqueued with.
38 39 40 |
# File 'lib/rage/deferred/context.rb', line 38 def self.get_kwargs(context) context[2] end |
.get_log_context(context) ⇒ Hash?
Returns log context associated with the task.
63 64 65 |
# File 'lib/rage/deferred/context.rb', line 63 def self.get_log_context(context) context[5] end |
.get_log_tags(context) ⇒ Array?
Returns log tags associated with the task.
58 59 60 |
# File 'lib/rage/deferred/context.rb', line 58 def self.(context) context[4] end |
.get_or_create_args(context) ⇒ Array
Returns arguments the task was enqueued with, creating it if it does not exist.
33 34 35 |
# File 'lib/rage/deferred/context.rb', line 33 def self.get_or_create_args(context) context[1] ||= [] end |
.get_or_create_kwargs(context) ⇒ Hash
Returns keyword arguments the task was enqueued with, creating it if it does not exist.
43 44 45 |
# File 'lib/rage/deferred/context.rb', line 43 def self.get_or_create_kwargs(context) context[2] ||= {} end |
.get_or_create_user_context(context) ⇒ Hash
Returns user context associated with the task, creating it if it does not exist.
73 74 75 |
# File 'lib/rage/deferred/context.rb', line 73 def self.get_or_create_user_context(context) context[6] ||= {} end |
.get_task(context) ⇒ Class
Returns the task class.
23 24 25 |
# File 'lib/rage/deferred/context.rb', line 23 def self.get_task(context) context[0] end |
.get_user_context(context) ⇒ Hash?
Returns user context associated with the task.
68 69 70 |
# File 'lib/rage/deferred/context.rb', line 68 def self.get_user_context(context) context[6] end |
.inc_attempts(context) ⇒ Object
Increments the number of attempts made to process the task
53 54 55 |
# File 'lib/rage/deferred/context.rb', line 53 def self.inc_attempts(context) context[3] = context[3].to_i + 1 end |