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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bcafda35a29dbc6cb71004f638807b9634658e3eb50cd13f9ebd4274709f03c
4
- data.tar.gz: 6a6a0e43df2db48f77525ac3ceae7bb26b36cd300becee484b65b14caec3c703
3
+ metadata.gz: d04fb7e6db54d4ed074bd176cd6a966f74ad964889c3970c542d921a1d605936
4
+ data.tar.gz: 3c3612c4dfb226a3155b0192c08e133b4610023f490f051e4cd12852df55ba45
5
5
  SHA512:
6
- metadata.gz: 799d3d7aa098fe1775a7ec0e36d210ae25713ccb96c2ab5bd8962298097b7754fb5805f4c99267111aabe19f20caf47e64671806410ffd2af5c11a757121e9a1
7
- data.tar.gz: ecef09781a6b2833d30c6e8c1ee2dcf3d32c3a500df0f1b1cab60e4cf8490eeda1b294a77263ffdc9039adec10740b68396e7d292542e75e245a405f3ec59ea0
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-232-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
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 = false
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
- # enforce after contracts in a separate thread to ensure that any perform related behavior
26
- # defined in ContractablePrepends will finish executing before we invoke contract.enforce!
27
- Thread.new do
28
- sleep 0
29
- synchronize do
30
- contracts.select(&:after?).each do |contract|
31
- contract.enforce! self unless halted
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JobContracts
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job_contracts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins