cyclop 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
+ -I lib
1
2
  --color
2
3
  --format documentation
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ cyclop is Copyright © 2011 TalentBox SA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -78,6 +78,10 @@ Usage
78
78
  * Start a worker:
79
79
 
80
80
  cyclop -c config.yml
81
+
82
+ * To get help about the format for config.yml
83
+
84
+ cyclop -h
81
85
 
82
86
  About
83
87
  -----
data/bin/cyclop CHANGED
@@ -58,6 +58,9 @@ else
58
58
  queues: [
59
59
  "email", "cache"
60
60
  ]
61
+ # Limit this worker to job queued by this host
62
+ # use "localhost" to let Cyclop set it to the host running the worker
63
+ limit_to_host: "server1.mydomain.tld"
61
64
  # Load actions in this directory (default to ./actions)
62
65
  actions: "/app/actions"
63
66
  sleep_interval: 0.5 # in seconds
data/cyclop.gemspec CHANGED
@@ -12,8 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.summary = "Job queue with MongoDB"
13
13
  s.description = "Job queue with MongoDB with emphasis on never losing any task even if worker fails hard (segfault)."
14
14
 
15
- s.rubyforge_project = "cyclop"
16
-
17
15
  s.files = `git ls-files`.split("\n")
18
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,3 +1,3 @@
1
1
  module Cyclop
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/cyclop/worker.rb CHANGED
@@ -8,6 +8,8 @@ module Cyclop
8
8
  attr_accessor :sleep_interval
9
9
  # Path to actions directory
10
10
  attr_accessor :actions
11
+ # Options passed to Cyclop.next to get next job
12
+ attr_accessor :job_opts
11
13
 
12
14
  def initialize(config={})
13
15
  raise ArgumentError, 'mongo["database"] is required' unless config["mongo"] && config["mongo"]["database"]
@@ -16,6 +18,11 @@ module Cyclop
16
18
  self.logger = Logger.new(config["log_file"] || $stdout)
17
19
  self.sleep_interval = config["sleep_interval"] || 1
18
20
  self.actions = config["actions"] || "./actions"
21
+ @job_opts = {}
22
+ if config["limit_to_host"]
23
+ @job_opts[:host] = config["limit_to_host"]
24
+ @job_opts[:host] = Cyclop.host if @job_opts[:host]=="localhost"
25
+ end
19
26
  connection = if config["mongo"]["hosts"]
20
27
  Mongo::ReplSetConnection.new(
21
28
  *config["mongo"]["hosts"],
@@ -110,7 +117,7 @@ module Cyclop
110
117
  end
111
118
 
112
119
  def next_job
113
- Cyclop.next *queues
120
+ Cyclop.next *queues, job_opts
114
121
  end
115
122
 
116
123
  def procline(line)
data/lib/cyclop.rb CHANGED
@@ -82,6 +82,7 @@ module Cyclop
82
82
  # Returns a `Cyclop::Job`
83
83
  #
84
84
  def push(opts={})
85
+ opts["created_by"] = opts.delete :host
85
86
  Cyclop::Job.create opts
86
87
  end
87
88
 
@@ -74,5 +74,30 @@ describe Cyclop::Worker do
74
74
  job.attempts.should == 2
75
75
  end
76
76
  end
77
+
78
+ context "limiting to jobs queued by a given host" do
79
+ let(:host) { "test.local" }
80
+ let(:worker) do
81
+ Cyclop::Worker.new({
82
+ "log_file" => File.expand_path("../../../test.log", __FILE__),
83
+ "mongo" => {"database" => "cyclop_test"},
84
+ "actions" => File.expand_path("../../fixtures/actions", __FILE__),
85
+ "limit_to_host" => host,
86
+ })
87
+ end
88
+ it "run only jobs from this host" do
89
+ job = Cyclop.push queue: "slow", job_params: ["tony@starkenterprises.com", :welcome]
90
+ job_local = Cyclop.push queue: "slow", job_params: ["tony@starkenterprises.com", :welcome], host: host
91
+ 2.times do
92
+ t = Thread.new { worker.run }
93
+ sleep 1
94
+ worker.stop
95
+ t.join
96
+ end
97
+ job.reload
98
+ job.attempts.should == 0
99
+ Cyclop::Job.find(job_local._id).should be_nil
100
+ end
101
+ end
77
102
  end
78
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyclop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-06-09 00:00:00.000000000 +02:00
13
+ date: 2011-06-22 00:00:00.000000000 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bson_ext
18
- requirement: &2165985760 !ruby/object:Gem::Requirement
18
+ requirement: &2165763360 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 1.3.1
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2165985760
26
+ version_requirements: *2165763360
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mongo
29
- requirement: &2165985240 !ruby/object:Gem::Requirement
29
+ requirement: &2165762840 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.3.1
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2165985240
37
+ version_requirements: *2165762840
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: posix-spawn
40
- requirement: &2165984760 !ruby/object:Gem::Requirement
40
+ requirement: &2165762360 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 0.3.6
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *2165984760
48
+ version_requirements: *2165762360
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &2165984280 !ruby/object:Gem::Requirement
51
+ requirement: &2165761880 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 0.8.7
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *2165984280
59
+ version_requirements: *2165761880
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rspec
62
- requirement: &2165983800 !ruby/object:Gem::Requirement
62
+ requirement: &2165761380 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 2.6.0
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *2165983800
70
+ version_requirements: *2165761380
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rocco
73
- requirement: &2165983320 !ruby/object:Gem::Requirement
73
+ requirement: &2165760900 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ~>
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: '0.7'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *2165983320
81
+ version_requirements: *2165760900
82
82
  description: Job queue with MongoDB with emphasis on never losing any task even if
83
83
  worker fails hard (segfault).
84
84
  email:
@@ -92,6 +92,7 @@ files:
92
92
  - .gitignore
93
93
  - .rspec
94
94
  - Gemfile
95
+ - LICENSE
95
96
  - README.md
96
97
  - Rakefile
97
98
  - bin/cyclop
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
- rubyforge_project: cyclop
131
+ rubyforge_project:
131
132
  rubygems_version: 1.6.2
132
133
  signing_key:
133
134
  specification_version: 3