Commit 12440cec8a8406ab60c1ca8653e1763e7d7e6ab6
1 parent
593da77e
Exists in
master
and in
28 other branches
Logging Spaminator movements
Showing
3 changed files
with
26 additions
and
2 deletions
Show diff stats
plugins/spaminator/controllers/spaminator_plugin_admin_controller.rb
@@ -34,7 +34,7 @@ class SpaminatorPluginAdminController < AdminController | @@ -34,7 +34,7 @@ class SpaminatorPluginAdminController < AdminController | ||
34 | settings.scanning = true | 34 | settings.scanning = true |
35 | settings.save! | 35 | settings.save! |
36 | remove_scheduled_scan | 36 | remove_scheduled_scan |
37 | - Delayed::Job.enqueue(SpaminatorPlugin::ScanJob.new(environment)) | 37 | + Delayed::Job.enqueue(SpaminatorPlugin::ScanJob.new(environment.id)) |
38 | end | 38 | end |
39 | redirect_to :action => 'index' | 39 | redirect_to :action => 'index' |
40 | end | 40 | end |
plugins/spaminator/lib/spaminator_plugin/scan_job.rb
@@ -6,7 +6,11 @@ class SpaminatorPlugin::ScanJob < Struct.new(:environment_id) | @@ -6,7 +6,11 @@ class SpaminatorPlugin::ScanJob < Struct.new(:environment_id) | ||
6 | settings.scanning = true | 6 | settings.scanning = true |
7 | settings.save! | 7 | settings.save! |
8 | 8 | ||
9 | - SpaminatorPlugin::Spaminator.run(environment) | 9 | + begin |
10 | + SpaminatorPlugin::Spaminator.run(environment) | ||
11 | + rescue Exception => exception | ||
12 | + SpaminatorPlugin::Spaminator.log("Spaminator failed with the following error: \n ==> #{exception}\n#{exception.backtrace.join("\n")}") | ||
13 | + end | ||
10 | 14 | ||
11 | settings.scanning = false | 15 | settings.scanning = false |
12 | SpaminatorPlugin.schedule_scan(environment) if settings.deployed | 16 | SpaminatorPlugin.schedule_scan(environment) if settings.deployed |
plugins/spaminator/lib/spaminator_plugin/spaminator.rb
@@ -11,6 +11,14 @@ class SpaminatorPlugin::Spaminator | @@ -11,6 +11,14 @@ class SpaminatorPlugin::Spaminator | ||
11 | def benchmark(environment) | 11 | def benchmark(environment) |
12 | puts Benchmark.measure { run(environment) } | 12 | puts Benchmark.measure { run(environment) } |
13 | end | 13 | end |
14 | + | ||
15 | + def initialize_logger(logpath) | ||
16 | + @logger = Logger.new(logpath) | ||
17 | + end | ||
18 | + | ||
19 | + def log(message) | ||
20 | + @logger << "[#{Time.now.strftime("%F %T %z")}] #{message}\n" | ||
21 | + end | ||
14 | end | 22 | end |
15 | 23 | ||
16 | 24 | ||
@@ -20,9 +28,12 @@ class SpaminatorPlugin::Spaminator | @@ -20,9 +28,12 @@ class SpaminatorPlugin::Spaminator | ||
20 | @report = SpaminatorPlugin::Report.new(:environment => environment, | 28 | @report = SpaminatorPlugin::Report.new(:environment => environment, |
21 | :total_people => Person.count, | 29 | :total_people => Person.count, |
22 | :total_comments => Comment.count) | 30 | :total_comments => Comment.count) |
31 | + logpath = File.join(SpaminatorPlugin.root_path, 'log', "#{environment.name.to_slug}_#{ENV['RAILS_ENV']}_#{Time.now.strftime("%F_%T")}.log") | ||
32 | + self.class.initialize_logger(logpath) | ||
23 | end | 33 | end |
24 | 34 | ||
25 | def run | 35 | def run |
36 | + self.class.log("Starting Spaminator scan") | ||
26 | start_time = Time.now | 37 | start_time = Time.now |
27 | 38 | ||
28 | process_all_comments | 39 | process_all_comments |
@@ -37,6 +48,7 @@ class SpaminatorPlugin::Spaminator | @@ -37,6 +48,7 @@ class SpaminatorPlugin::Spaminator | ||
37 | finish_report | 48 | finish_report |
38 | @settings.last_run = start_time | 49 | @settings.last_run = start_time |
39 | @settings.save! | 50 | @settings.save! |
51 | + self.class.log("Finishing Spaminator scan successfully") | ||
40 | end | 52 | end |
41 | 53 | ||
42 | # TODO considering run everything always | 54 | # TODO considering run everything always |
@@ -53,6 +65,7 @@ class SpaminatorPlugin::Spaminator | @@ -53,6 +65,7 @@ class SpaminatorPlugin::Spaminator | ||
53 | end | 65 | end |
54 | 66 | ||
55 | def process_all_comments | 67 | def process_all_comments |
68 | + self.class.log("Starting to process all comments") | ||
56 | comments = comments_to_process | 69 | comments = comments_to_process |
57 | total = comments.count | 70 | total = comments.count |
58 | pbar = ProgressBar.new("☢ Comments", total) | 71 | pbar = ProgressBar.new("☢ Comments", total) |
@@ -66,9 +79,11 @@ class SpaminatorPlugin::Spaminator | @@ -66,9 +79,11 @@ class SpaminatorPlugin::Spaminator | ||
66 | end | 79 | end |
67 | @report.processed_comments = total | 80 | @report.processed_comments = total |
68 | pbar.finish | 81 | pbar.finish |
82 | + self.class.log("All comments processed") | ||
69 | end | 83 | end |
70 | 84 | ||
71 | def process_all_people | 85 | def process_all_people |
86 | + self.class.log("Starting to process all people") | ||
72 | people = people_to_process | 87 | people = people_to_process |
73 | total = people.count | 88 | total = people.count |
74 | pbar = ProgressBar.new("☢ People", total) | 89 | pbar = ProgressBar.new("☢ People", total) |
@@ -79,9 +94,11 @@ class SpaminatorPlugin::Spaminator | @@ -79,9 +94,11 @@ class SpaminatorPlugin::Spaminator | ||
79 | end | 94 | end |
80 | @report.processed_people = total | 95 | @report.processed_people = total |
81 | pbar.finish | 96 | pbar.finish |
97 | + self.class.log("All people processed") | ||
82 | end | 98 | end |
83 | 99 | ||
84 | def process_comment(comment) | 100 | def process_comment(comment) |
101 | + self.class.log("Processing Comment[#{comment.id.to_s}]") | ||
85 | comment = Comment.find(comment.id) | 102 | comment = Comment.find(comment.id) |
86 | comment.check_for_spam | 103 | comment.check_for_spam |
87 | @report.spams_by_content += 1 if comment.spam | 104 | @report.spams_by_content += 1 if comment.spam |
@@ -97,6 +114,7 @@ class SpaminatorPlugin::Spaminator | @@ -97,6 +114,7 @@ class SpaminatorPlugin::Spaminator | ||
97 | # person is author of more than 2 comments marked as spam | 114 | # person is author of more than 2 comments marked as spam |
98 | # → mark as spammer | 115 | # → mark as spammer |
99 | # | 116 | # |
117 | + self.class.log("Processing Person[#{person.id.to_s}] by comments") | ||
100 | begin | 118 | begin |
101 | number_of_spam_comments = Comment.spam.where(:author_id => person.id).count | 119 | number_of_spam_comments = Comment.spam.where(:author_id => person.id).count |
102 | if number_of_spam_comments > 2 | 120 | if number_of_spam_comments > 2 |
@@ -115,6 +133,7 @@ class SpaminatorPlugin::Spaminator | @@ -115,6 +133,7 @@ class SpaminatorPlugin::Spaminator | ||
115 | # → disable the profile | 133 | # → disable the profile |
116 | # ? mark their comments as spam | 134 | # ? mark their comments as spam |
117 | # | 135 | # |
136 | + self.class.log("Processing Person[#{person.id.to_s}] by network") | ||
118 | if person.created_at < (Time.now - 1.month) && | 137 | if person.created_at < (Time.now - 1.month) && |
119 | person.friends.count == 0 && | 138 | person.friends.count == 0 && |
120 | person.communities.count <= 1 | 139 | person.communities.count <= 1 |
@@ -151,6 +170,7 @@ class SpaminatorPlugin::Spaminator | @@ -151,6 +170,7 @@ class SpaminatorPlugin::Spaminator | ||
151 | end | 170 | end |
152 | 171 | ||
153 | def register_fail(kind, failed) | 172 | def register_fail(kind, failed) |
173 | + self.class.log("Failed #{kind.to_s.camelize}[#{failed.id.to_s}]") | ||
154 | @report[:failed][kind.to_sym] << failed.id | 174 | @report[:failed][kind.to_sym] << failed.id |
155 | end | 175 | end |
156 | end | 176 | end |