Class: FlowChat::BackgroundController

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_chat/async_job.rb

Overview

Duck-type controller for background jobs Provides render/head no-ops and request interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_data) ⇒ BackgroundController

Returns a new instance of BackgroundController.



70
71
72
73
74
75
# File 'lib/flow_chat/async_job.rb', line 70

def initialize(request_data)
  FlowChat.logger.debug { "BackgroundController: Initializing with request data" }
  @request = BackgroundRequest.new(request_data)
  @side_events_published = request_data[:side_events_published] || false
  @response = nil
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



68
69
70
# File 'lib/flow_chat/async_job.rb', line 68

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



68
69
70
# File 'lib/flow_chat/async_job.rb', line 68

def response
  @response
end

Instance Method Details

#head(status) ⇒ Object



97
98
99
100
101
# File 'lib/flow_chat/async_job.rb', line 97

def head(status)
  FlowChat.logger.debug { "BackgroundController: head called (no-op): #{status}" }
  @response = {status: status}
  nil  # No-op in background
end

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/flow_chat/async_job.rb', line 103

def is_a?(klass)
  return true if klass == FlowChat::BackgroundController
  super
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
# File 'lib/flow_chat/async_job.rb', line 108

def kind_of?(klass)
  return true if klass == FlowChat::BackgroundController
  super
end

#paramsObject

Delegate params to request (mimics Rails controller behavior)



87
88
89
# File 'lib/flow_chat/async_job.rb', line 87

def params
  request.params
end

#render(options) ⇒ Object



91
92
93
94
95
# File 'lib/flow_chat/async_job.rb', line 91

def render(options)
  FlowChat.logger.debug { "BackgroundController: render called (no-op): #{options.inspect}" }
  @response = options
  nil  # No-op in background
end

#side_events_published?Boolean

Whether the pass that enqueued this job already announced the delivery's side events. Only the gem sets it, when it enqueues a job of its own. An application that builds a request context by hand and enqueues directly has no earlier pass behind it, so the answer is false and the job is the one that announces them.

Returns:

  • (Boolean)


82
83
84
# File 'lib/flow_chat/async_job.rb', line 82

def side_events_published?
  @side_events_published
end