Class: Jets::Shim::Adapter::Fallback
- Inherits:
-
Base
- Object
- Base
- Jets::Shim::Adapter::Fallback
show all
- Defined in:
- lib/jets/shim/adapter/fallback.rb
Instance Attribute Summary
Attributes inherited from Base
#context, #event, #target
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize
#log
Class Method Details
.handler(event, context = nil, target = nil) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/jets/shim/adapter/fallback.rb', line 13
def handler(event, context = nil, target = nil)
puts <<~EOL
WARN: handler for it could not be found. The default fallback handler is being used.
The default fallback handler simply prints out the event payload for debugging, it will be printed below.
Usually the default handler is not what you want.
You might be using a test event payload for testing which does not represent a real event.
Please double check the event payload.
EOL
if ENV["_HANDLER"] puts "event: #{JSON.dump(event)}"
else
puts "event:"
puts JSON.pretty_generate(event)
end
if target
puts "WARN: Event handler target not found: #{target}".color(:red)
target_class, target_method = target.split(".")
target_class = target_class.camelize
target_method ||= "perform"
puts <<~EOL
You can configure define an app/events handler in your application. Example:
app/events/#{target_class.underscore}.rb
class #{target_class} < ApplicationEvent
def #{target_method}
puts "event #{JSON.dump(event)}"
end
end
EOL
else
puts <<~EOL
You can also configure a custom fallback handler with a config/jets/shim.rb file.
Though custom handlers rarely needed and you should double check the event payload.
Example:
config/jets/shim.rb
Jets.shim.configure do |config|
config.fallback_handler = FallbackHandler
end
FallbackHandler should implement handler(event, context)
EOL
end
{
errorMessage: "Event handler not found. Look at logs for details",
errorType: "JetsEventHandlerNotFound"
}
end
|
Instance Method Details
#fallback_handler ⇒ Object
7
8
9
|
# File 'lib/jets/shim/adapter/fallback.rb', line 7
def fallback_handler
Jets::Shim.config.fallback_handler || self.class
end
|
#handle ⇒ Object
3
4
5
|
# File 'lib/jets/shim/adapter/fallback.rb', line 3
def handle
fallback_handler.handler(event, context, target)
end
|