magent 0.1.3 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -3
- data/Rakefile +3 -3
- data/lib/magent.rb +3 -1
- data/lib/magent/actor.rb +1 -2
- data/lib/magent/channel.rb +7 -10
- data/lib/magent/generic_channel.rb +18 -39
- data/lib/magent/processor.rb +1 -1
- data/magent.gemspec +9 -6
- metadata +14 -4
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ Simple job queue system based on mongodb
|
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
* fast
|
11
|
+
* fast
|
12
12
|
* simple
|
13
13
|
* scalable
|
14
14
|
|
@@ -18,8 +18,8 @@ see examples/
|
|
18
18
|
|
19
19
|
== REQUIREMENTS:
|
20
20
|
|
21
|
-
* mongodb >= 1.
|
22
|
-
* mongo >= 0.
|
21
|
+
* mongodb >= 1.3
|
22
|
+
* mongo >= 0.18.2 (gem install mongo)
|
23
23
|
|
24
24
|
== INSTALL:
|
25
25
|
|
data/Rakefile
CHANGED
@@ -12,10 +12,10 @@ Hoe.plugin :newgem
|
|
12
12
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
13
|
$hoe = Hoe.spec 'magent' do
|
14
14
|
self.developer 'David Cuadrado', 'krawek@gmail.com'
|
15
|
-
self.post_install_message = '
|
15
|
+
self.post_install_message = ''
|
16
16
|
self.rubyforge_name = self.name
|
17
|
-
self.extra_deps = [['mongo','>= 0.
|
18
|
-
|
17
|
+
self.extra_deps = [['mongo','>= 0.18.2'],
|
18
|
+
['uuidtools', '>= 2.0.0']]
|
19
19
|
end
|
20
20
|
|
21
21
|
require 'newgem/tasks'
|
data/lib/magent.rb
CHANGED
@@ -3,6 +3,8 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
|
4
4
|
require 'mongo'
|
5
5
|
require 'set'
|
6
|
+
require 'uuidtools'
|
7
|
+
|
6
8
|
require 'magent/utils'
|
7
9
|
require 'magent/generic_channel'
|
8
10
|
require 'magent/channel'
|
@@ -11,7 +13,7 @@ require 'magent/actor'
|
|
11
13
|
require 'magent/processor'
|
12
14
|
|
13
15
|
module Magent
|
14
|
-
VERSION = '0.
|
16
|
+
VERSION = '0.2'
|
15
17
|
|
16
18
|
def self.connection
|
17
19
|
@@connection ||= Mongo::Connection.new(nil, nil, :auto_reconnect => true)
|
data/lib/magent/actor.rb
CHANGED
data/lib/magent/channel.rb
CHANGED
@@ -5,27 +5,24 @@ module Magent
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def failed(info)
|
8
|
-
error_collection.save(info.merge({:
|
8
|
+
error_collection.save(info.merge({:_id => generate_uid, :channel => @name, :created_at => Time.now.utc}))
|
9
9
|
end
|
10
10
|
|
11
11
|
def error_count
|
12
|
-
error_collection.
|
12
|
+
error_collection.count()
|
13
13
|
end
|
14
14
|
|
15
15
|
def errors(conds = {})
|
16
16
|
page = conds.delete(:page) || 1
|
17
17
|
per_page = conds.delete(:per_page) || 10
|
18
18
|
|
19
|
-
error_collection.find({
|
19
|
+
error_collection.find({}, {:skip => (page-1)*per_page,
|
20
|
+
:limit => per_page,
|
21
|
+
:sort => [["created_at", -1]]})
|
20
22
|
end
|
21
23
|
|
22
24
|
def remove_error(error_id)
|
23
|
-
|
24
|
-
if error_id.kind_of?(String)
|
25
|
-
object_id = Mongo::ObjectID.from_string(error_id)
|
26
|
-
end
|
27
|
-
|
28
|
-
self.error_collection.remove(:_id => object_id, :channel_id => @name)
|
25
|
+
self.error_collection.remove(:_id => error_id)
|
29
26
|
end
|
30
27
|
|
31
28
|
def retry_error(error)
|
@@ -34,7 +31,7 @@ module Magent
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def error_collection
|
37
|
-
@error_collection ||= Magent.database.collection("errors")
|
34
|
+
@error_collection ||= Magent.database.collection("#{@name}-errors")
|
38
35
|
end
|
39
36
|
end # Channel
|
40
37
|
end
|
@@ -1,64 +1,43 @@
|
|
1
1
|
module Magent
|
2
2
|
class GenericChannel
|
3
|
+
attr_reader :name
|
4
|
+
|
3
5
|
def initialize(name)
|
4
6
|
@name = name
|
5
|
-
|
6
|
-
if !collection.find_one({:_id => @name}, {:fields => [:_id]})
|
7
|
-
collection.save({:_id => @name, :messages => []})
|
8
|
-
end
|
9
7
|
end
|
10
8
|
|
11
9
|
def enqueue(message)
|
12
|
-
collection.
|
10
|
+
collection.save({:_id => generate_uid, :message => message, :priority => 3, :created_at => Time.now.to_i})
|
13
11
|
end
|
14
12
|
|
15
13
|
def message_count
|
16
|
-
|
17
|
-
if channel
|
18
|
-
channel["message_count"] || 0
|
19
|
-
else
|
20
|
-
0
|
21
|
-
end
|
14
|
+
collection.count # TODO: number of processed messages (create a collection for stats)
|
22
15
|
end
|
23
16
|
|
24
17
|
def queue_count
|
25
|
-
|
26
|
-
function queue_count() {
|
27
|
-
var selector = {_id: '#{@name}'};
|
28
|
-
var q = db.channels.findOne(selector, {messages: 1 });
|
29
|
-
return q.messages.length;
|
30
|
-
}
|
31
|
-
@)
|
18
|
+
collection.count
|
32
19
|
end
|
33
20
|
|
34
21
|
def dequeue
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
var q = db.channels.findOne(selector, {messages: 1 });
|
39
|
-
var m = q.messages[0];
|
40
|
-
if(m)
|
41
|
-
db.channels.update(selector, { $pop: { messages : -1 } })
|
42
|
-
return m;
|
43
|
-
}
|
44
|
-
@)
|
22
|
+
if m = self.next_message
|
23
|
+
m["message"]
|
24
|
+
end
|
45
25
|
end
|
46
26
|
|
47
|
-
def
|
48
|
-
|
27
|
+
def next_message
|
28
|
+
Magent.database.command(OrderedHash[:findandmodify, @name,
|
29
|
+
:sort, [{:priority => -1}, {:created_at => 1}],
|
30
|
+
:remove, true
|
31
|
+
])["value"]
|
49
32
|
end
|
50
33
|
|
51
|
-
def
|
52
|
-
@collection ||= Magent.database.collection(
|
34
|
+
def collection
|
35
|
+
@collection ||= Magent.database.collection(@name)
|
53
36
|
end
|
54
37
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
cursor.map {|c| name = c["_id"]; yield name; name }
|
59
|
-
else
|
60
|
-
cursor.map {|c| c["_id"] }
|
61
|
-
end
|
38
|
+
protected
|
39
|
+
def generate_uid
|
40
|
+
UUIDTools::UUID.random_create.hexdigest
|
62
41
|
end
|
63
42
|
end # GenericChannel
|
64
43
|
end
|
data/lib/magent/processor.rb
CHANGED
data/magent.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{magent}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["David Cuadrado"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2010-01-06}
|
10
10
|
s.default_executable = %q{magent}
|
11
11
|
s.description = %q{Simple job queue system based on mongodb}
|
12
12
|
s.email = ["krawek@gmail.com"]
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
|
15
15
|
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "bin/magent", "examples/comm/run.rb", "examples/comm/worker.rb", "examples/error/error.rb", "examples/simple/bot.rb", "examples/stats/stats.rb", "lib/magent.rb", "lib/magent/actor.rb", "lib/magent/channel.rb", "lib/magent/generic_channel.rb", "lib/magent/processor.rb", "lib/magent/push.rb", "lib/magent/utils.rb", "magent.gemspec", "script/console", "test/test_helper.rb", "test/test_magent.rb"]
|
16
16
|
s.homepage = %q{http://github.com/dcu/magent}
|
17
|
-
s.post_install_message = %q{
|
17
|
+
s.post_install_message = %q{}
|
18
18
|
s.rdoc_options = ["--main", "README.rdoc"]
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.rubyforge_project = %q{magent}
|
@@ -27,14 +27,17 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.specification_version = 3
|
28
28
|
|
29
29
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
-
s.add_runtime_dependency(%q<mongo>, [">= 0.
|
30
|
+
s.add_runtime_dependency(%q<mongo>, [">= 0.18.2"])
|
31
|
+
s.add_runtime_dependency(%q<uuidtools>, [">= 2.0.0"])
|
31
32
|
s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
|
32
33
|
else
|
33
|
-
s.add_dependency(%q<mongo>, [">= 0.
|
34
|
+
s.add_dependency(%q<mongo>, [">= 0.18.2"])
|
35
|
+
s.add_dependency(%q<uuidtools>, [">= 2.0.0"])
|
34
36
|
s.add_dependency(%q<hoe>, [">= 2.3.3"])
|
35
37
|
end
|
36
38
|
else
|
37
|
-
s.add_dependency(%q<mongo>, [">= 0.
|
39
|
+
s.add_dependency(%q<mongo>, [">= 0.18.2"])
|
40
|
+
s.add_dependency(%q<uuidtools>, [">= 2.0.0"])
|
38
41
|
s.add_dependency(%q<hoe>, [">= 2.3.3"])
|
39
42
|
end
|
40
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.2"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cuadrado
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-06 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,17 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 0.18.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: uuidtools
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
24
34
|
version:
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: hoe
|
@@ -70,7 +80,7 @@ has_rdoc: true
|
|
70
80
|
homepage: http://github.com/dcu/magent
|
71
81
|
licenses: []
|
72
82
|
|
73
|
-
post_install_message:
|
83
|
+
post_install_message: ""
|
74
84
|
rdoc_options:
|
75
85
|
- --main
|
76
86
|
- README.rdoc
|