mobilize-base 1.294 → 1.295

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -355,22 +355,16 @@ mobilize_base:resque_web task, as detailed in [Start Resque-Web](#section_Start_
355
355
  Mobilize stores cached data in MongoDB Gridfs.
356
356
  It needs the below parameters, which can be found in the [lib/samples][git_samples] folder.
357
357
 
358
- * max_versions - the number of __different__ versions of data to keep
359
- for a given cache. Default is 10. This is meant mostly to allow you to
360
- restore Runners from cache if necessary.
361
358
  * max_compressed_write_size - the amount of compressed data Gridfs will
362
359
  allow. If you try to write more than this, an exception will be thrown.
363
360
 
364
361
  ``` yml
365
362
  ---
366
363
  development:
367
- max_versions: 10 #number of versions of cache to keep in gridfs
368
364
  max_compressed_write_size: 1000000000 #~1GB
369
365
  test:
370
- max_versions: 10 #number of versions of cache to keep in gridfs
371
366
  max_compressed_write_size: 1000000000 #~1GB
372
367
  production:
373
- max_versions: 10 #number of versions of cache to keep in gridfs
374
368
  max_compressed_write_size: 1000000000 #~1GB
375
369
  ```
376
370
 
@@ -11,6 +11,9 @@ class String
11
11
  def opp
12
12
  pp self
13
13
  end
14
+ def to_md5
15
+ Digest::MD5.hexdigest(self)
16
+ end
14
17
  def bash(except=true)
15
18
  str = self
16
19
  pid,stdin,stdout,stderr = Open4.popen4(str)
@@ -10,13 +10,16 @@ module YAML
10
10
  #make sure urls have their colon spaces fixed
11
11
  result_hash={}
12
12
  easy_hash.each do |k,v|
13
- result_hash[k] = if v.class==String
14
- v.gsub(": //","://")
15
- elsif v.class==Array
16
- v.map{|av| av.to_s.gsub(": //","://")}
17
- else
18
- v
19
- end
13
+ #fucking yaml puts spaces in front of the key
14
+ #or something
15
+ strip_k = k.strip
16
+ result_hash[strip_k] = if v.class==String
17
+ v.gsub(": //","://")
18
+ elsif v.class==Array
19
+ v.map{|av| av.to_s.gsub(": //","://")}
20
+ else
21
+ v
22
+ end
20
23
  end
21
24
  return result_hash
22
25
  end
@@ -14,57 +14,44 @@ module Mobilize
14
14
  dst = Dataset.find_by_handler_and_path('gbook',path)
15
15
  if dst and dst.http_url.to_s.length>0
16
16
  book = Gbook.find_by_http_url(dst.http_url,gdrive_slot)
17
- begin
18
- #doesn't count if it's deleted
19
- #or if its name can't be accessed
20
- if book.entry_hash[:deleted]
21
- book = nil
22
- else
23
- return book
24
- end
25
- rescue
26
- #use regular process if book entry hash fails
27
- book = nil
17
+ if book
18
+ return book
19
+ else
20
+ raise "Could not find book #{path} with url #{dst.http_url}, please check dataset"
28
21
  end
29
22
  end
23
+ #try to find books by title
30
24
  books = Gbook.find_all_by_path(path,gdrive_slot)
31
- dst = Dataset.find_or_create_by_handler_and_path('gbook',path)
32
- book = nil
33
- if books.length>1 and dst.http_url.to_s.length>0
34
- #some idiot process or malicious user created a duplicate book.
35
- #Fix by deleting all but the one with dst entry's key
36
- dkey = dst.http_url.split("key=").last
37
- books.each do |b|
38
- bkey = b.resource_id.split(":").last
39
- if bkey == dkey
40
- book = b
41
- dst.update_attributes(:http_url=>book.human_url)
42
- else
43
- #delete the invalid book
44
- b.delete
45
- ("Deleted duplicate book #{path}").oputs
46
- end
47
- end
48
- else
49
- #If it's a new dst or if there are multiple books
50
- #take the first
51
- book = books.first
52
- dst.update_attributes(:http_url=>book.human_url) if book
25
+ #sort by publish date; if entry hash retrieval fails (as it does)
26
+ #assume the book was published now
27
+ book = books.sort_by{|b| begin b.entry_hash[:published];rescue;Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z");end;}.first
28
+ if book
29
+ #we know dataset will have blank url since it wasn't picked up above
30
+ dst = Dataset.find_or_create_by_handler_and_path('gbook',path)
31
+ api_url = book.human_url.split("&").first
32
+ dst.update_attributes(:http_url=>api_url)
53
33
  end
54
34
  return book
55
35
  end
36
+
56
37
  def Gbook.find_or_create_by_path(path,gdrive_slot)
57
38
  book = Gbook.find_by_path(path,gdrive_slot)
58
- dst = Dataset.find_or_create_by_handler_and_path('gbook',path)
59
39
  if book.nil?
60
40
  #always use owner email to make sure all books are owned by owner account
61
41
  book = Gdrive.root(Gdrive.owner_email).create_spreadsheet(path)
62
42
  ("Created book #{path} at #{Time.now.utc.to_s}; Access at #{book.human_url}").oputs
43
+ #check to make sure the dataset has a blank url; if not, error out
44
+ dst = Dataset.find_or_create_by_handler_and_path('gbook',path)
45
+ if dst.http_url.to_s.length>0
46
+ #add acls to book regardless
47
+ book.add_admin_acl
48
+ raise "Book #{path} is already assigned to #{dst.http_url}; please update the record with #{book.human_url}"
49
+ else
50
+ api_url = book.human_url.split("&").first
51
+ dst.update_attributes(:http_url=>api_url)
52
+ book.add_admin_acl
53
+ end
63
54
  end
64
- #always make sure book dataset http URL is up to date
65
- #and that book has admin acl
66
- dst.update_attributes(:http_url=>book.human_url)
67
- book.add_admin_acl
68
55
  return book
69
56
  end
70
57
  end
@@ -38,7 +38,8 @@ module Mobilize
38
38
  end
39
39
  #update http url for file
40
40
  dst = Dataset.find_by_handler_and_path("gfile",dst_path)
41
- dst.update_attributes(:http_url=>file.human_url)
41
+ api_url = file.human_url.split("&").first
42
+ dst.update_attributes(:http_url=>api_url)
42
43
  true
43
44
  end
44
45
 
@@ -86,7 +87,8 @@ module Mobilize
86
87
  #always make sure dataset http URL is up to date
87
88
  #and that it has admin acl
88
89
  if file
89
- dst.update_attributes(:http_url=>file.human_url)
90
+ api_url = file.human_url.split("&").first
91
+ dst.update_attributes(:http_url=>api_url)
90
92
  file.add_admin_acl
91
93
  end
92
94
  return file
@@ -4,40 +4,34 @@ module Mobilize
4
4
  Base.config('gridfs')
5
5
  end
6
6
 
7
- def Gridfs.grid
8
- session = ::Mongoid.configure.sessions['default']
9
- database_name = session['database']
10
- host,port = session['hosts'].first.split(":")
11
- return ::Mongo::GridFileSystem.new(::Mongo::Connection.new(host,port).db(database_name))
7
+ def Gridfs.read_by_dataset_path(dst_path,*args)
8
+ curr_file = Mongoid::GridFs::Fs::File.where(:filename=>dst_path).first
9
+ zs = curr_file.data if curr_file
10
+ return ::Zlib::Inflate.inflate(zs) if zs.to_s.length>0
12
11
  end
13
12
 
14
- def Gridfs.read_by_dataset_path(dst_path,user_name,*args)
15
- begin
16
- zs=Gridfs.grid.open(dst_path,'r').read
17
- return ::Zlib::Inflate.inflate(zs)
18
- rescue
19
- return nil
20
- end
21
- end
22
-
23
- def Gridfs.write_by_dataset_path(dst_path,string,user_name,*args)
13
+ def Gridfs.write_by_dataset_path(dst_path,string,*args)
24
14
  zs = ::Zlib::Deflate.deflate(string)
25
15
  raise "compressed string too large for Gridfs write" if zs.length > Gridfs.config['max_compressed_write_size']
26
- curr_zs = Gridfs.read_by_dataset_path(dst_path,user_name).to_s
27
- #write a new version when there is a change
16
+ #find and delete existing file
17
+ curr_file = Mongoid::GridFs::Fs::File.where(:filename=>dst_path).first
18
+ curr_zs = curr_file.data if curr_file
19
+ #overwrite when there is a change
28
20
  if curr_zs != zs
29
- Gridfs.grid.open(dst_path,'w',:versions => Gridfs.config['max_versions']){|f| f.write(zs)}
21
+ curr_file.delete if curr_file
22
+ #create temp file w zstring
23
+ temp_file = Tempfile.new("#{string}#{Time.now.to_f}".to_md5)
24
+ temp_file.print(zs)
25
+ temp_file.close
26
+ #put data in file
27
+ Mongoid::GridFs.put(temp_file.path,:filename=>dst_path)
30
28
  end
31
29
  return true
32
30
  end
33
31
 
34
32
  def Gridfs.delete(dst_path)
35
- begin
36
- Gridfs.grid.delete(dst_path)
37
- return true
38
- rescue
39
- return nil
40
- end
33
+ curr_file = Mongoid::GridFs::Fs::File.where(:filename=>dst_path).first
34
+ curr_file.delete
41
35
  end
42
36
  end
43
37
  end
@@ -86,6 +86,10 @@ module Mobilize
86
86
  temp_sheet.delete if temp_sheet
87
87
  #write data to temp sheet
88
88
  temp_sheet = Gsheet.find_or_create_by_path(temp_path,gdrive_slot)
89
+ #delete the temp sheet's datasets, they won't be needed again
90
+ temp_sheet_dst = Dataset.find_by_handler_and_path("gsheet",temp_path)
91
+ temp_book_dst = Dataset.find_by_handler_and_path("gbook",target_path.gridsafe)
92
+ [temp_sheet_dst, temp_book_dst].compact.each{|s| s.delete}
89
93
  #this step has a tendency to fail; if it does,
90
94
  #don't fail the stage, mark it as false
91
95
  begin
@@ -286,6 +286,7 @@ module Mobilize
286
286
  # delete any old runner from previous test runs
287
287
  gdrive_slot = Gdrive.owner_email
288
288
  u.runner.gsheet(gdrive_slot).spreadsheet.delete
289
+ Dataset.find_by_handler_and_path('gbook',u.runner.title).delete
289
290
  Jobtracker.update_status("enqueue jobtracker, wait 45s")
290
291
  Mobilize::Jobtracker.start
291
292
  sleep 45
@@ -93,8 +93,6 @@ module Mobilize
93
93
  end
94
94
  end
95
95
  jobs_sheet.add_headers(r.headers)
96
- #add url to dataset
97
- Dataset.find_or_create_by_url("gsheet://#{r.path}").update_attributes(:http_url=>jobs_sheet.spreadsheet.human_url)
98
96
  begin;jobs_sheet.delete_sheet1;rescue;end #don't care if sheet1 deletion fails
99
97
  return jobs_sheet
100
98
  end
@@ -159,7 +157,7 @@ module Mobilize
159
157
  #there's nothing to update if runner has never had a completed at
160
158
  return false unless r.completed_at
161
159
  jobs_gsheet = r.gsheet(gdrive_slot)
162
- upd_jobs = r.jobs.select{|j| j.status_at and j.status_at > j.runner.completed_at}
160
+ upd_jobs = r.jobs.select{|j| j.status_at and j.status_at.to_f > j.runner.completed_at.to_f}
163
161
  upd_rows = upd_jobs.map{|j| {'name'=>j.name, 'active'=>j.active, 'status'=>j.status}}
164
162
  jobs_gsheet.add_or_update_rows(upd_rows)
165
163
  r.update_status("gsheet updated")
@@ -178,7 +176,7 @@ module Mobilize
178
176
 
179
177
  def user
180
178
  r = self
181
- user_name = r.path.split("_").second.split("(").first.split("/").first
179
+ user_name = r.path.split("_")[1..-1].join("_").split("(").first.split("/").first
182
180
  User.where(:name=>user_name).first
183
181
  end
184
182
 
@@ -1,5 +1,5 @@
1
1
  module Mobilize
2
2
  module Base
3
- VERSION = "1.294"
3
+ VERSION = "1.295"
4
4
  end
5
5
  end
data/lib/mobilize-base.rb CHANGED
@@ -60,8 +60,8 @@ module Mobilize
60
60
  end
61
61
  mongoid_config_path = "#{Mobilize::Base.root}/#{Mobilize::Base.config_dir}mongoid.yml"
62
62
  if File.exists?(mongoid_config_path)
63
- require 'mongo'
64
63
  require 'mongoid'
64
+ require 'mongoid-grid_fs'
65
65
  Mongoid.load!(mongoid_config_path, Mobilize::Base.env)
66
66
  require "mobilize-base/models/dataset"
67
67
  require "mobilize-base/models/user"
@@ -1,10 +1,7 @@
1
1
  ---
2
2
  development:
3
- max_versions: 10 #number of versions of cache to keep in gridfs
4
3
  max_compressed_write_size: 1000000000 #~1GB
5
4
  test:
6
- max_versions: 10 #number of versions of cache to keep in gridfs
7
5
  max_compressed_write_size: 1000000000 #~1GB
8
6
  production:
9
- max_versions: 10 #number of versions of cache to keep in gridfs
10
7
  max_compressed_write_size: 1000000000 #~1GB
@@ -22,10 +22,10 @@ Gem::Specification.new do |s|
22
22
  s.require_paths = ["lib"]
23
23
 
24
24
  s.add_runtime_dependency 'rake'
25
- s.add_runtime_dependency 'bson','1.6.1'
26
- s.add_runtime_dependency 'bson_ext','1.6.1'
27
- s.add_runtime_dependency 'mongo', '1.6.1'
25
+ s.add_runtime_dependency 'bson','1.8.4'
26
+ s.add_runtime_dependency 'bson_ext','1.8.4'
28
27
  s.add_runtime_dependency "mongoid", "~>3.0.0"
28
+ s.add_runtime_dependency 'mongoid-grid_fs'
29
29
  s.add_runtime_dependency 'resque', '1.24.0'
30
30
  s.add_runtime_dependency 'google_drive','0.3.2'
31
31
  s.add_runtime_dependency 'popen4','0.1.2'
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.294'
4
+ version: '1.295'
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-01 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.6.1
37
+ version: 1.8.4
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.6.1
45
+ version: 1.8.4
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bson_ext
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 1.6.1
53
+ version: 1.8.4
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,39 +58,39 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.6.1
61
+ version: 1.8.4
62
62
  - !ruby/object:Gem::Dependency
63
- name: mongo
63
+ name: mongoid
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - '='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.6.1
69
+ version: 3.0.0
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - '='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.6.1
77
+ version: 3.0.0
78
78
  - !ruby/object:Gem::Dependency
79
- name: mongoid
79
+ name: mongoid-grid_fs
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ~>
83
+ - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
- version: 3.0.0
85
+ version: '0'
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ~>
91
+ - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
- version: 3.0.0
93
+ version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: resque
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -225,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
225
  version: '0'
226
226
  segments:
227
227
  - 0
228
- hash: 1508381292879500596
228
+ hash: -2613537944604284453
229
229
  required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  none: false
231
231
  requirements:
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  segments:
236
236
  - 0
237
- hash: 1508381292879500596
237
+ hash: -2613537944604284453
238
238
  requirements: []
239
239
  rubyforge_project: mobilize-base
240
240
  rubygems_version: 1.8.25