mongrel_upload_progress 0.2 → 0.2.1
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/Rakefile +1 -1
- data/lib/mongrel_upload_progress/init.rb +18 -26
- metadata +4 -3
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
|
|
15
15
|
desc "Does a full compile, test run"
|
16
16
|
task :default => [:test, :package]
|
17
17
|
|
18
|
-
version="0.2"
|
18
|
+
version="0.2.1"
|
19
19
|
name="mongrel_upload_progress"
|
20
20
|
|
21
21
|
setup_gem(name, version) do |spec|
|
@@ -5,7 +5,7 @@ class Upload < GemPlugin::Plugin "/handlers"
|
|
5
5
|
include Mongrel::HttpHandlerPlugin
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
|
-
@path_info = options[:path_info]
|
8
|
+
@path_info = Array(options[:path_info])
|
9
9
|
@frequency = options[:frequency] || 3
|
10
10
|
@request_notify = true
|
11
11
|
if options[:drb]
|
@@ -32,19 +32,15 @@ class Upload < GemPlugin::Plugin "/handlers"
|
|
32
32
|
|
33
33
|
private
|
34
34
|
def upload_notify(action, params, *args)
|
35
|
-
return unless params['PATH_INFO']
|
35
|
+
return unless @path_info.include?(params['PATH_INFO']) &&
|
36
36
|
params[Mongrel::Const::REQUEST_METHOD] == 'POST' &&
|
37
37
|
upload_id = Mongrel::HttpRequest.query_parse(params['QUERY_STRING'])['upload_id']
|
38
38
|
if action == :mark
|
39
|
-
last_checked_time =
|
39
|
+
last_checked_time = Mongrel::Uploads.last_checked(upload_id)
|
40
40
|
return unless last_checked_time && Time.now - last_checked_time > @frequency
|
41
41
|
end
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def checked_var(key)
|
47
|
-
key && "@checked_#{key}"
|
42
|
+
Mongrel::Uploads.send(action, upload_id, *args)
|
43
|
+
Mongrel::Uploads.update_checked_time(upload_id) unless action == :finish
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
@@ -57,42 +53,38 @@ class Mongrel::UploadProgress
|
|
57
53
|
end
|
58
54
|
|
59
55
|
def check(upid)
|
60
|
-
|
61
|
-
|
56
|
+
@counters[upid].last rescue nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def last_checked(upid)
|
60
|
+
@counters[upid].first rescue nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def update_checked_time(upid)
|
64
|
+
@guard.synchronize { @counters[upid][0] = Time.now }
|
62
65
|
end
|
63
66
|
|
64
67
|
def add(upid, size)
|
65
68
|
@guard.synchronize do
|
66
|
-
@counters[upid] = Time.now
|
67
|
-
instance_variable_set(upload_var(upid), {:size => size, :received => 0})
|
69
|
+
@counters[upid] = [Time.now, {:size => size, :received => 0}]
|
68
70
|
puts "#{upid}: Added" if @debug
|
69
71
|
end
|
70
|
-
true
|
71
|
-
rescue NameError # bad upid instance var
|
72
|
-
puts $!.message
|
73
|
-
@guard.synchronize { @counters[upid] = nil }
|
74
72
|
end
|
75
73
|
|
76
74
|
def mark(upid, len)
|
75
|
+
return unless status = check(upid)
|
77
76
|
puts "#{upid}: Marking" if @debug
|
78
|
-
status =
|
79
|
-
status[:received] = status[:size] - len if status
|
77
|
+
@guard.synchronize { status[:received] = status[:size] - len }
|
80
78
|
end
|
81
79
|
|
82
80
|
def finish(upid)
|
83
81
|
@guard.synchronize do
|
84
82
|
puts "#{upid}: Finished" if @debug
|
85
|
-
|
83
|
+
@counters.delete(upid)
|
86
84
|
end
|
87
|
-
true
|
88
85
|
end
|
89
86
|
|
90
87
|
def list
|
91
88
|
@counters.keys.sort
|
92
89
|
end
|
93
|
-
|
94
|
-
private
|
95
|
-
def upload_var(key)
|
96
|
-
key && "@upload_#{key}"
|
97
|
-
end
|
98
90
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: mongrel_upload_progress
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version:
|
7
|
-
date:
|
6
|
+
version: 0.2.1
|
7
|
+
date: 2007-01-19 00:00:00 -08:00
|
8
8
|
summary: The mongrel_upload_progress GemPlugin
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
25
|
platform: ruby
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
|
+
post_install_message:
|
28
29
|
authors:
|
29
30
|
- Nobody
|
30
31
|
files:
|