Class: Dolphin::Worker
- Inherits:
-
Object
- Object
- Dolphin::Worker
- Includes:
- Celluloid, Util
- Defined in:
- lib/dolphin/worker.rb
Instance Method Summary collapse
- #delete_notification(notification) ⇒ Object
- #get_event(params) ⇒ Object
- #get_notification(notification) ⇒ Object
- #put_event(event_object) ⇒ Object
- #put_notification(notification) ⇒ Object
Methods included from Util
Instance Method Details
#delete_notification(notification) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/dolphin/worker.rb', line 110 def delete_notification(notification) notification = query_processor.delete_notification(notification) if query_processor_failed?(notification) return FailureObject.new('Failed to delete notification') end SuccessObject.new(notification) end |
#get_event(params) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/dolphin/worker.rb', line 85 def get_event(params) event = query_processor.get_event(params) if query_processor_failed?(event) return FailureObject.new('Failed to get events') end SuccessObject.new(event) end |
#get_notification(notification) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/dolphin/worker.rb', line 93 def get_notification(notification) notification_id = notification[:id] notification = query_processor.get_notification(notification_id) if query_processor_failed?(notification) return FailureObject.new('Failed to get notification') end SuccessObject.new(notification) end |
#put_event(event_object) ⇒ Object
10 11 12 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dolphin/worker.rb', line 10 def put_event(event_object) logger :info, "Worker put events #{event_object}" notification_id = event_object[:notification_id] = event_object[:message_type] future_event = query_processor.future.put_event(event_object) # if notification_id not exists, doesn't send notification. if notification_id.blank? return SuccessObject.new end future_notification = query_processor.future.get_notification(notification_id) # synchronized notifications = future_notification.value event_id = future_event.value if notifications.nil? = "Not found notification: #{event_object[:notification_id]}" logger :error, return FailureObject.new() end if query_processor_failed?(notifications) return FailureObject.new('Failed to get notifications') end notifications.each do |sender_type, values| if values.blank? logger :info, "Skip to notify message because notifications was blank." next end unless Sender::TYPES.include? sender_type = "Not found sender #{sender_type}" logger :error, # Does not do response to Request Handler. next end build_params = {} # TODO: Plugin case sender_type when 'email' build_params["to"] = values['to'] build_params["cc"] = values['cc'] build_params["bcc"] = values['bcc'] build_params["messages"] = event_object[:messages] end = (sender_type, , build_params) if .nil? = "Failed to build message: #{build_params}" logger :error, # Does not do response to Request Handler. next else .event_id = event_id end logger :info, "Send notification from Worker #{}" begin send_notification(sender_type, ) rescue => e logger :error, e # Does not do response to Request Handler. next end end SuccessObject.new end |
#put_notification(notification) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/dolphin/worker.rb', line 102 def put_notification(notification) notification = query_processor.put_notification(notification) if query_processor_failed?(notification) return FailureObject.new('Failed to put notification') end SuccessObject.new(notification) end |