-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
58 lines (48 loc) · 1.59 KB
/
Rakefile
1
2
3
4
5
6
7
8
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
require_relative 'spec/spec_cache_retriever'
if !ENV['deployment']
Dir["lib/tasks/machine_learning/*.rake"].each { |file| import file }
end
namespace :tmp do
desc 'Clears all cached artifacts'
task :clear do
files = Dir['./tmp/**/*.*']
FileUtils.rm(files, verbose: true)
end
end
task :setup_processing do
require 'colorize'
require_relative './lib/logging'
require 'logger'
Logging.logger = Logger.new(STDOUT)
end
desc 'Process unprocessed bills'
task process: :setup_processing do
process(:unprocessed, :to_process_queue) do |recognition_result, _bill, meteor|
include Logging
id = recognition_result.delete :id
logger.info ["result for bill #{id}:", recognition_result].map(&:to_s)
.map(&:yellow).join(' ')
meteor.write_detection_result(id, recognition_result)
end
end
desc 'Reprocess bills from older versions of the processor'
task reprocess: :setup_processing do
process(:toReprocess, :to_reprocess_queue) do |recognition_result, _bill, meteor|
include Logging
id = recognition_result.delete :id
logger.info ["result for bill #{id}:", recognition_result].map(&:to_s)
.map(&:yellow).join(' ')
meteor.write_detection_result(id, recognition_result)
end
end
def process(bill_kind, queue, &bill_proc)
require 'erb'
require 'yaml'
require_relative 'lib/hub'
environment = ENV['RECOGNIZER_ENV'] || 'development'
config_yaml = ERB.new(IO.read('config.yml')).result
config = YAML.load(config_yaml)[environment].freeze
hub = Hub.new(bills: bill_kind, config: config, queue: queue)
hub.run(&bill_proc)
end