sms-logparser 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d9aa56b379edf1fef5f9322463a6fa581d38ff8
4
- data.tar.gz: ef45045d3538b34b9612f1fca2b7fe546e5d2583
3
+ metadata.gz: 296d8d061cd01d90fe03d842a78bdbf343e512ef
4
+ data.tar.gz: 7ead0d25faed08ce7fe3082a06d8d14dfbb67f76
5
5
  SHA512:
6
- metadata.gz: 3a5bd6d467611916e182b95428f2fa49c7ef4131d92e2cd675559344db3b46b20a8376d0f8f9df85b145459fcaf120a2bfca4229fa8fc6f2c8fc76b55960ee3f
7
- data.tar.gz: 2324fde02fd0598af49909792cc928728d79cfd4117598f369e8ee90db43c658d1ccd8c0bb6a7d761309d12ced9a508f5c7f426dbbbde5059f129b8e56083c98
6
+ metadata.gz: 6c7fa5bdc80e292209795d134f4c56a5e2c73abcf985e18413cbbe741a09529408e1c0262f33925a9839b194a625eb4c32dc8accc678a726d916c42e9673b81d
7
+ data.tar.gz: a8bb321f3ecaa98b60a4d0144db508b1b61e718bdf082a2747e8ddadeafb51b03a89173a00f006c40c0b6c5e3b93d9d048bdaef3475be2099d64e9b39effc807
@@ -2,7 +2,7 @@ module SmsLogparser
2
2
  class Cli < Thor
3
3
  require 'yaml'
4
4
 
5
- STATUS = {ok: 0, api_error: 1}
5
+ STATUS = {ok: 0, api_error: 1, running: 3}
6
6
 
7
7
  class_option :config,
8
8
  default: File.join(Dir.home, '.sms-logparser.yml'),
@@ -59,14 +59,14 @@ module SmsLogparser
59
59
  def parse
60
60
  say "Starting the parser...", :green
61
61
  mysql = Mysql.new(options)
62
- if mysql.parser_running?
63
- say "Aborting. Another instance of the parser is already running.", :red
62
+ if !options[:simulate] && mysql.parser_running?
63
+ say "Exit. Another instance of the parser is already running.", :yellow
64
64
  exit
65
65
  end
66
66
  state = {
67
67
  last_event_id: mysql.get_last_parse_id,
68
68
  match_count: 0,
69
- status: STATUS[:ok],
69
+ status: STATUS[:running],
70
70
  run_at: Time.now,
71
71
  run_time: 0.0
72
72
  }
@@ -82,15 +82,18 @@ module SmsLogparser
82
82
  state[:last_event_id] = entry['ID']
83
83
  end
84
84
  end
85
+ state[:status] = STATUS[:ok]
85
86
  rescue => e
86
87
  say "Error: #{e.message}", :red
87
88
  say "Aborting parser run...", :red
88
89
  state[:status] = STATUS[:api_error] if state
89
90
  ensure
90
91
  begin
91
- if mysql
92
+ if mysql && state
92
93
  state[:run_time] = (Time.now - state[:run_at]).round(2)
93
- mysql.write_parse_result(state) unless options[:simulate]
94
+ if state[:id]
95
+ mysql.write_parse_result(state) unless options[:simulate]
96
+ end
94
97
  print_parse_results(state)
95
98
  end
96
99
  rescue => e
@@ -48,7 +48,7 @@ module SmsLogparser
48
48
  "SELECT status FROM sms_logparser_runs ORDER BY id DESC LIMIT 1"
49
49
  )
50
50
  if entry = last_parse.first
51
- return false unless entry['status'] == running_state
51
+ return entry['status'] == running_state ? true : false
52
52
  end
53
53
  false
54
54
  end
@@ -67,13 +67,12 @@ module SmsLogparser
67
67
 
68
68
  def write_parse_result(options)
69
69
  client.query(
70
- "UPDATE sms_logparser_runs SET match_count, status, run_time\
70
+ "UPDATE sms_logparser_runs SET\
71
71
  last_event_id = #{options[:last_event_id]},\
72
72
  match_count = #{options[:match_count]},\
73
73
  status = #{options[:status]},\
74
74
  run_time = #{options[:run_time]}\
75
- WHERE id = #{options[id]}
76
- )"
75
+ WHERE id = #{options[:id]}"
77
76
  )
78
77
  end
79
78
 
@@ -100,8 +99,6 @@ module SmsLogparser
100
99
 
101
100
  private
102
101
 
103
-
104
-
105
102
  def select_entries(last_id)
106
103
  client.query("SELECT * FROM SystemEvents\
107
104
  WHERE `FromHost` like '#{@host_filter}'\
@@ -1,3 +1,3 @@
1
1
  module SmsLogparser
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms-logparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - niwo