mobilize-base 1.33 → 1.34

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/README.md CHANGED
@@ -278,6 +278,9 @@ The Jobtracker sits on your Resque and does 2 things:
278
278
 
279
279
  Emails are sent using ActionMailer, through the owner Google Drive
280
280
  account.
281
+ * errors are sent to the owner of the job/stage as well as the admin group.
282
+ * errors not specific to a job/stage are sent to the admin group only, as
283
+ given in gdrive.yml
281
284
 
282
285
  To this end, it needs these parameters, for which there is a sample
283
286
  below and in the [lib/samples][git_samples] folder:
@@ -290,24 +293,18 @@ development:
290
293
  runner_read_freq: 300 #5 min between runner reads
291
294
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
292
295
  extensions: [] #additional Mobilize modules to load workers with
293
- admins: #emails to send notifications to
294
- - email: admin@host.com
295
296
  test:
296
297
  cycle_freq: 10 #time between Jobtracker sweeps
297
298
  notification_freq: 3600 #1 hour between failure/timeout notifications
298
299
  runner_read_freq: 300 #5 min between runner reads
299
300
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
300
301
  extensions: [] #additional Mobilize modules to load workers with
301
- admins: #emails to send notifications to
302
- - email: admin@host.com
303
302
  production:
304
303
  cycle_freq: 10 #time between Jobtracker sweeps
305
304
  notification_freq: 3600 #1 hour between failure/timeout notifications
306
305
  runner_read_freq: 300 #5 min between runner reads
307
306
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
308
307
  extensions: [] #additional Mobilize modules to load workers with
309
- admins: #emails to send notifications to
310
- - email: admin@host.com
311
308
  ```
312
309
 
313
310
  <a name='section_Configure_Resque'></a>
@@ -3,42 +3,16 @@ module GoogleDrive
3
3
 
4
4
  def add_worker_acl
5
5
  f = self
6
- return true if f.has_worker_acl?
7
- Mobilize::Gdrive.worker_emails.each do |a|
8
- f.update_acl(a)
9
- end
6
+ email = "#{Mobilize::Gdrive.worker_group_name}@#{Mobilize::Gdrive.domain}"
7
+ f.update_acl(email,"group")
10
8
  end
11
9
 
12
10
  def add_admin_acl
13
11
  f = self
14
- #admin includes workers
15
- return true if f.has_admin_acl?
16
- accounts = (Mobilize::Gdrive.admin_emails + Mobilize::Gdrive.worker_emails).uniq
17
- accounts.each do |email|
18
- f.update_acl(email)
19
- end
20
- end
21
-
22
- def has_admin_acl?
23
- f = self
24
- curr_emails = f.acls.map{|a| a.scope}.compact.sort
25
- admin_emails = (Mobilize::Gdrive.admin_emails + Mobilize::Gdrive.worker_emails).uniq
26
- if curr_emails == admin_emails or (curr_emails & admin_emails) == admin_emails
27
- return true
28
- else
29
- return false
30
- end
31
- end
32
-
33
- def has_worker_acl?
34
- f = self
35
- curr_emails = f.acls.map{|a| a.scope}.compact.sort
36
- worker_emails = Mobilize::Gdrive.worker_emails.sort
37
- if curr_emails == worker_emails or (curr_emails & worker_emails) == worker_emails
38
- return true
39
- else
40
- return false
41
- end
12
+ email = "#{Mobilize::Gdrive.admin_group_name}@#{Mobilize::Gdrive.domain}"
13
+ f.update_acl(email,"group")
14
+ #if adding acl ,must currently add workers as well
15
+ f.add_worker_acl
42
16
  end
43
17
 
44
18
  def read(user_name)
@@ -51,7 +25,7 @@ module GoogleDrive
51
25
  end
52
26
  end
53
27
 
54
- def update_acl(email,role="writer")
28
+ def update_acl(email,scope_type="user",role="writer")
55
29
  f = self
56
30
  #need these flags for HTTP retries
57
31
  #create req_acl hash to add to current acl
@@ -64,16 +38,16 @@ module GoogleDrive
64
38
  if entry.role != role
65
39
  #for whatever reason
66
40
  f.acl.delete(entry)
67
- f.acl.push({:scope_type=>"user",:scope=>email,:role=>role})
41
+ f.acl.push({:scope_type=>scope_type,:scope=>email,:role=>role})
68
42
  end
69
43
  elsif !['reader','writer','owner'].include?(role)
70
44
  raise "Invalid role #{role}"
71
45
  end
72
46
  else
73
47
  begin
74
- f.acl.push({:scope_type=>"user",:scope=>email,:role=>role})
48
+ f.acl.push({:scope_type=>scope_type,:scope=>email,:role=>role})
75
49
  rescue => exc
76
- raise exc unless exc.to_s.index("user already has access")
50
+ raise exc unless exc.to_s.index("already has access")
77
51
  end
78
52
  end
79
53
  return true
@@ -49,10 +49,6 @@ module Mobilize
49
49
  Gdrive.workers.map{|w| [w['name'],Gdrive.domain].join("@")}
50
50
  end
51
51
 
52
- def Gdrive.admin_emails
53
- Gdrive.admins.map{|w| [w['name'],Gdrive.domain].join("@")}
54
- end
55
-
56
52
  #email management - used to make sure not too many emails get used at the same time
57
53
  def Gdrive.slot_worker_by_path(path)
58
54
  working_slots = Mobilize::Resque.jobs.map{|j| begin j['args'][1]['gdrive_slot'];rescue;nil;end}.compact.uniq
@@ -19,13 +19,17 @@ module Mobilize
19
19
  def Resque.workers(state="all")
20
20
  workers = ::Resque.workers.select{|w| w.queues.first == Resque.queue_name}
21
21
  return workers if state == 'all'
22
- working_workers = workers.select{|w| w.job['queue']== Resque.queue_name}
22
+ working_workers = workers.select{|w| w.job['queue'] == Resque.queue_name}
23
23
  return working_workers if state == 'working'
24
24
  idle_workers = workers.select{|w| w.job['queue'].nil?}
25
25
  return idle_workers if state == 'idle'
26
26
  stale_workers = workers.select{|w| Time.parse(w.started) < Jobtracker.deployed_at}
27
27
  return stale_workers if state == 'stale'
28
- timeout_workers = workers.select{|w| w.job['payload'] and w.job['payload']['class']!='Jobtracker' and w.job['run_at'] < (Time.now.utc - Jobtracker.max_run_time)}
28
+ timeout_workers = workers.select do |w|
29
+ w.job['payload'] and
30
+ w.job['payload']['class']!='Jobtracker' and
31
+ w.job['run_at'] < (Time.now.utc - Jobtracker.max_run_time)
32
+ end
29
33
  return timeout_workers if state == 'timeout'
30
34
  raise "invalid state #{state}"
31
35
  end
@@ -115,14 +119,14 @@ module Mobilize
115
119
  s = Stage.where(:path=>stage_path).first
116
120
  if s.params['notify'].to_s=="false"
117
121
  next
118
- elsif s.params['notify'].index("@")
122
+ elsif s.params['notify'].to_s.index("@")
119
123
  s.params['notify']
120
124
  else
121
125
  s.job.runner.user.email
122
126
  end
123
127
  rescue ScriptError, StandardError
124
- #jobs without stages are sent to first admin
125
- Jobtracker.admin_emails.first
128
+ #jobs without stages are sent to admins
129
+ [Gdrive.admin_group_name,Gdrive.domain].join("@")
126
130
  end
127
131
  exc_to_s = f['error']
128
132
  if fjobs[email].nil?
@@ -27,10 +27,6 @@ module Mobilize
27
27
  Jobtracker.config['admins']
28
28
  end
29
29
 
30
- def Jobtracker.admin_emails
31
- Jobtracker.admins.map{|a| a['email'] }
32
- end
33
-
34
30
  def Jobtracker.worker
35
31
  Resque.find_worker_by_path("jobtracker")
36
32
  end
@@ -35,10 +35,12 @@ module Mobilize
35
35
  end
36
36
  end.flatten.join("\n\n")
37
37
  u = User.where(:name=>email.split("@").first).first
38
- runner_dst = Dataset.find_by_url("gsheet://#{u.runner.path}")
39
- n['body'] += "\n\n#{runner_dst.http_url}" if runner_dst and runner_dst.http_url
38
+ if u
39
+ runner_dst = Dataset.find_by_url("gsheet://#{u.runner.path}")
40
+ n['body'] += "\n\n#{runner_dst.http_url}" if runner_dst and runner_dst.http_url
41
+ end
40
42
  n['to'] = email
41
- n['bcc'] = Jobtracker.admin_emails.join(",")
43
+ n['bcc'] = [Gdrive.admin_group_name,Gdrive.domain].join("@")
42
44
  notifs << n
43
45
  end
44
46
  end
@@ -52,7 +54,7 @@ module Mobilize
52
54
  n = {}
53
55
  n['subject'] = "#{lws.length.to_s} max run time jobs"
54
56
  n['body'] = bod
55
- n['to'] = Jobtracker.admin_emails.join(",")
57
+ n['to'] = [Gdrive.admin_group_name,Gdrive.domain].join("@")
56
58
  notifs << n
57
59
  end
58
60
  #deliver each email generated
@@ -101,9 +101,14 @@ module Mobilize
101
101
  return true
102
102
  end
103
103
 
104
+ def worker
105
+ r = self
106
+ Mobilize::Resque.find_worker_by_path(r.path)
107
+ end
108
+
104
109
  def enqueue!
105
110
  r = self
106
- ::Resque::Job.create("mobilize",Runner,r.path,{})
111
+ ::Resque::Job.create("mobilize",Runner,r.path,{}) unless r.worker
107
112
  return true
108
113
  end
109
114
  end
@@ -148,7 +148,7 @@ module Mobilize
148
148
 
149
149
  def enqueue!
150
150
  s = self
151
- ::Resque::Job.create("mobilize",Stage,s.path,{})
151
+ ::Resque::Job.create("mobilize",Stage,s.path,{}) unless s.worker
152
152
  return true
153
153
  end
154
154
 
@@ -1,5 +1,5 @@
1
1
  module Mobilize
2
2
  module Base
3
- VERSION = "1.33"
3
+ VERSION = "1.34"
4
4
  end
5
5
  end
@@ -5,21 +5,15 @@ development:
5
5
  runner_read_freq: 300 #5 min between runner reads
6
6
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
7
7
  extensions: [] #additional Mobilize modules to load workers with
8
- admins: #emails to send notifications to
9
- - email: admin@host.com
10
8
  test:
11
9
  cycle_freq: 10 #time between Jobtracker sweeps
12
10
  notification_freq: 3600 #1 hour between failure/timeout notifications
13
11
  runner_read_freq: 300 #5 min between runner reads
14
12
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
15
13
  extensions: [] #additional Mobilize modules to load workers with
16
- admins: #emails to send notifications to
17
- - email: admin@host.com
18
14
  production:
19
15
  cycle_freq: 10 #time between Jobtracker sweeps
20
16
  notification_freq: 3600 #1 hour between failure/timeout notifications
21
17
  runner_read_freq: 300 #5 min between runner reads
22
18
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
23
19
  extensions: [] #additional Mobilize modules to load workers with
24
- admins: #emails to send notifications to
25
- - email: admin@host.com
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.33'
4
+ version: '1.34'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -229,7 +229,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
229
  version: '0'
230
230
  segments:
231
231
  - 0
232
- hash: -193800591836657576
232
+ hash: -307993879085768039
233
233
  required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  none: false
235
235
  requirements:
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  version: '0'
239
239
  segments:
240
240
  - 0
241
- hash: -193800591836657576
241
+ hash: -307993879085768039
242
242
  requirements: []
243
243
  rubyforge_project: mobilize-base
244
244
  rubygems_version: 1.8.25