Class: Sqewer::ExecutionContext
- Inherits:
-
Object
- Object
- Sqewer::ExecutionContext
- Defined in:
- lib/sqewer/execution_context.rb
Overview
Is passed to each Job when executing (is the argument for the #run
method
of the job). The job can use this object to submit extra jobs, or to get
at the things specific for the execution context (database/key-value store
connections, error handling transaction and so on).
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns a key of the execution environment by name.
-
#[]=(key, value) ⇒ Object
Sets a key in the execution environment.
-
#fetch(key, &blk) ⇒ Object
Returns a key of the execution environment, or executes the given block if the key is not set.
-
#initialize(submitter, extra_variables = {}) ⇒ ExecutionContext
constructor
Create a new ExecutionContext with an environment hash.
-
#logger ⇒ Logger
Returns the logger set in the execution environment, or the NullLogger if no logger is set.
-
#submit!(job, **execution_options) ⇒ Object
Submits one or more jobs to the queue.
Constructor Details
#initialize(submitter, extra_variables = {}) ⇒ ExecutionContext
Create a new ExecutionContext with an environment hash.
12 13 14 15 16 |
# File 'lib/sqewer/execution_context.rb', line 12 def initialize(submitter, extra_variables={}) @submitter = submitter @params = {} extra_variables.each_pair{|k, v| self[k] = v } end |
Instance Method Details
#[](key) ⇒ Object
Returns a key of the execution environment by name
36 37 38 |
# File 'lib/sqewer/execution_context.rb', line 36 def [](key) @params[key.to_s] end |
#[]=(key, value) ⇒ Object
Sets a key in the execution environment
29 30 31 |
# File 'lib/sqewer/execution_context.rb', line 29 def []=(key, value) @params[key.to_s] = value end |
#fetch(key, &blk) ⇒ Object
Returns a key of the execution environment, or executes the given block if the key is not set
45 46 47 |
# File 'lib/sqewer/execution_context.rb', line 45 def fetch(key, &blk) @params.fetch(key.to_s, &blk) end |
#logger ⇒ Logger
Returns the logger set in the execution environment, or the NullLogger if no logger is set. Can be used to supply a logger prefixed with job parameters per job.
54 55 56 |
# File 'lib/sqewer/execution_context.rb', line 54 def logger @params.fetch('logger') { Sqewer::NullLogger } end |
#submit!(job, **execution_options) ⇒ Object
Submits one or more jobs to the queue
21 22 23 |
# File 'lib/sqewer/execution_context.rb', line 21 def submit!(job, **) @submitter.submit!(job, **) end |