Class: Cangaroo::PollJob

Inherits:
BaseJob
  • Object
show all
Defined in:
app/jobs/cangaroo/poll_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Job

#payload, #source_connection, #type

Methods included from LoggerHelper

#job_tags

Instance Attribute Details

#current_timeObject (readonly)

Returns the value of attribute current_time.



5
6
7
# File 'app/jobs/cangaroo/poll_job.rb', line 5

def current_time
  @current_time
end

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/jobs/cangaroo/poll_job.rb', line 11

def perform(*)
  @current_time = DateTime.now

  if !perform?(current_time)
    Cangaroo.logger.info 'skipping poll', job_tags
    return
  end

  restart_flow(connection_request)

  update_last_poll_timestamp
end

#perform?(execution_time) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'app/jobs/cangaroo/poll_job.rb', line 24

def perform?(execution_time)
  last_poll_timestamp.nil? ||
    execution_time.to_i - last_poll_timestamp.to_i > self.class.frequency
end

#transformObject



7
8
9
# File 'app/jobs/cangaroo/poll_job.rb', line 7

def transform
  { last_poll: last_poll_timestamp.to_i }
end