mobilize-base 1.370 → 1.371

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,14 @@ module Mobilize
43
43
 
44
44
  def Gdrive.workers(email=nil)
45
45
  if email.nil?
46
- Gdrive.config['workers']
46
+ #divide worker array into equal number of parts
47
+ #as there are deploy servers
48
+ servers = Jobtracker.deploy_servers
49
+ workers = Gdrive.config['workers']
50
+ current_server = Jobtracker.current_server || servers.first
51
+ server_i = servers.index(current_server)
52
+ server_workers = workers.in_groups(servers.length,false)[server_i]
53
+ return server_workers
47
54
  else
48
55
  Gdrive.workers.select{|w| [w['name'],Gdrive.domain].join("@") == email}.first
49
56
  end
@@ -74,6 +74,27 @@ module Mobilize
74
74
  return true
75
75
  end
76
76
 
77
+ def Jobtracker.deploy_servers
78
+ servers = begin
79
+ deploy_file_path = "#{Base.root}/config/deploy/#{Base.env}.rb"
80
+ server_line = File.readlines(deploy_file_path).select{|l| l.strip.starts_with?("role ")}.first
81
+ #reject arguments that start w symbols
82
+ server_strings = server_line.split(",")[1..-1].reject{|t| t.strip.starts_with?(":")}
83
+ server_strings.map{|ss| ss.gsub("'","").gsub('"','').strip}
84
+ rescue
85
+ ["127.0.0.1"]
86
+ end
87
+ servers
88
+ end
89
+
90
+ def Jobtracker.current_server
91
+ begin
92
+ Socket.gethostbyname(Socket.gethostname).first
93
+ rescue
94
+ nil
95
+ end
96
+ end
97
+
77
98
  def Jobtracker.perform(id,*args)
78
99
  while Jobtracker.status != 'stopping'
79
100
  users = User.all
@@ -23,13 +23,7 @@ module Mobilize
23
23
  def Runner.perform(id,*args)
24
24
  r = Runner.find_by_path(id)
25
25
  #get gdrive slot for read
26
- gdrive_slot = Gdrive.slot_worker_by_path(r.path)
27
- unless gdrive_slot
28
- r.update_status("no gdrive slot available")
29
- #re-queue so we can wait for slot
30
- r.enqueue!
31
- return nil
32
- end
26
+ gdrive_slot = Gdrive.slot_worker_by_path(r.path) || Gdrive.worker_emails.sort_by{rand}.first
33
27
  r.update_attributes(:started_at=>Time.now.utc)
34
28
  begin
35
29
  #make sure any updates to activity are processed first
@@ -127,7 +121,7 @@ module Mobilize
127
121
  r = self
128
122
  u = r.user
129
123
  resque_server = u.resque_server
130
- current_server = begin;Socket.gethostbyname(Socket.gethostname).first;rescue;nil;end
124
+ current_server = Jobtracker.current_server
131
125
  return true if ['127.0.0.1',current_server].include?(resque_server)
132
126
  end
133
127
 
@@ -33,19 +33,9 @@ module Mobilize
33
33
  #otherwise, localhost
34
34
  def resque_server
35
35
  u = self
36
- deploy_file_path = "#{Base.root}/config/deploy/#{Base.env}.rb"
37
- result = begin
38
- server_line = File.readlines(deploy_file_path).select{|l| l.strip.starts_with?("role ")}.first
39
- #reject arguments that start w symbols
40
- server_strings = server_line.split(",")[1..-1].reject{|t| t.strip.starts_with?(":")}
41
- servers = server_strings.map{|ss| ss.gsub("'","").gsub('"','').strip}
42
- server_i = u.name.to_md5.gsub(/[^0-9]/,'').to_i % servers.length
43
- servers[server_i]
44
- rescue
45
- #default to self if this doesn't work
46
- "127.0.0.1"
47
- end
48
- result
36
+ servers = Jobtracker.deploy_servers
37
+ server_i = u.name.to_md5.gsub(/[^0-9]/,'').to_i % servers.length
38
+ servers[server_i]
49
39
  end
50
40
 
51
41
  def runner_path
@@ -1,5 +1,5 @@
1
1
  module Mobilize
2
2
  module Base
3
- VERSION = "1.370"
3
+ VERSION = "1.371"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobilize-base
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.370'
4
+ version: '1.371'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -234,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  segments:
236
236
  - 0
237
- hash: 2127778661316611093
237
+ hash: -4607436373459673499
238
238
  required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  none: false
240
240
  requirements:
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  version: '0'
244
244
  segments:
245
245
  - 0
246
- hash: 2127778661316611093
246
+ hash: -4607436373459673499
247
247
  requirements: []
248
248
  rubyforge_project: mobilize-base
249
249
  rubygems_version: 1.8.25