Class: Sinatra::Scheduled::ScheduledContext
- Inherits:
-
Object
- Object
- Sinatra::Scheduled::ScheduledContext
- Defined in:
- lib/sinatra/scheduled.rb
Overview
ScheduledContext is the ‘self` inside a `schedule do … end` block. It deliberately mirrors only the slice of Sinatra’s request scope that makes sense outside an HTTP context: env, logger, settings, and Cloudflare binding helpers (db / kv / bucket).
Defined Under Namespace
Classes: LoggerShim
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
Instance Method Summary collapse
- #bucket ⇒ Object
- #db ⇒ Object
-
#initialize(env, event, js_ctx) ⇒ ScheduledContext
constructor
A new instance of ScheduledContext.
- #kv ⇒ Object
-
#logger ⇒ Object
Minimal logger so jobs can puts without crashing in non-Workers test environments.
-
#wait_until(promise) ⇒ Object
Forward a long-running promise to the Workers runtime so the job can return immediately while the work continues.
Constructor Details
#initialize(env, event, js_ctx) ⇒ ScheduledContext
Returns a new instance of ScheduledContext.
295 296 297 298 299 |
# File 'lib/sinatra/scheduled.rb', line 295 def initialize(env, event, js_ctx) @env = env @event = event @js_ctx = js_ctx end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
293 294 295 |
# File 'lib/sinatra/scheduled.rb', line 293 def env @env end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
293 294 295 |
# File 'lib/sinatra/scheduled.rb', line 293 def event @event end |
Instance Method Details
#bucket ⇒ Object
303 |
# File 'lib/sinatra/scheduled.rb', line 303 def bucket; env['cloudflare.BUCKET']; end |
#db ⇒ Object
301 |
# File 'lib/sinatra/scheduled.rb', line 301 def db; env['cloudflare.DB']; end |
#kv ⇒ Object
302 |
# File 'lib/sinatra/scheduled.rb', line 302 def kv; env['cloudflare.KV']; end |
#logger ⇒ Object
Minimal logger so jobs can puts without crashing in non-Workers test environments. Falls back to STDOUT.
317 318 319 |
# File 'lib/sinatra/scheduled.rb', line 317 def logger @logger ||= LoggerShim.new end |
#wait_until(promise) ⇒ Object
Forward a long-running promise to the Workers runtime so the job can return immediately while the work continues. Mirrors ‘ctx.waitUntil(promise)` in the JS API.
308 309 310 311 312 313 |
# File 'lib/sinatra/scheduled.rb', line 308 def wait_until(promise) return promise if @js_ctx.nil? js_ctx = @js_ctx `#{js_ctx}.waitUntil(#{promise})` promise end |