Browse Source

Replaced puts for rails logger and enabled info logging on rake tasks + new tasks for deleting all action logs

master
rodley82 4 years ago
parent
commit
8ffaa0fd2c
  1. 6
      app/interactors/monitor_inbox.rb
  2. 1
      db/migrate/20220307195441_add_action_logs_table.rb
  3. 16
      lib/tasks/monitor.rake

6
app/interactors/monitor_inbox.rb

@ -43,7 +43,7 @@ class MonitorInbox
# Analiza uno a uno los elmentos del array de emails
def analyze_emails(emails_arr)
emails_arr.each do |email|
puts "Analyzing email with subject: #{email.subject} From: #{email.from} On #{email.date}"
Rails.logger.info "Analyzing email with subject: #{email.subject} From: #{email.from} On #{email.date}"
if is_action_email?(email)
execute_action(email)
end
@ -65,7 +65,7 @@ class MonitorInbox
)
if al.valid?
puts "Executing action..."
Rails.logger.info "Executing action..."
command = ENV["COMMAND"]
system(command)
context.actions_executed_count+=1
@ -73,7 +73,7 @@ class MonitorInbox
else
# We're using the validate uniqueness of ActionLog to detect duplicate actions
# we have already processed if we get this exception we should not execute it
puts "We have already executed this action"
Rails.logger.info "We have already executed this action"
end
end
end

1
db/migrate/20220307195441_add_action_logs_table.rb

@ -8,4 +8,3 @@ class AddActionLogsTable < ActiveRecord::Migration[7.0]
end
end
end

16
lib/tasks/monitor.rake

@ -1,9 +1,19 @@
namespace :monitor do
desc "executes the monitoring logic"
task :run => :environment do
puts "About to check #{ENV["EMAIL"]} inbox..."
Rails.logger = Logger.new(STDOUT)
Rails.logger.level = Logger::INFO
Rails.logger.info "About to check #{ENV["EMAIL"]} inbox..."
res = MonitorInbox.call!
puts "A total of #{res.analyzed_emails_count} new emails were analyzed"
puts "A total of #{res.actions_executed_count} actions were triggered"
Rails.logger.info "A total of #{res.analyzed_emails_count} new emails were analyzed"
Rails.logger.info "A total of #{res.actions_executed_count} actions were triggered"
end
desc "deletes all log entries"
task :clear_log => :environment do
Rails.logger = Logger.new(STDOUT)
Rails.logger.level = Logger::INFO
Rails.logger.info "About to clear all log entries"
ActionLog.delete_all
end
end

Loading…
Cancel
Save