Class: Cloudflare::QueueContext
- Inherits:
-
Object
- Object
- Cloudflare::QueueContext
- Defined in:
- lib/cloudflare_workers/queue.rb
Overview
‘self` inside a `consume_queue do |batch| … end` block. Exposes env / ctx helpers alongside the batch so the block can reach the same D1 / KV / R2 bindings an HTTP route would. This keeps the consumer side consistent with Phase 9’s ScheduledContext.
Instance Attribute Summary collapse
-
#batch ⇒ Object
readonly
Returns the value of attribute batch.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#js_ctx ⇒ Object
readonly
Returns the value of attribute js_ctx.
-
#js_env ⇒ Object
readonly
Returns the value of attribute js_env.
Instance Method Summary collapse
- #bucket ⇒ Object
- #db ⇒ Object
-
#initialize(batch, js_env, js_ctx) ⇒ QueueContext
constructor
A new instance of QueueContext.
- #kv ⇒ Object
-
#wait_until(promise) ⇒ Object
Hand a long-running promise to ctx.waitUntil.
Constructor Details
#initialize(batch, js_env, js_ctx) ⇒ QueueContext
Returns a new instance of QueueContext.
363 364 365 366 367 368 |
# File 'lib/cloudflare_workers/queue.rb', line 363 def initialize(batch, js_env, js_ctx) @batch = batch @js_env = js_env @js_ctx = js_ctx @env = build_env(js_env) end |
Instance Attribute Details
#batch ⇒ Object (readonly)
Returns the value of attribute batch.
361 362 363 |
# File 'lib/cloudflare_workers/queue.rb', line 361 def batch @batch end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
361 362 363 |
# File 'lib/cloudflare_workers/queue.rb', line 361 def env @env end |
#js_ctx ⇒ Object (readonly)
Returns the value of attribute js_ctx.
361 362 363 |
# File 'lib/cloudflare_workers/queue.rb', line 361 def js_ctx @js_ctx end |
#js_env ⇒ Object (readonly)
Returns the value of attribute js_env.
361 362 363 |
# File 'lib/cloudflare_workers/queue.rb', line 361 def js_env @js_env end |
Instance Method Details
#bucket ⇒ Object
372 |
# File 'lib/cloudflare_workers/queue.rb', line 372 def bucket; env['cloudflare.BUCKET']; end |
#db ⇒ Object
370 |
# File 'lib/cloudflare_workers/queue.rb', line 370 def db; env['cloudflare.DB']; end |
#kv ⇒ Object
371 |
# File 'lib/cloudflare_workers/queue.rb', line 371 def kv; env['cloudflare.KV']; end |
#wait_until(promise) ⇒ Object
Hand a long-running promise to ctx.waitUntil. Mirrors the same helper in Sinatra::Scheduled’s ScheduledContext.
376 377 378 379 380 381 |
# File 'lib/cloudflare_workers/queue.rb', line 376 def wait_until(promise) return promise if @js_ctx.nil? js_ctx = @js_ctx `#{js_ctx}.waitUntil(#{promise})` promise end |