activejob-google_cloud_pubsub 0.3.0 → 0.4.0

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: 4cd2666c082bf65b5b43a727217f8eafaf97ad54
4
- data.tar.gz: 63c2c8bf57004c1316d6b74afe0c067a6a7c7f9e
3
+ metadata.gz: 7e1151a90370ecf792eae87e6daf9fd28e985de3
4
+ data.tar.gz: 50b07a891b460d56c44fa1e60ed08b31ddfdd354
5
5
  SHA512:
6
- metadata.gz: c05fd361f9da5456c4a5dfc0efd75cd40b18d4bd2af9c15980c4d7aaec96dd6cc695680b01b29d350fefaf174d8264226080c3adfe7314ed0c282c4e27b7ccd4
7
- data.tar.gz: 04643c9cdbc51a4ea8d371f062d4d5f2d5dc5728f0e238ac650267d2e2411ea73bc030115ca92dc93c1772830ae070eaa5ca774a5f8fde5cc202e964164608da
6
+ metadata.gz: 32504d3cd91e414cd6df30b90c7c5b16035a1bda30f2dfe48540adb22ba377fdfea0d867347c793fd2ed717f7e1e224cd9afd68cd3a9649ab7ca63b2bdf30e01
7
+ data.tar.gz: 4f249b0da43e0212f5ec16ed3df3c31eefdad9fa91045b0c84938fb6ab1fba0c3ba6ae16a4c9a8ef48b39e1f90fbab9af60f7f20270a6bc777bacd3317ccb572
data/README.md CHANGED
@@ -69,7 +69,7 @@ Rails.application.config.active_job.queue_adapter = ActiveJob::GoogleCloudPubsub
69
69
  )
70
70
  ```
71
71
 
72
- Please see [`Google::Cloud::Pubsub.new`](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/cloud/pubsub?method=new-class) for details.
72
+ Please see [`Google::Cloud::Pubsub.new`](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/master/google/cloud/pubsub?method=new-class) for details.
73
73
 
74
74
  ### Worker
75
75
 
@@ -39,4 +39,8 @@ require opts[:require] if opts[:require]
39
39
 
40
40
  pubsub = Google::Cloud::Pubsub.new(pubsub_args)
41
41
 
42
- ActiveJob::GoogleCloudPubsub::Worker.new(pubsub: pubsub, **worker_args).run
42
+ begin
43
+ ActiveJob::GoogleCloudPubsub::Worker.new(pubsub: pubsub, **worker_args).run
44
+ rescue Interrupt
45
+ exit
46
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module GoogleCloudPubsub
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -23,6 +23,8 @@ module ActiveJob
23
23
  pool = Concurrent::ThreadPoolExecutor.new(min_threads: @min_threads, max_threads: @max_threads, max_queue: -1)
24
24
 
25
25
  @pubsub.subscription_for(@queue_name).listen do |message|
26
+ logger.info "Message(#{message.message_id}) was received."
27
+
26
28
  begin
27
29
  Concurrent::Promise.execute(args: message, executor: pool) {|msg|
28
30
  process msg
@@ -31,6 +33,8 @@ module ActiveJob
31
33
  }
32
34
  rescue Concurrent::RejectedExecutionError
33
35
  message.delay! 10.seconds.to_i
36
+
37
+ logger.info "Message(#{message.message_id}) was rescheduled after 10 seconds because the thread pool is full."
34
38
  end
35
39
  end
36
40
  end
@@ -45,12 +49,17 @@ module ActiveJob
45
49
 
46
50
  def process(message)
47
51
  if timestamp = message.attributes['timestamp']
48
- ts = Time.at(timestamp.to_f)
52
+ ts = Time.at(timestamp.to_f)
53
+ now = Time.now
49
54
 
50
- if ts >= Time.now
55
+ if ts <= now
51
56
  _process message
52
57
  else
53
- message.delay! [(ts - Time.now).ceil, MAX_DEADLINE.to_i].min
58
+ deadline = [(ts - now).to_f.ceil, MAX_DEADLINE.to_i].min
59
+
60
+ message.delay! deadline
61
+
62
+ logger.info "Message(#{message.message_id}) was rescheduled after #{deadline} seconds because the timestamp is #{ts}."
54
63
  end
55
64
  else
56
65
  _process message
@@ -84,6 +93,8 @@ module ActiveJob
84
93
 
85
94
  if succeeded || failed
86
95
  message.acknowledge!
96
+
97
+ logger.info "Message(#{message.message_id}) was acknowledged."
87
98
  else
88
99
  # terminated from outside
89
100
  message.delay! 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-google_cloud_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima