magellan-gcs-proxy 0.1.3 → 0.1.4

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: f274888037621b3123477b9770fe6a47aad3261f
4
- data.tar.gz: a63901a3c16ee906bdfaabbef597abedfc959c36
3
+ metadata.gz: 50724872f81d7d6de7c7803628cd766428150f5d
4
+ data.tar.gz: bc1b1ed15f3239206268f2596b9769aa22cf683f
5
5
  SHA512:
6
- metadata.gz: 5e9f4f0c29a3aa5537e717693daf8c5ec65ae9a228454a79c14e98cbbd0d0e6371388ecfa325b18215ec3f652fb46d4b597fa8fb8e37baf5b8aeb598409d3f4f
7
- data.tar.gz: c640f5d0e52f2a8c27b96a8e4a72f707ee37561df9a956a75087098fc926d6704e7fc960de24a7cc0ce7335d97a966c8db6e52e00b4f8a461426db4cf6670e98
6
+ metadata.gz: ae86f4f6bd8b441cbc11fdd21ffa580cacbb81676d8f092b196ff961ad3924798c7d767d2c7a31e993d6b0ce67fbb6ebde99a5597bc13990c547f23158dbb40e
7
+ data.tar.gz: da279b3209b1b16931a870e260c74de94a2ecc6315ecf111b7774cdc5b3d101c73a97704e9d77a6f888bda517b591ac84050610bc87fd76f64ad64a92e315a8f
@@ -76,7 +76,7 @@ GEM
76
76
  logging (2.1.0)
77
77
  little-plugger (~> 1.1)
78
78
  multi_json (~> 1.10)
79
- magellan-gcs-proxy (0.1.3)
79
+ magellan-gcs-proxy (0.1.4)
80
80
  dotenv
81
81
  google-cloud-logging
82
82
  google-cloud-pubsub
@@ -17,9 +17,9 @@ sustainer:
17
17
  # specified by BLOCKS_BATCH_PUBSUB_SUBSCRIPTION
18
18
  # You can check ACK_DEADLINE by `gcloud beta pubsub subscriptions list`
19
19
  # ACK_DEADLINE is set by `--ack-deadline` option for `gcloud beta pubsub subscriptions create`.
20
- delay: 600
20
+ delay: <%= ENV['BLOCKS_BATCH_SUSTAINER_DELAY'] || 600 %>
21
21
 
22
22
  # interval
23
23
  # The interval to send delay message. It must be lower than delay
24
24
  # Default: 90% of delay
25
- interval: 540
25
+ interval: <%= ENV['BLOCKS_BATCH_SUSTAINER_INTERVAL'] || 540 %>
@@ -37,28 +37,47 @@ module Magellan
37
37
  end
38
38
 
39
39
  def run
40
+ reset_next_limit
40
41
  loop do
41
42
  debug("is sleeping #{interval} sec.")
42
- unless wait_while_processing(interval)
43
+ unless wait_while_processing
43
44
  debug('is stopping.')
44
45
  break
45
46
  end
46
- debug("is sending delay!(#{delay})")
47
- message.delay! delay
48
- debug("sent delay!(#{delay}) successfully")
47
+ send_delay
48
+ reset_next_limit
49
49
  end
50
50
  debug('stopped.')
51
51
  rescue => e
52
52
  logger.error(e)
53
53
  end
54
54
 
55
+ attr_reader :next_limit, :next_deadline
56
+ def reset_next_limit
57
+ now = Time.now.to_f
58
+ @next_limit = now + interval
59
+ @next_deadline = now + delay
60
+ end
61
+
62
+ def send_delay
63
+ debug("is sending delay!(#{delay})")
64
+ message.delay! delay
65
+ debug("sent delay!(#{delay}) successfully")
66
+ rescue Google::Cloud::UnavailableError => e
67
+ if Time.now.to_f < next_deadline
68
+ sleep(1) # retry interval
69
+ debug("is retrying to send delay! cause of [#{e.class.name}] #{e.message}")
70
+ retry
71
+ end
72
+ raise e
73
+ end
74
+
55
75
  def debug(msg)
56
76
  logger.debug("#{self.class.name} #{msg}")
57
77
  end
58
78
 
59
- def wait_while_processing(seconds)
60
- limit = Time.now.to_f + seconds
61
- while Time.now.to_f < limit
79
+ def wait_while_processing
80
+ while Time.now.to_f < next_limit
62
81
  return false unless Thread.current[:processing_message]
63
82
  sleep(0.1)
64
83
  end
@@ -1,7 +1,7 @@
1
1
  module Magellan
2
2
  module Gcs
3
3
  module Proxy
4
- VERSION = '0.1.3'.freeze
4
+ VERSION = '0.1.4'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-gcs-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv