activejob-google_cloud_pubsub 0.6.0 → 0.7.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8cb5dcd87c4c044f590ff7159aeae92b9005fe
|
4
|
+
data.tar.gz: af83887bfe5e38ee312dd88290615a81448c0a0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
70
|
-
|
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
|
-
#### `--
|
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', '
|
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
|
@@ -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
|
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
|
-
|
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
|
-
|
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
|
57
|
-
if
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
+
message.delay! deadline
|
67
63
|
|
68
|
-
|
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
|
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.
|
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-
|
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.
|
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.
|
68
|
+
version: 0.27.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|