ext_batch 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 161f89b793ce8e0c47982974ae4ce6a871ebbb34
4
- data.tar.gz: bafb5ea1e0f452fbc4e69a95e1b67a7a3e90d24e
3
+ metadata.gz: 52aeecd3a82748aa907ad6d5f3ca59df5570b8da
4
+ data.tar.gz: 518adee2c3a7c4375ebb42b0c5eecb8497396c9c
5
5
  SHA512:
6
- metadata.gz: 2803a11495151399f2fc7b50d7a4a22c9a925a5549c892f5489a9d39f45f540d55b1b220c7a41f5ec84bc7097895facc1466c6fabe21f4617c3c2abb30d757ec
7
- data.tar.gz: fcaa5df84a98c00f184a925da462a1a9c567e7582f3775eeacbcc08e054bc8d249d5a11b4fd2de1e21efee44db872246c96ac13c1b52aa069ee88860bcd05117
6
+ metadata.gz: 62639aba2fa865b6c03856195a3009de2485930da664bc47da1a49c2606fba5e29bbba217943f79b966e990ae78816dce7c48f0ebd9178eb123669cad0d47bc8
7
+ data.tar.gz: b4c3aff281e9ee23e0bda9aebf97da56fb9b3216a94f8d532c958b67aad44eec6ea0bd553f5d346fce17c3ec39175a4ca1f0762e25f8ae0347f78c8900f51c6b
data/README.md CHANGED
@@ -5,7 +5,7 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
5
5
  ```explain
6
6
  Extended the ext_logger gem package, services for Ruby batch and Ruby rake.
7
7
  Other extensions see version updates.
8
- 2019-01-20(0.1.0):
8
+ 2019-01-20(0.1.1):
9
9
  dependency: ext_logger ~> v0.2
10
10
 
11
11
 
@@ -39,9 +39,12 @@ class ExtBatch
39
39
  @start_time ||= Time.now
40
40
  @last_time ||= @start_time
41
41
 
42
+
43
+ @pid_flag = true
42
44
  @pid_file = {
43
45
  path: '',
44
- name: ''
46
+ name: '',
47
+ cmd: ''
45
48
  }
46
49
 
47
50
  init(args[0]) if args.size == 1
@@ -93,7 +96,7 @@ class ExtBatch
93
96
  # opt[:show_use_time] = true if opt[:show_use_time] != false
94
97
  message += get_total_time(@start_time) #if opt[:show_use_time]
95
98
 
96
- delete_pid_file
99
+ delete_pid_file if @pid_flag
97
100
  @ext_logger.info message
98
101
  @ext_logger.record_memory('end') if defined?(@ext_logger.record_memory)
99
102
  end
@@ -125,6 +128,7 @@ class ExtBatch
125
128
 
126
129
  # Inheriting ExtLogger instance method: info
127
130
  def exception(e, opt={})
131
+ opt = {} if !opt.is_a?(Hash)
128
132
  opt[:send_mail] ||= SEND_MAIL_NO
129
133
  opt[:status] = LABEL_ERROR
130
134
  content = []
@@ -142,6 +146,7 @@ class ExtBatch
142
146
  # batch: send ok mail
143
147
  def mail_ok(opt={})
144
148
  func_name = "[#{get_instance_name}.#{__method__.to_s}]"
149
+ opt = {} if !opt.is_a?(Hash)
145
150
  opt[:content] ||= ''
146
151
  opt[:status] = LABEL_OK
147
152
  return mail_tips(@log_name, opt)
@@ -150,6 +155,7 @@ class ExtBatch
150
155
  # batch: send error mail
151
156
  def mail_error(opt={})
152
157
  func_name = "[#{get_instance_name}.#{__method__.to_s}]"
158
+ opt = {} if !opt.is_a?(Hash)
153
159
  opt[:content] ||= ''
154
160
  opt[:status] = LABEL_ERROR
155
161
  return mail_tips(@log_name, opt)
@@ -158,6 +164,7 @@ class ExtBatch
158
164
  # batch: send warning mail
159
165
  def mail_warn(opt={})
160
166
  func_name = "[#{get_instance_name}.#{__method__.to_s}]"
167
+ opt = {} if !opt.is_a?(Hash)
161
168
  opt[:content] ||= ''
162
169
  opt[:status] = LABEL_WARN
163
170
  return mail_tips(@log_name, opt)
@@ -176,6 +183,17 @@ class ExtBatch
176
183
  return mail_tips(@log_name, opt)
177
184
  end
178
185
 
186
+ # Set file name for batch process pid
187
+ def set_pid_flag(flag=true)
188
+ flag = true if !flag.is_a?(TrueClass) && !flag.is_a?(FalseClass)
189
+ @pid_flag = flag
190
+ end
191
+
192
+ # Get file name for batch process pid
193
+ def get_pid_file_name
194
+ return @pid_file[:name]
195
+ end
196
+
179
197
  # Set file path for batch process pid
180
198
  def set_pid_file_path(str)
181
199
  @pid_file[:path] = str if str.is_a?(String) && !is_blank?(str)
@@ -306,11 +324,15 @@ class ExtBatch
306
324
  @batch_message += opt[:message]
307
325
  end
308
326
 
309
- @pid_file = {
310
- path: rails_root + '/tmp/batch_pids/', # Prevent duplication after file sharing by multiple servers
311
- name: @task_name
312
- }
313
- create_pid_file
327
+ set_pid_flag(opt[:pid_flag]) if !is_blank?(opt[:pid_flag])
328
+ if @pid_flag
329
+ @pid_file = {
330
+ path: rails_root + '/tmp/batch_pids/', # Prevent duplication after file sharing by multiple servers
331
+ name: @task_name.gsub(':', '#').gsub(' ', '_') + '.pid',
332
+ cmd: @task_name
333
+ }
334
+ create_pid_file
335
+ end
314
336
 
315
337
  message = "(#{rails_env}) #{@task_name} START"
316
338
  @ext_logger.info message
@@ -385,12 +407,13 @@ class ExtBatch
385
407
  def create_pid_file
386
408
  func_name = "[#{get_class_name}:private #{__method__.to_s}]"
387
409
  if !is_blank?(@pid_file[:name]) && !is_blank?(@pid_file[:path])
388
- file_path = File.join(@pid_file[:path], @pid_file[:name].gsub(' ', '_'))
410
+ file_path = File.join(@pid_file[:path], @pid_file[:name])
411
+ @ext_logger.info "#{func_name} pid_file_path: #{file_path}"
389
412
 
390
413
  pid = nil
391
414
  a = ProcTable.ps
392
415
  a.each_with_index do |p, idx|
393
- if p.cmdline.include?(@pid_file[:name])
416
+ if p.cmdline.include?(@pid_file[:cmd])
394
417
  @ext_logger.info "pid:#{p.pid}, cmd:#{p.comm}, cmdline: #{p.cmdline}"
395
418
  pid = p.pid
396
419
  break
@@ -404,7 +427,7 @@ class ExtBatch
404
427
 
405
428
 
406
429
  if pid
407
- @ext_logger.info "#{func_name} #{@pid_file[:name]}.pid:#{pid}, pid_file_path:#{file_path}"
430
+ @ext_logger.info "#{func_name} #{@pid_file[:name]}.pid: #{pid}"
408
431
  mkdir_more(file_path)
409
432
 
410
433
  File.open(file_path, 'w') do |f|
@@ -1,3 +1,3 @@
1
1
  module ExtBatch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,34 +1,17 @@
1
- class BitflyerFxPairWorker
1
+ class ExtBatchMonitor
2
+ require 'ext_batch'
2
3
  include Sidekiq::Worker
3
4
  sidekiq_options :retry => false
4
5
 
5
6
  def perform(*args)
6
- # 这个worker取bitFlyer的FX数据
7
- # 只显示在BTC_JPY的页面
8
- # 只存入redis
9
- logger = TickApi.new_logger(File.basename(__FILE__).gsub('.rb', ''))
7
+ batch_name = File.basename(__FILE__).gsub('.rb', '')
8
+ batch = ExtBatch.new(batch_name)
10
9
  begin
11
- pair_code = 'fx_btc_jpy'
12
- Yml::TICK_API[:pair][pair_code].each do |item|
13
- company = Yml::TICK_API[:company][item]
14
- next if company.blank?
15
10
 
16
- code = company[:code][pair_code]
17
- code = pair_code if code == ''
18
11
 
19
- # 请求api
20
- json = TickApi.get_tick_data(company[:api], code, {logger: logger})
21
- return if json.blank?
22
-
23
- # 保存到缓存
24
- # 数据存入到btc_jpy的key里面用于tick.coffee实时更新
25
- TickApi.save_tick_cache('btc_jpy', item, json, {logger: logger})
26
- # 数据存入到fx_btc_jpy的key里面用于页面刷新
27
- ticks = TickApi.save_tick_cache(pair_code, item, json, {logger: logger})
28
- logger.info "[main]#{pair_code} ### worker done." if !ticks.blank?
29
- end
30
12
  rescue Exception => e
31
- logger.error e.message
13
+ batch.exception e
32
14
  end
15
+ batch.end
33
16
  end
34
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ext_batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby