Class: Delfos::Neo4j::Batch::Execution
- Inherits:
-
Object
- Object
- Delfos::Neo4j::Batch::Execution
- Defined in:
- lib/delfos/neo4j/batch/execution.rb
Constant Summary collapse
- BATCH_MUTEX =
Mutex.new
Class Attribute Summary collapse
-
.batch ⇒ Object
writeonly
Sets the attribute batch.
Instance Attribute Summary collapse
-
#commit_url ⇒ Object
readonly
Returns the value of attribute commit_url.
-
#current_transaction_url ⇒ Object
readonly
Returns the value of attribute current_transaction_url.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
- .execute!(query, params: {}, size: nil) ⇒ Object
- .flush! ⇒ Object
- .new_batch(size) ⇒ Object
- .reset! ⇒ Object
Instance Method Summary collapse
- #execute!(query, params: {}, retrying: false) ⇒ Object
- #flush! ⇒ Object
-
#initialize(size:, clock: Time) ⇒ Execution
constructor
A new instance of Execution.
- #query_count ⇒ Object
Constructor Details
#initialize(size:, clock: Time) ⇒ Execution
Returns a new instance of Execution.
34 35 36 37 38 39 40 41 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 34 def initialize(size:, clock: Time) @size = size @clock = clock @queries = [] @expires = nil @commit_url = nil @current_transaction_url = nil end |
Class Attribute Details
.batch=(value) ⇒ Object (writeonly)
Sets the attribute batch
31 32 33 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 31 def batch=(value) @batch = value end |
Instance Attribute Details
#commit_url ⇒ Object (readonly)
Returns the value of attribute commit_url.
43 44 45 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 43 def commit_url @commit_url end |
#current_transaction_url ⇒ Object (readonly)
Returns the value of attribute current_transaction_url.
43 44 45 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 43 def current_transaction_url @current_transaction_url end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
43 44 45 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 43 def expires @expires end |
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
43 44 45 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 43 def queries @queries end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
43 44 45 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 43 def size @size end |
Class Method Details
.execute!(query, params: {}, size: nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 11 def execute!(query, params: {}, size: nil) batch = @batch || new_batch(size || 1_000) batch.execute!(query, params: params) end |
.flush! ⇒ Object
21 22 23 24 25 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 21 def flush! @batch&.flush! rescue reset! end |
.new_batch(size) ⇒ Object
17 18 19 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 17 def new_batch(size) @batch = new(size: size) end |
.reset! ⇒ Object
27 28 29 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 27 def reset! @batch = nil end |
Instance Method Details
#execute!(query, params: {}, retrying: false) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 45 def execute!(query, params: {}, retrying: false) queries.push([query, params]) unless with_retry() do BATCH_MUTEX.synchronize do check_for_expiry! perform_query(query, params) flush_if_required! end end end |
#flush! ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 58 def flush! return unless query_count.positive? return unless @commit_url QueryExecution::Transactional.flush!(@commit_url) reset! end |
#query_count ⇒ Object
66 67 68 |
# File 'lib/delfos/neo4j/batch/execution.rb', line 66 def query_count queries.length end |