Class: Cloudflare::QueueContext
- Inherits:
-
Object
- Object
- Cloudflare::QueueContext
- Defined in:
- lib/homura/runtime/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
- #ai ⇒ Object
- #bucket ⇒ Object
- #cf_ctx ⇒ Object
- #cf_env ⇒ Object
- #d1 ⇒ Object
- #db ⇒ Object
- #durable_object(name, id_or_name = nil) ⇒ Object
-
#initialize(batch, js_env, js_ctx) ⇒ QueueContext
constructor
A new instance of QueueContext.
- #jobs_queue ⇒ Object
- #kv ⇒ Object
- #send_email ⇒ 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.
396 397 398 399 400 401 |
# File 'lib/homura/runtime/queue.rb', line 396 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.
394 395 396 |
# File 'lib/homura/runtime/queue.rb', line 394 def batch @batch end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
394 395 396 |
# File 'lib/homura/runtime/queue.rb', line 394 def env @env end |
#js_ctx ⇒ Object (readonly)
Returns the value of attribute js_ctx.
394 395 396 |
# File 'lib/homura/runtime/queue.rb', line 394 def js_ctx @js_ctx end |
#js_env ⇒ Object (readonly)
Returns the value of attribute js_env.
394 395 396 |
# File 'lib/homura/runtime/queue.rb', line 394 def js_env @js_env end |
Instance Method Details
#ai ⇒ Object
421 422 423 |
# File 'lib/homura/runtime/queue.rb', line 421 def ai Cloudflare::Bindings.ai(env) end |
#bucket ⇒ Object
418 419 420 |
# File 'lib/homura/runtime/queue.rb', line 418 def bucket env["cloudflare.BUCKET"] end |
#cf_ctx ⇒ Object
412 413 414 |
# File 'lib/homura/runtime/queue.rb', line 412 def cf_ctx env["cloudflare.ctx"] end |
#cf_env ⇒ Object
409 410 411 |
# File 'lib/homura/runtime/queue.rb', line 409 def cf_env env["cloudflare.env"] end |
#d1 ⇒ Object
403 404 405 |
# File 'lib/homura/runtime/queue.rb', line 403 def d1 env["cloudflare.DB"] end |
#db ⇒ Object
406 407 408 |
# File 'lib/homura/runtime/queue.rb', line 406 def db d1 end |
#durable_object(name, id_or_name = nil) ⇒ Object
430 431 432 |
# File 'lib/homura/runtime/queue.rb', line 430 def durable_object(name, id_or_name = nil) Cloudflare::Bindings.durable_object(env, name, id_or_name) end |
#jobs_queue ⇒ Object
427 428 429 |
# File 'lib/homura/runtime/queue.rb', line 427 def jobs_queue env["cloudflare.QUEUE_JOBS"] end |
#kv ⇒ Object
415 416 417 |
# File 'lib/homura/runtime/queue.rb', line 415 def kv env["cloudflare.KV"] end |
#send_email ⇒ Object
424 425 426 |
# File 'lib/homura/runtime/queue.rb', line 424 def send_email env["cloudflare.SEND_EMAIL"] end |
#wait_until(promise) ⇒ Object
Hand a long-running promise to ctx.waitUntil. Mirrors the same helper in Sinatra::Scheduled’s ScheduledContext.
436 437 438 439 440 441 |
# File 'lib/homura/runtime/queue.rb', line 436 def wait_until(promise) return promise if @js_ctx.nil? js_ctx = @js_ctx `#{js_ctx}.waitUntil(#{promise})` promise end |