Class: Ryespy::Listener::FTP

Inherits:
Base
  • Object
show all
Defined in:
lib/ryespy/listener/ftp.rb

Constant Summary collapse

REDIS_KEY_PREFIX =
'ftp'.freeze
SIDEKIQ_JOB_CLASS =
'RyespyFTPJob'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FTP

Returns a new instance of FTP.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ryespy/listener/ftp.rb', line 13

def initialize(opts = {})
  @ftp_config = {
    :host     => opts[:host],
    :port     => opts[:port],
    :passive  => opts[:passive],
    :username => opts[:username],
    :password => opts[:password],
  }
  
  super(opts)
end

Instance Method Details

#check(dir) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ryespy/listener/ftp.rb', line 29

def check(dir)
  @logger.debug { "dir: #{dir}" }
  
  @logger.debug { "redis_key: #{redis_key(dir)}" }
  
  seen_files = @redis.hgetall(redis_key(dir))
  
  unseen_files = get_unseen_files(dir, seen_files)
  
  @logger.debug { "unseen_files: #{unseen_files}" }
  
  unseen_files.each do |filename, checksum|
    @redis.hset(redis_key(dir), filename, checksum)
    
    @notifiers.each { |n| n.notify(SIDEKIQ_JOB_CLASS, [dir, filename]) }
  end
  
  @logger.info { "#{dir} has #{unseen_files.count} new files" }
end

#closeObject



25
26
27
# File 'lib/ryespy/listener/ftp.rb', line 25

def close
  @ftp.close
end