blaxter-delayed_job 2.1.6 → 2.1.8
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.
- data/VERSION +1 -1
- data/lib/delayed/job_launcher.rb +8 -3
- data/lib/delayed_job.rb +1 -0
- data/lib/semaphore.rb +54 -0
- metadata +7 -6
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.
|
1
|
+
2.1.8
|
data/lib/delayed/job_launcher.rb
CHANGED
@@ -34,21 +34,25 @@ module Delayed
|
|
34
34
|
def initialize_launcher(max_active_jobs=MAX_ACTIVE_JOBS)
|
35
35
|
@max_active_jobs = max_active_jobs
|
36
36
|
@jobs = {}
|
37
|
-
@
|
37
|
+
@mutex = Mutex.new
|
38
38
|
end
|
39
39
|
|
40
40
|
# Launch the job in a thread and register it. Returns whether the job
|
41
41
|
# has been launched or not.
|
42
42
|
def launch(job)
|
43
43
|
return false unless can_execute job
|
44
|
+
s = Semaphore.new
|
44
45
|
t = Thread.new do
|
46
|
+
s.wait
|
45
47
|
begin
|
46
48
|
job.run_with_lock Job::MAX_RUN_TIME, name
|
47
49
|
ensure
|
48
50
|
unregister_job job
|
51
|
+
job.connection.release_connection rescue nil
|
49
52
|
end
|
50
53
|
end
|
51
54
|
register_job job, t
|
55
|
+
s.signal
|
52
56
|
return true
|
53
57
|
end
|
54
58
|
|
@@ -126,13 +130,14 @@ module Delayed
|
|
126
130
|
end
|
127
131
|
|
128
132
|
def unregister_job(job)
|
129
|
-
@
|
133
|
+
@mutex.synchronize do
|
130
134
|
@jobs.delete get_object(job)
|
135
|
+
log "No jobs right now!" if @jobs.size == 0
|
131
136
|
end
|
132
137
|
end
|
133
138
|
|
134
139
|
def register_job(job, thread)
|
135
|
-
@
|
140
|
+
@mutex.synchronize do
|
136
141
|
@jobs[get_object(job)] = {
|
137
142
|
:thread => thread,
|
138
143
|
:job => job,
|
data/lib/delayed_job.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
autoload :ActiveRecord, 'activerecord'
|
2
2
|
|
3
|
+
require File.dirname(__FILE__) + '/semaphore'
|
3
4
|
require File.dirname(__FILE__) + '/delayed/message_sending'
|
4
5
|
require File.dirname(__FILE__) + '/delayed/performable_method'
|
5
6
|
require File.dirname(__FILE__) + '/delayed/yaml_ext'
|
data/lib/semaphore.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# $Id: semaphore.rb,v 1.2 2003/03/15 20:10:10 fukumoto Exp $
|
3
|
+
#
|
4
|
+
|
5
|
+
class CountingSemaphore
|
6
|
+
|
7
|
+
def initialize(initvalue = 0)
|
8
|
+
@counter = initvalue
|
9
|
+
@waiting_list = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def wait
|
13
|
+
Thread.critical = true
|
14
|
+
if (@counter -= 1) < 0
|
15
|
+
@waiting_list.push(Thread.current)
|
16
|
+
Thread.stop
|
17
|
+
end
|
18
|
+
self
|
19
|
+
ensure
|
20
|
+
Thread.critical = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def signal
|
24
|
+
Thread.critical = true
|
25
|
+
begin
|
26
|
+
if (@counter += 1) <= 0
|
27
|
+
t = @waiting_list.shift
|
28
|
+
t.wakeup if t
|
29
|
+
end
|
30
|
+
rescue ThreadError
|
31
|
+
retry
|
32
|
+
end
|
33
|
+
self
|
34
|
+
ensure
|
35
|
+
Thread.critical = false
|
36
|
+
end
|
37
|
+
|
38
|
+
alias down wait
|
39
|
+
alias up signal
|
40
|
+
alias P wait
|
41
|
+
alias V signal
|
42
|
+
|
43
|
+
def exclusive
|
44
|
+
wait
|
45
|
+
yield
|
46
|
+
ensure
|
47
|
+
signal
|
48
|
+
end
|
49
|
+
|
50
|
+
alias synchronize exclusive
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
Semaphore = CountingSemaphore
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blaxter-delayed_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 8
|
10
|
+
version: 2.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Tobias L\xC3\xBCtke"
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-04-14 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/delayed/worker.rb
|
42
42
|
- lib/delayed/yaml_ext.rb
|
43
43
|
- lib/delayed_job.rb
|
44
|
+
- lib/semaphore.rb
|
44
45
|
- spec/database.rb
|
45
46
|
- spec/delayed_method_spec.rb
|
46
47
|
- spec/job_spec.rb
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
requirements: []
|
79
80
|
|
80
81
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.4.2
|
82
83
|
signing_key:
|
83
84
|
specification_version: 3
|
84
85
|
summary: Database-backed asynchronous priority queue system -- Extracted from Shopify
|