Class: Sync::SessionsWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/sync/sessions_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(from_time) ⇒ Object



9
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
# File 'app/workers/sync/sessions_worker.rb', line 9

def perform(from_time)
  sessions = SessionRecord.where("started_at > ?", from_time).order("started_at").all

  sessions.each do |session|
    Sidekiq::Logging.logger.info "- submitting session #{session.message_id}"

    providers = RestClient::Request.execute(
      :method       => :post,
      :url          => "#{Terminal.config.host}/session_records",
      :timeout      => 40,
      :open_timeout => 60,
      :payload => {
        :terminal => Terminal.keyword,
        :session_record => {
          :message_id => session.message_id,
          :started_at => session.started_at,
          :upstream   => session.upstream,
          :downstream => session.downstream,
          :time       => session.time
        }
      }
    )
  end

rescue Exception => e
  Sidekiq::Logging.logger.warn e.to_s
end