job_contracts 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/job_contracts/concerns/contractable.rb +20 -13
- data/lib/job_contracts/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04fb7e6db54d4ed074bd176cd6a966f74ad964889c3970c542d921a1d605936
|
4
|
+
data.tar.gz: 3c3612c4dfb226a3155b0192c08e133b4610023f490f051e4cd12852df55ba45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b56ddc45288e5b424e1844af3e4cde8d07fffa90a37c4236c8beef2f0654b27b13a760918fef9e338e69c3ffe1da0ea0978b7c195e02048ee3703295cd4f8dda
|
7
|
+
data.tar.gz: b560b5b6d179ca0d35f2b734600c265ec4c96526c18ca1f9df7d4d92a1f20bd7fa72b089a637a0807b416b43af64aeb31d9794d1a41912fcace75812b89b3079
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
[![Lines of Code](http://img.shields.io/badge/lines_of_code-
|
1
|
+
[![Lines of Code](http://img.shields.io/badge/lines_of_code-236-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
2
|
[![Code Quality](https://app.codacy.com/project/badge/Grade/f604d4bc6db0474c802ef51182732488)](https://www.codacy.com/gh/hopsoft/job_contracts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hopsoft/job_contracts&utm_campaign=Badge_Grade)
|
3
3
|
![Tests](https://github.com/hopsoft/job_contracts/actions/workflows/test.yml/badge.svg)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/job_contracts.svg)](https://badge.fury.io/rb/job_contracts)
|
5
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/job_contracts)](https://rubygems.org/gems/job_contracts)
|
5
6
|
[![Follow Hopsoft](https://img.shields.io/twitter/follow/hopsoft?style=social)](https://twitter.com/hopsoft)
|
6
7
|
|
7
8
|
# Job Contracts
|
@@ -15,21 +15,16 @@ module JobContracts
|
|
15
15
|
# fetch sidekiq job/worker metadata on main thread
|
16
16
|
try :sidekiq_job_metadata
|
17
17
|
|
18
|
-
halted =
|
19
|
-
contracts.select(&:before?).each do |contract|
|
20
|
-
contract.enforce! self unless halted
|
21
|
-
halted = true if contract.breached? && contract.halt?
|
22
|
-
end
|
18
|
+
halted = enforce_contracts!(contracts.select(&:before?))
|
23
19
|
super unless halted
|
24
20
|
ensure
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
21
|
+
unless halted
|
22
|
+
# enforce after-contracts in a separate thread to ensure that any perform related behavior
|
23
|
+
# defined in ContractablePrepends will finish executing before we invoke contract.enforce!
|
24
|
+
# important when multiple contracts have been applied
|
25
|
+
Thread.new do
|
26
|
+
sleep 0
|
27
|
+
synchronize { enforce_contracts! contracts.select(&:after?) }
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
@@ -75,5 +70,17 @@ module JobContracts
|
|
75
70
|
def contract_breached!
|
76
71
|
# noop / override in job subclasses
|
77
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def enforce_contracts!(contracts)
|
77
|
+
halted = false
|
78
|
+
contracts.each do |contract|
|
79
|
+
next if halted
|
80
|
+
contract.enforce! self
|
81
|
+
halted ||= contract.breached? && contract.halt?
|
82
|
+
end
|
83
|
+
halted
|
84
|
+
end
|
78
85
|
end
|
79
86
|
end
|