mobilize-base 1.361 → 1.363

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,13 +87,13 @@ require "mobilize-base/handlers/resque"
87
87
  Resque.redis = "127.0.0.1:#{Mobilize::Resque.config['redis_port']}"
88
88
  require 'popen4'
89
89
  require "mobilize-base/jobtracker"
90
- require "mobilize-base/handlers/gdrive"
91
- require "mobilize-base/handlers/gfile"
92
- require "mobilize-base/handlers/gbook"
93
- require "mobilize-base/handlers/gsheet"
90
+ require "mobilize-base/handlers/google/gdrive"
91
+ require "mobilize-base/handlers/google/gfile"
92
+ require "mobilize-base/handlers/google/gbook"
93
+ require "mobilize-base/handlers/google/gsheet"
94
+ require "mobilize-base/handlers/google/gmail"
94
95
  require "mobilize-base/extensions/google_drive/acl"
95
96
  require "mobilize-base/extensions/google_drive/client_login_fetcher"
96
97
  require "mobilize-base/extensions/google_drive/file"
97
98
  require "mobilize-base/extensions/google_drive/worksheet"
98
99
  require "mobilize-base/handlers/gridfs"
99
- require "mobilize-base/handlers/email"
@@ -222,7 +222,8 @@ module GoogleDrive
222
222
  true
223
223
  end
224
224
  else
225
- raise "#{errcnt} errors found in checksum"
225
+ sheet.save
226
+ "#{errcnt} errors found in checksum".oputs
226
227
  end
227
228
  end
228
229
  end
@@ -33,9 +33,12 @@ class String
33
33
  new_str.gsub!(c,"\\#{c}")}
34
34
  new_str
35
35
  end
36
- def gridsafe
36
+ #makes everything alphanumeric
37
+ #except spaces, slashes, and underscores
38
+ #which are made into underscores
39
+ def alphanunderscore
37
40
  str = self
38
- str.downcase.gsub(/[^a-z0-9]/,"")
41
+ str.gsub(/[^A-Za-z0-9_ \/]/,"").gsub(/[ \/]/,"_")
39
42
  end
40
43
  def googlesafe
41
44
  v=self
@@ -1,6 +1,6 @@
1
1
  module Mobilize
2
2
  require 'action_mailer'
3
- class Email < ActionMailer::Base
3
+ class Gmail < ActionMailer::Base
4
4
  ActionMailer::Base.delivery_method = :smtp
5
5
 
6
6
  ActionMailer::Base.smtp_settings = {
@@ -81,9 +81,11 @@ module Mobilize
81
81
 
82
82
  def Gsheet.write_temp(target_path,gdrive_slot,tsv)
83
83
  #find and delete temp sheet, if any
84
- temp_book_title = target_path.gridsafe
84
+ temp_book_title = target_path.downcase.alphanunderscore
85
85
  #create book and sheet
86
86
  temp_book = Gdrive.root(gdrive_slot).create_spreadsheet(temp_book_title)
87
+ #add admin acl so we can look at it if it fails
88
+ temp_book.add_admin_acl
87
89
  rows, cols = tsv.split("\n").ie{|t| [t.length,t.first.split("\t").length]}
88
90
  temp_sheet = temp_book.add_worksheet("temp",rows,cols)
89
91
  #this step has a tendency to fail; if it does,
@@ -21,11 +21,13 @@ module Mobilize
21
21
  if curr_zs != zs
22
22
  Mongoid::GridFs.delete(curr_file.id) if curr_file
23
23
  #create temp file w zstring
24
- temp_file = ::Tempfile.new("#{string}#{Time.now.to_f}".to_md5)
24
+ temp_file = ::Tempfile.new("#{dst_path.downcase.alphanunderscore}_#{Time.now.to_f}")
25
25
  temp_file.print(zs)
26
26
  temp_file.close
27
27
  #put data in file
28
28
  Mongoid::GridFs.put(temp_file.path,:filename=>dst_path)
29
+ #remove temp file
30
+ `rm #{temp_file.path}`
29
31
  end
30
32
  return true
31
33
  end
@@ -35,6 +35,10 @@ module Mobilize
35
35
  Resque.workers(state)
36
36
  end
37
37
 
38
+ def Jobtracker.disabled_methods
39
+ Jobtracker.config['disabled_methods']
40
+ end
41
+
38
42
  def Jobtracker.status
39
43
  args = Jobtracker.get_args
40
44
  return args['status'] if args
@@ -73,10 +77,6 @@ module Mobilize
73
77
  Resque.kill_idle_workers
74
78
  end
75
79
 
76
- def Jobtracker.kill_idle_and_stale_workers
77
- Resque.kill_idle_and_stale_workers
78
- end
79
-
80
80
  def Jobtracker.prep_workers
81
81
  Resque.prep_workers
82
82
  end
@@ -60,7 +60,7 @@ module Mobilize
60
60
  #deliver each email generated
61
61
  notifs.each do |notif|
62
62
  begin
63
- Email.write(notif).deliver
63
+ Gmail.write(notif).deliver
64
64
  rescue
65
65
  #log email on failure
66
66
  Jobtracker.update_status("Failed to deliver #{notif.to_s}")
@@ -82,7 +82,17 @@ module Mobilize
82
82
  users.sort_by{rand}.each do |u|
83
83
  r = u.runner
84
84
  Jobtracker.update_status("Checking #{r.path}")
85
- if r.is_due?
85
+ #check for run_now file
86
+ run_now_dir = "/home/#{u.name}/mobilize/"
87
+ run_now_path = "#{run_now_dir}run_now"
88
+ run_now = if File.exists?(run_now_dir) and File.exists?(run_now_path)
89
+ #delete user's run now file
90
+ `sudo rm -rf #{run_now_path}`
91
+ true
92
+ else
93
+ false
94
+ end
95
+ if r.is_due? or run_now
86
96
  r.enqueue!
87
97
  Jobtracker.update_status("Enqueued #{r.path}")
88
98
  end
@@ -92,29 +102,5 @@ module Mobilize
92
102
  Jobtracker.update_status("told to stop")
93
103
  return true
94
104
  end
95
-
96
- def Jobtracker.deployed_at
97
- #assumes deploy is as of last commit, or as of last deploy time
98
- #as given by the REVISION file in the root folder
99
- deploy_time = begin
100
- %{git log -1 --format="%cd"}.bash
101
- rescue
102
- revision_path = "#{ENV['PWD']}/REVISION"
103
- "touch #{revision_path}".bash unless File.exists?(revision_path)
104
- revision_string = "ls -l #{revision_path}".bash
105
- revision_rows = revision_string.split("\n").map{|lss| lss.strip.split(" ")}
106
- mod_time = revision_rows.map do |lsr|
107
- if lsr.length == 8
108
- #ubuntu
109
- lsr[5..6].join(" ")
110
- elsif lsr.length == 9
111
- #osx
112
- lsr[5..7].join(" ")
113
- end
114
- end.first
115
- mod_time
116
- end.to_s.strip
117
- Time.parse(deploy_time)
118
- end
119
105
  end
120
106
  end
@@ -79,11 +79,10 @@ module Mobilize
79
79
  return false
80
80
  end
81
81
 
82
- #if job contains handlers not loaded by jobtracker, not due
83
- loaded_handlers = Jobtracker.config['extensions'].map{|m| m.split("-").last}
84
- job_handlers = j.stages.map{|s| s.handler}.uniq
82
+ #if job contains methods in disabled_methods, not due
83
+ job_methods = j.stages.map{|s| "#{s.handler}.#{s.call}"}.uniq
85
84
  #base handlers are the ones in mobilize-base/handlers
86
- if (job_handlers - loaded_handlers - Base.handlers).length>0
85
+ if (Jobtracker.disabled_methods & job_methods).length>0
87
86
  return false
88
87
  end
89
88
 
@@ -4,6 +4,7 @@ module Mobilize
4
4
  include Mongoid::Timestamps
5
5
  field :active, type: Boolean
6
6
  field :name, type: String
7
+ field :ssh_public_key, type: String
7
8
  field :last_run, type: Time
8
9
 
9
10
  def User.find_or_create_by_name(name)
@@ -27,22 +28,6 @@ module Mobilize
27
28
  return u.runner.jobs
28
29
  end
29
30
 
30
- def creds(gdrive_slot)
31
- u = self
32
- creds_path = "#{u.runner.path.split("/").first}/creds"
33
- begin
34
- creds_sheet = Gsheet.find_by_path(creds_path,gdrive_slot)
35
- cred_array = creds_sheet.read(u.name).tsv_to_hash_array.map{|h| {h['name']=>{'user'=>h['user'],'password'=>h['password']}}}
36
- result = {}
37
- cred_array.each do |cred|
38
- result[cred.keys.first] = cred.values.first
39
- end
40
- return result
41
- rescue
42
- return {}
43
- end
44
- end
45
-
46
31
  def runner_path
47
32
  u = self
48
33
  prefix = "Runner_"
@@ -26,12 +26,6 @@ namespace :mobilize do
26
26
  require 'mobilize-base'
27
27
  Mobilize::Jobtracker.kill_workers
28
28
  end
29
- desc "Kill idle workers not in sync with repo"
30
- task :kill_idle_and_stale_workers, :env do |t,args|
31
- ENV['MOBILIZE_ENV']=args.env
32
- require 'mobilize-base'
33
- Mobilize::Jobtracker.kill_idle_and_stale_workers
34
- end
35
29
  desc "Kill idle workers"
36
30
  task :kill_idle_workers, :env do |t,args|
37
31
  ENV['MOBILIZE_ENV']=args.env
@@ -70,11 +64,11 @@ namespace :mobilize do
70
64
  require 'mobilize-base'
71
65
  Mobilize::Jobtracker.restart!
72
66
  end
73
- desc "Add a user"
74
- task :add_user, :name, :env do |t,args|
67
+ desc "Add a user and set up local files"
68
+ task :add_base_user, :name, :env do |t,args|
75
69
  ENV['MOBILIZE_ENV']=args.env
76
70
  require 'mobilize-base'
77
- Mobilize::User.find_or_create_by_name(args.name)
71
+ u = Mobilize::User.find_or_create_by_name(args.name)
78
72
  end
79
73
  desc "Enqueue a user's runner"
80
74
  task :enqueue_user, :name, :env do |t,args|
@@ -87,7 +81,7 @@ namespace :mobilize do
87
81
  ENV['MOBILIZE_ENV']=args.env
88
82
  require 'mobilize-base'
89
83
  user,job,stage = args.path.split("/")
90
- Mobilize::Stage.where(path: "Runner_#{user}/jobs/#{job}/#{stage}").first.en
84
+ Mobilize::Stage.where(path: "Runner_#{user}/jobs/#{job}/#{stage}").first.enqueue!
91
85
  end
92
86
  desc "kill all old resque web processes, start new one with resque_web.rb extension file"
93
87
  task :resque_web, :env do |t,args|
@@ -126,7 +120,7 @@ namespace :mobilize do
126
120
  "Mobilize::#{m}".constantize.create_indexes
127
121
  end
128
122
  end
129
- desc "Set up config and log folders and files, populate from samples"
123
+ desc "Set up base config and log folders and files"
130
124
  task :setup_base do
131
125
  config_dir = (ENV['MOBILIZE_CONFIG_DIR'] ||= "config/mobilize/")
132
126
  log_dir = (ENV['MOBILIZE_LOG_DIR'] ||= "log/")
@@ -1,5 +1,5 @@
1
1
  module Mobilize
2
2
  module Base
3
- VERSION = "1.361"
3
+ VERSION = "1.363"
4
4
  end
5
5
  end
@@ -5,15 +5,18 @@ 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
+ disabled_methods: [] #methods for jobs that should be ignored (used for outages)
8
9
  test:
9
10
  cycle_freq: 10 #time between Jobtracker sweeps
10
11
  notification_freq: 3600 #1 hour between failure/timeout notifications
11
12
  runner_read_freq: 300 #5 min between runner reads
12
13
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
13
14
  extensions: [] #additional Mobilize modules to load workers with
15
+ disabled_methods: [] #methods for jobs that should be ignored (used for outages)
14
16
  production:
15
17
  cycle_freq: 10 #time between Jobtracker sweeps
16
18
  notification_freq: 3600 #1 hour between failure/timeout notifications
17
19
  runner_read_freq: 300 #5 min between runner reads
18
20
  max_run_time: 14400 # if a job runs for 4h+, notification will be sent
19
21
  extensions: [] #additional Mobilize modules to load workers with
22
+ disabled_methods: [] #methods for jobs that should be ignored (used for outages)
@@ -89,9 +89,3 @@
89
89
  parent: {completed_at: Time.now.utc - 1.second}
90
90
  completed_at: Time.now.utc
91
91
  expected: false
92
- - name: missing_module
93
- active: true
94
- trigger: once
95
- status: ""
96
- stage1: handler.method source:"source", target:"target"
97
- expected: false
@@ -10,6 +10,8 @@ require 'mobilize-base'
10
10
  $TESTING = true
11
11
  module TestHelper
12
12
  def TestHelper.confirm_expected_jobs(expected_fixture_name,time_limit=600)
13
+ #clear all failures
14
+ ::Resque::Failure.clear
13
15
  jobs = {}
14
16
  jobs['expected'] = TestHelper.load_fixture(expected_fixture_name)
15
17
  jobs['pending'] = jobs['expected'].select{|j| j['confirmed_ats'].length < j['count']}
@@ -27,6 +27,7 @@ class TestUnit < MiniTest::Unit::TestCase
27
27
  end
28
28
  expected = jh['expected']
29
29
  #check if is_due
30
+ puts "checking #{j.name}"
30
31
  assert expected == j.is_due?
31
32
  end
32
33
  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.361'
4
+ version: '1.363'
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-05-31 00:00:00.000000000 Z
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -184,12 +184,12 @@ files:
184
184
  - lib/mobilize-base/extensions/string.rb
185
185
  - lib/mobilize-base/extensions/time.rb
186
186
  - lib/mobilize-base/extensions/yaml.rb
187
- - lib/mobilize-base/handlers/email.rb
188
- - lib/mobilize-base/handlers/gbook.rb
189
- - lib/mobilize-base/handlers/gdrive.rb
190
- - lib/mobilize-base/handlers/gfile.rb
187
+ - lib/mobilize-base/handlers/google/gbook.rb
188
+ - lib/mobilize-base/handlers/google/gdrive.rb
189
+ - lib/mobilize-base/handlers/google/gfile.rb
190
+ - lib/mobilize-base/handlers/google/gmail.rb
191
+ - lib/mobilize-base/handlers/google/gsheet.rb
191
192
  - lib/mobilize-base/handlers/gridfs.rb
192
- - lib/mobilize-base/handlers/gsheet.rb
193
193
  - lib/mobilize-base/handlers/resque.rb
194
194
  - lib/mobilize-base/helpers/job_helper.rb
195
195
  - lib/mobilize-base/helpers/jobtracker_helper.rb
@@ -234,7 +234,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  segments:
236
236
  - 0
237
- hash: 3685016355014440836
237
+ hash: 1540799042957557582
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: 3685016355014440836
246
+ hash: 1540799042957557582
247
247
  requirements: []
248
248
  rubyforge_project: mobilize-base
249
249
  rubygems_version: 1.8.25