Permalink
Browse files

Add the ability to process un-answered units

  • Loading branch information...
1 parent f9b7a81 commit fba083e6b13a360edde0c9cf9ed585bf01478413 @rwdaigle committed Jun 1, 2012
View
@@ -30,25 +30,22 @@ def seedRandom(seed)
end
def process!(subject_id, overwrite=false)
- log({ 'subject_id' => subject_id, 'overwrite' => overwrite }) do
- subject = self.find(subject_id)
- subject.process!(overwrite) if subject
- end
+ subject = self.find(subject_id)
+ subject.process!(overwrite) if subject
end
end
def process!(overwrite = false)
- with_processor do |processor_klass|
- (overwrite ? units : units.empty).each do |unit|
- processor_klass.process!(self, unit)
- end
+ (overwrite ? units : units.empty).each do |unit|
+ $queue.enqueue("WordnikProcessor.process!", unit.id)
end
end
- def with_processor(&block)
- processor_klass = resolve_processor_class
- yield processor_klass if processor_klass
- end
+ # # Processors are now unit-specific
+ # def with_processor(&block)
+ # processor_klass = resolve_processor_class
+ # yield processor_klass if processor_klass
+ # end
# Override the param field to use in URIs
def to_param; permalink; end
@@ -4,13 +4,13 @@ class WordnikProcessor
class << self
- def process!(subject, unit)
- result = answer = nil
- log(subject, unit, { 'answer' => answer }) do
+ def process!(unit_id)
+ unit = Unit.find(unit_id)
+ log({'action' => "wordnik-process"}, unit) do
result = Wordnik.word.get_definitions(unit.question, :limit => 1)
answer = result && !result.empty? ? result[0]['text'] : nil
unit.update_attributes(answer: answer)
- end
+ end if unit
end
end
end
@@ -13,21 +13,30 @@ def receive(log_data)
def event_receivers
[
- # EVENT_IMPORT_WOD_WORDNIK_PERFORMANCE
+ # EVENT_IMPORT_WOD_WORDNIK
lambda { |action, log_data|
if(action == 'wod-import')
stat_hat_post_performance(StatHatConfig::EVENT_IMPORT_WOD_WORDNIK_PERFORMANCE, log_data)
stat_hat_post_increment(StatHatConfig::EVENT_IMPORT_WOD_WORDNIK_REQUEST)
end
},
- # EVENT_IMPORT_EMAIL_PERFORMANCE
+ # EVENT_IMPORT_EMAIL
lambda { |action, log_data|
if(action == 'email-import')
stat_hat_post_performance(StatHatConfig::EVENT_IMPORT_EMAIL_PERFORMANCE, log_data)
stat_hat_post_increment(StatHatConfig::EVENT_IMPORT_EMAIL_REQUEST)
end
}
+
+ # EVENT_PROCESS_WORDNIK
+ lambda { |action, log_data|
+ if(action == 'wordnik-process')
+ stat_hat_post_performance(StatHatConfig::EVENT_PROCESS_WORDNIK_PERFORMANCE, log_data)
+ stat_hat_post_increment(StatHatConfig::EVENT_PROCESS_WORDNIK_REQUEST)
+ end
+ }
+
]
end
@@ -6,4 +6,8 @@ module StatHatConfig
EVENT_IMPORT_EMAIL_PERFORMANCE = 'Email Import Performance'
EVENT_IMPORT_EMAIL_REQUEST = 'Email Import Requests'
+ # Processors
+ EVENT_PROCESS_WORDNIK_PERFORMANCE = 'Wordnik Process Performance'
+ EVENT_PROCESS_WORDNIK_REQUEST = 'Wordnik Process Requests'
+
end
View
@@ -1,10 +1,10 @@
namespace :ptls do
- desc "Auto translate the units of the SUBJECT_ID env variable"
- task :translate => :environment do
- subject = Subject.find(ENV['SUBJECT_ID'])
- subject.translate if subject
- end
+ # desc "Auto translate the units of the SUBJECT_ID env variable"
+ # task :translate => :environment do
+ # subject = Subject.find(ENV['SUBJECT_ID'])
+ # subject.translate if subject
+ # end
desc "Load words from external sources"
task :load => :environment do
@@ -13,4 +13,9 @@ namespace :ptls do
# klass.load!
end
end
+
+ desc "Process un-answered units"
+ task :process => :environment do
+ $queue.enqueue("Subject.process!", Subject.vocabulary.id)
+ end
end

0 comments on commit fba083e

Please sign in to comment.