activejob-google_cloud_pubsub 0.6.0 → 0.7.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: da9fc1a9899e01a539b7915f3048fe431b2318ec
4
- data.tar.gz: 33fc32d0c44ebe6268f5cc4ce758197e90270b62
3
+ metadata.gz: db8cb5dcd87c4c044f590ff7159aeae92b9005fe
4
+ data.tar.gz: af83887bfe5e38ee312dd88290615a81448c0a0c
5
5
  SHA512:
6
- metadata.gz: 3cea59188f9bc8c735b8d78091fa604eb37812e063c5974b6f41fa67484ef9b684fe1e3a7a2e5e856c051d98e979901a80c2f9c7a0f4c1f9afa1a401af2e6425
7
- data.tar.gz: 6d7695efa2eacc5c7b32ec3327fb1ea3d7879cc5ea2155367add6e26ce0b0af08ea2c4453a607d1bf802e819a5b306c14ede4145e341847d3a5ab556f783b473
6
+ metadata.gz: a6ec0ba0e29951b8ee8678e07b67589612ae97568c553ed2d107273ff51902c071afd5671038a948c637cf0d97b24b4694901c8b65a4fb2b965f65a0a3316ee9
7
+ data.tar.gz: 1c7adfbc95a95a3b46528ca3b9aefe26ab536213b195a4b8ebea8b588c8fe165fac5c09527e13cd21cf263f3a857328c224c12579813bf07eb329fafefef6e89
data/README.md CHANGED
@@ -66,8 +66,8 @@ Rails.application.config.active_job.queue_adapter = ActiveJob::GoogleCloudPubsub
66
66
  logger: Rails.logger,
67
67
 
68
68
  pubsub: Google::Cloud::Pubsub.new(
69
- project: 'MY-PROJECT-ID',
70
- keyfile: 'path/to/keyfile.json'
69
+ project_id: 'MY-PROJECT-ID',
70
+ credentials: 'path/to/keyfile.json'
71
71
  )
72
72
  )
73
73
  ```
@@ -120,7 +120,7 @@ Maximum number of worker threads.
120
120
 
121
121
  Default: number of logical cores
122
122
 
123
- #### `--project=PROJECT_ID`, `--keyfile=PATH`
123
+ #### `--project_id=PROJECT_ID`, `--credentials=KEYFILE_PATH`
124
124
 
125
125
  Credentials of Google Cloud Platform. Please see [the document](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/AUTHENTICATION.md) for details.
126
126
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'activejob'
24
24
  spec.add_runtime_dependency 'activesupport'
25
25
  spec.add_runtime_dependency 'concurrent-ruby'
26
- spec.add_runtime_dependency 'google-cloud-pubsub', '~> 0.26.0'
26
+ spec.add_runtime_dependency 'google-cloud-pubsub', '>= 0.27.0'
27
27
 
28
28
  spec.add_development_dependency 'bundler'
29
29
  spec.add_development_dependency 'rake'
@@ -16,6 +16,22 @@ module ActiveJob
16
16
  subscription(name) || topic_for(queue_name).subscribe(name)
17
17
  end
18
18
  end
19
+
20
+ refine Google::Cloud::Pubsub::ReceivedMessage do
21
+ def scheduled_at
22
+ return nil unless timestamp = attributes['timestamp']
23
+
24
+ Time.at(timestamp.to_f)
25
+ end
26
+
27
+ def remaining_time_to_schedule
28
+ scheduled_at ? [(scheduled_at - Time.now).to_f.ceil, 0].max : 0
29
+ end
30
+
31
+ def time_to_process?
32
+ remaining_time_to_schedule.zero?
33
+ end
34
+ end
19
35
  end
20
36
  end
21
37
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module GoogleCloudPubsub
3
- VERSION = '0.6.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
@@ -24,12 +24,12 @@ module ActiveJob
24
24
  def run
25
25
  pool = Concurrent::ThreadPoolExecutor.new(min_threads: @min_threads, max_threads: @max_threads, max_queue: -1)
26
26
 
27
- @pubsub.subscription_for(@queue_name).listen do |message|
27
+ @pubsub.subscription_for(@queue_name).listen {|message|
28
28
  @logger&.info "Message(#{message.message_id}) was received."
29
29
 
30
30
  begin
31
31
  Concurrent::Promise.execute(args: message, executor: pool) {|msg|
32
- process msg
32
+ process_or_delay msg
33
33
  }.rescue {|e|
34
34
  @logger&.error e
35
35
  }
@@ -42,7 +42,7 @@ module ActiveJob
42
42
  @logger&.error e
43
43
  }
44
44
  end
45
- end
45
+ }.start
46
46
  end
47
47
 
48
48
  def ensure_subscription
@@ -53,26 +53,19 @@ module ActiveJob
53
53
 
54
54
  private
55
55
 
56
- def process(message)
57
- if timestamp = message.attributes['timestamp']
58
- ts = Time.at(timestamp.to_f)
59
- now = Time.now
60
-
61
- if ts <= now
62
- _process message
63
- else
64
- deadline = [(ts - now).to_f.ceil, MAX_DEADLINE.to_i].min
56
+ def process_or_delay(message)
57
+ if message.time_to_process?
58
+ process message
59
+ else
60
+ deadline = [message.remaining_time_to_schedule, MAX_DEADLINE.to_i].min
65
61
 
66
- message.delay! deadline
62
+ message.delay! deadline
67
63
 
68
- @logger&.info "Message(#{message.message_id}) was rescheduled after #{deadline} seconds because the timestamp is #{ts}."
69
- end
70
- else
71
- _process message
64
+ @logger&.info "Message(#{message.message_id}) was scheduled at #{message.scheduled_at} so it was rescheduled after #{deadline} seconds."
72
65
  end
73
66
  end
74
67
 
75
- def _process(message)
68
+ def process(message)
76
69
  timer_opts = {
77
70
  execution_interval: MAX_DEADLINE - 10.seconds,
78
71
  timeout_interval: 5.seconds,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-google_cloud_pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keita Urashima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2017-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: google-cloud-pubsub
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.26.0
61
+ version: 0.27.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.26.0
68
+ version: 0.27.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement