Class: MyFirebaseWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/my_firebase_worker.rb

Overview

Updating Firebase db record takes some time, so we need to use Sidekiq to do it in background. Before we have this worker, the update process is done in the Reservation::Create service, which sometime slow down the processing time, so that's why we need to move it to background.

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(action, namespace, query, retry_count = 0) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/workers/my_firebase_worker.rb', line 7

def perform(action, namespace, query, retry_count = 0)
  firebase = MyFirebase.new
  firebase.send action.to_sym, namespace, query
rescue ::MyFirebase::RetryError => e
  retry_count = retry_count.to_i + 1
  if retry_count > 20
    # do nothing
    return
  end

  if retry_count.to_i > 3
    APMErrorHandler.report(e, action: action, namespace: namespace,
                              query: query, retry_count: retry_count)

  end

  delay = 10.seconds
  self.class.perform_in(delay, action, namespace, query, retry_count)
end