activejob-google_cloud_pubsub 0.3.0 → 0.4.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: 7e1151a90370ecf792eae87e6daf9fd28e985de3
|
4
|
+
data.tar.gz: 50b07a891b460d56c44fa1e60ed08b31ddfdd354
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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
|
-
|
42
|
+
begin
|
43
|
+
ActiveJob::GoogleCloudPubsub::Worker.new(pubsub: pubsub, **worker_args).run
|
44
|
+
rescue Interrupt
|
45
|
+
exit
|
46
|
+
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
|
52
|
+
ts = Time.at(timestamp.to_f)
|
53
|
+
now = Time.now
|
49
54
|
|
50
|
-
if ts
|
55
|
+
if ts <= now
|
51
56
|
_process message
|
52
57
|
else
|
53
|
-
|
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
|