conflow 0.4.0 → 0.4.1

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: e4e50a7f447dad66d1522e881c5253e3478a806a38a08478660fc0a831d59a5d
4
- data.tar.gz: ae859355013408d204a12532dc480efdef8933dd70bc37ab87e60a06e17f0612
3
+ metadata.gz: 172b50e6e55599152b9db5caa41bf3c2c12a3ea50211cba7abee58a4087caa78
4
+ data.tar.gz: 73dbbd9b138d9e5dd97e3827f595f80274b51a62aa1da59b39e443c4b190ad54
5
5
  SHA512:
6
- metadata.gz: 6b004258305c37c987b6edee1482ba0e00e2f9e02ca3ef6d5354288de59f7e6f7d8f2c75235cc1a51faf678e8a639459d6cb925f03276a10fc307b86b877a964
7
- data.tar.gz: b9b87d6d3579b7301e19b1e74ff7ff292e06e2df16f1810c4e0a2de6ab537597fb2aa42b9c1da780248161f1e3b8e667cb97be88a80fcfd7268a2afe23ab21f8
6
+ metadata.gz: 67ce640beb104c23a542f3ba8439922a7582c5a4debf7ce444e39137ae6c019b901e529ab1fb8722826a1a554d2d973c791d16aff02883493691d5297cf4b97c
7
+ data.tar.gz: 991a119e2a9bcc11fafe10ce53b53f121e1b5103773a8471ad9c52cbc734c60dc32cade6473564088fdf87e1ab354bb7bd237c61683855da840cf20186824943
@@ -1,3 +1,7 @@
1
+ ## 0.4.1
2
+
3
+ - Prevent enqueing jobs and finishing flow during flow configuration
4
+
1
5
  ## 0.4.0
2
6
 
3
7
  - Removed hooks, added promises. If you were looking only on Changelog, you never even knew about hooks - it can stay that way :)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- conflow (0.4.0)
4
+ conflow (0.4.1)
5
5
  redis (~> 4.0)
6
6
 
7
7
  GEM
@@ -41,6 +41,7 @@ module Conflow
41
41
  has_many :jobs, Conflow::Job
42
42
  field :queued_jobs, :set
43
43
  field :indegree, :sorted_set
44
+ field :lock, :value
44
45
 
45
46
  # Create new flow with given parameters
46
47
  # @param args [Array<Object>] any parameters that will be passed to {#configure} method
@@ -56,13 +57,17 @@ module Conflow
56
57
  # MyFlow.create(id: 320, strict: false)
57
58
  # MyFlow.create(id: 15, strict: true)
58
59
  def self.create(*args)
59
- new.tap { |flow| flow.configure(*args) }
60
+ new.tap do |flow|
61
+ flow.with_lock do
62
+ flow.configure(*args)
63
+ end
64
+ end
60
65
  end
61
66
 
62
67
  # Returns whether or not the flow is finished (all jobs were processed)
63
68
  # @return [Boolean] true if no pending jobs
64
69
  def finished?
65
- queued_jobs.size.zero? && indegree.size.zero?
70
+ lock.value != 1 && queued_jobs.size.zero? && indegree.size.zero?
66
71
  end
67
72
 
68
73
  # @abstract
@@ -71,5 +76,15 @@ module Conflow
71
76
  # @param args [Array<Object>] any arguments needed to start a flow
72
77
  # @see create
73
78
  def configure(*args); end
79
+
80
+ # Lock prevents flow from enqueuing jobs during configuration - it could happen that first job is finished
81
+ # before second is enqueued, therefore "finishing" the flow.
82
+ # @api private
83
+ def with_lock
84
+ self.lock = 1
85
+ yield
86
+ self.lock = 0
87
+ queue_available_jobs
88
+ end
74
89
  end
75
90
  end
@@ -41,6 +41,8 @@ module Conflow
41
41
  private
42
42
 
43
43
  def queue_available_jobs
44
+ return unless lock.value != 1
45
+
44
46
  call_script(Conflow::Redis::QueueJobsScript)&.each do |job_id|
45
47
  queue Conflow::Job.new(job_id)
46
48
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Conflow
4
4
  # Current version of the gem
5
- VERSION = "0.4.0"
5
+ VERSION = "0.4.1"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Begejowicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-21 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis