Class: Atig::Agent::Agent

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/atig/agent/agent.rb

Direct Known Subclasses

Mention, Timeline

Instance Method Summary collapse

Methods included from ExceptionUtil

daemon, safe

Constructor Details

#initialize(context, api, db) ⇒ Agent

Returns a new instance of Agent.



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 'lib/atig/agent/agent.rb', line 10

def initialize(context, api, db)
  @log = context.log
  @api = api
  @prev = nil

  log :info, "initialize"

  @api.repeat( interval ) do|t|
    q = { count: 200 }
    if @prev
      q.update since_id: @prev
    else
      q.update count: 20
    end

    sources = t.get( path, q)

    sources.reverse_each do|s|
      db.statuses.transaction do|d|
        d.add source: source, status: s, user: s.user
      end
    end

    @prev = sources.first.id if sources && !sources.empty?
  end
end