Class: Processor
- Inherits:
-
Object
show all
- Includes:
- Logging
- Defined in:
- lib/flickrup/processor.rb
Instance Method Summary
collapse
Methods included from Logging
logger, #logger, pre_init
Constructor Details
#initialize(config) ⇒ Processor
Returns a new instance of Processor.
17
18
19
20
21
|
# File 'lib/flickrup/processor.rb', line 17
def initialize(config)
@MAX_DATE = Time.at(2130578470)
@config = config
@converter = Converter.new(config[:convert_files])
end
|
Instance Method Details
#paused ⇒ Object
23
24
25
|
# File 'lib/flickrup/processor.rb', line 23
def paused
Dir["#{@config[:watch_dir]}/paused"].length > 0
end
|
#run(all_files = Dir["#{@config[:watch_dir]}/*.*"]) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/flickrup/processor.rb', line 27
def run(all_files = Dir["#{@config[:watch_dir]}/*.*"])
logger.info("Processing #{all_files.length} files")
if paused
logger.info("Paused detected, so skipping processing...")
return 0
end
converted_count = all_files.select{ |x|
if File.exist? x
@converter.maybe_convert(x)
else
false
end
}.length
if converted_count > 0
logger.info("Converted #{converted_count} files, reprocessing")
return true
end
files = all_files.map { |x|
if File.exist? x
begin
TaggedFile.create(x)
rescue => e
logger.error("Failed to load file #{x}: #{e}")
logger.info("Aborting run")
return false
end
else
logger.debug("File #{x} already removed, skipping.")
end
}.compact
logger.debug("Scanned #{files.length} files")
by_date = files.sort_by { |x|
x.date_created || @MAX_DATE
}
tagged = by_date.take_while { |x|
!(x.tags.nil? || x.tags.empty?)
}
if tagged.empty?
logger.info('No files selected for upload')
unless by_date.empty?
logger.debug("Stopped on #{by_date[0].filename}")
end
else
logger.info("Selected #{tagged.length} files for upload")
end
uploader = get_uploader
if @config[:dryrun]
logger.info("Would now upload & move #{tagged.length} files, pausing for 5 secs instead")
sleep 5
else
tagged.each do |x|
begin
logger.info("Beginning upload for #{x.filename}...")
unless x.doUpload(get_preupload_handlers, uploader)
break end
logger.info("Upload complete for #{x.filename}")
logger.info("Beginning archive for #{x.filename}...")
x.archive(get_archiver, @config[:archive_dir])
logger.info("Processing complete for #{x.filename}")
rescue => e
logger.error("Failed to process #{x.filename} due to exception: #{e}")
logger.info(e.backtrace.join("\n"))
end
end
end
logger.info("Processed #{tagged.length} valid files")
false
end
|