sqewer 5.0.2 → 5.0.3
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 +4 -4
- data/lib/sqewer/extensions/appsignal_wrapper.rb +60 -12
- data/lib/sqewer/version.rb +1 -1
- data/sqewer.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46d6379551635abf688acf36eae180bf893cd1d1
|
4
|
+
data.tar.gz: 1b72a67a522b77932306175616e7e4ca875e480d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41b592290fa5616d61f5a2ca30a3a43e513ed603785426902d9677cb4406c4c08dd3db052aa3c22fb34bd6775443e89e12fab7ceacc2ccace5a65bd83c0a34bb
|
7
|
+
data.tar.gz: 066c8923a4db8070804c322335134af46f61426e84fc000a04712c43a9fc60b7ffff6d55064315dbd7fc0b11d83aded4fed5a07b9512838fa474dd6d55a29e10
|
@@ -4,25 +4,73 @@ module Sqewer
|
|
4
4
|
# to Appsignal and to monitor performance. Will only activate
|
5
5
|
# if the Appsignal gem is loaded within the current process and active.
|
6
6
|
class AppsignalWrapper
|
7
|
-
|
7
|
+
def self.new
|
8
|
+
if defined?(Appsignal)
|
9
|
+
super
|
10
|
+
else
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Acts as a replacement for Appsignal::GenericRequest
|
16
|
+
class FakeRequest < Struct.new(:params)
|
17
|
+
def initialize; super({}); end
|
18
|
+
def env; {params: self.params}; end
|
19
|
+
end
|
20
|
+
|
8
21
|
def around_deserialization(serializer, msg_id, msg_payload)
|
9
|
-
return yield unless
|
22
|
+
return yield unless Appsignal.active?
|
23
|
+
|
24
|
+
# This creates a transaction, but also sets it as the Appsignal.current_transaction
|
25
|
+
# which is a thread-local variable. We DO share this middleware between threads,
|
26
|
+
# but since the object lives in thread locals it should be fine.
|
27
|
+
transaction = Appsignal::Transaction.create(
|
28
|
+
SecureRandom.uuid,
|
29
|
+
namespace = Appsignal::Transaction::BACKGROUND_JOB,
|
30
|
+
request = FakeRequest.new)
|
31
|
+
|
32
|
+
transaction.set_action('%s#%s' % [serializer.class, 'unserialize'])
|
33
|
+
transaction.request.params = {:sqs_message_body => msg_payload.to_s}
|
34
|
+
transaction.set_http_or_background_queue_start
|
10
35
|
|
11
|
-
|
12
|
-
|
13
|
-
|
36
|
+
job_unserialized = yield
|
37
|
+
|
38
|
+
if !job_unserialized
|
39
|
+
# If the job is nil or falsy, we skip the execution. In that case we finish the transaction.
|
40
|
+
Appsignal::Transaction.complete_current!
|
41
|
+
else
|
42
|
+
# If not, then the job will be executed - keep the transaction open for execution block
|
43
|
+
# that comes next. Hacky but should work.
|
44
|
+
set_transaction_details_from_job(transaction, job_unserialized)
|
45
|
+
end
|
46
|
+
return job_unserialized
|
47
|
+
rescue Exception => e
|
48
|
+
if transaction
|
49
|
+
# If an exception is raised, raise it through and also set it as the Appsignal exception
|
50
|
+
# and commit the transaction.
|
51
|
+
transaction.set_error(e)
|
52
|
+
Appsignal::Transaction.complete_current!
|
14
53
|
end
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_transaction_details_from_job(transaction, job)
|
58
|
+
transaction.set_action('%s#%s' % [job.class.to_s, 'run'])
|
59
|
+
job_params = job.respond_to?(:to_h) ? job.to_h : {}
|
60
|
+
transaction.request.params = job_params
|
15
61
|
end
|
16
62
|
|
17
63
|
# Run the job with Appsignal monitoring.
|
18
64
|
def around_execution(job, context)
|
19
|
-
return yield unless
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
65
|
+
return yield unless Appsignal.active?
|
66
|
+
transaction = Appsignal::Transaction.current
|
67
|
+
set_transaction_details_from_job(transaction, job)
|
68
|
+
yield
|
69
|
+
rescue Exception => e
|
70
|
+
transaction.set_error(e) if transaction
|
71
|
+
raise e
|
72
|
+
ensure
|
73
|
+
Appsignal::Transaction.complete_current! if transaction
|
26
74
|
end
|
27
75
|
end
|
28
76
|
end
|
data/lib/sqewer/version.rb
CHANGED
data/sqewer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sqewer 5.0.
|
5
|
+
# stub: sqewer 5.0.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "sqewer"
|
9
|
-
s.version = "5.0.
|
9
|
+
s.version = "5.0.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Julik Tarkhanov"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-09-06"
|
15
15
|
s.description = "Process jobs from SQS"
|
16
16
|
s.email = "me@julik.nl"
|
17
17
|
s.executables = ["sqewer", "sqewer_rails"]
|
@@ -66,7 +66,7 @@ Gem::Specification.new do |s|
|
|
66
66
|
]
|
67
67
|
s.homepage = "https://gitlab.wetransfer.net/julik/sqewer"
|
68
68
|
s.licenses = ["MIT"]
|
69
|
-
s.rubygems_version = "2.
|
69
|
+
s.rubygems_version = "2.5.1"
|
70
70
|
s.summary = "A full-featured library for all them worker needs"
|
71
71
|
|
72
72
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -321,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
321
321
|
version: '0'
|
322
322
|
requirements: []
|
323
323
|
rubyforge_project:
|
324
|
-
rubygems_version: 2.
|
324
|
+
rubygems_version: 2.5.1
|
325
325
|
signing_key:
|
326
326
|
specification_version: 4
|
327
327
|
summary: A full-featured library for all them worker needs
|