mobilize-base 1.1.06 → 1.1.07
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 +42 -0
- data/lib/mobilize-base/extensions/google_drive/worksheet.rb +4 -1
- data/lib/mobilize-base/extensions/string.rb +28 -0
- data/lib/mobilize-base/models/runner.rb +3 -1
- data/lib/mobilize-base/version.rb +1 -1
- data/lib/samples/gsheet.yml +13 -3
- data/test/base1_stage1.yml +3 -3
- data/test/mobilize-base_test.rb +10 -10
- metadata +4 -4
data/README.md
CHANGED
@@ -25,6 +25,7 @@ Table Of Contents
|
|
25
25
|
* [Default Folders and Files](#section_Install_Folders_and_Files)
|
26
26
|
* [Configure](#section_Configure)
|
27
27
|
* [Google Drive](#section_Configure_Google_Drive)
|
28
|
+
* [Google Sheets](#section_Configure_Google_Sheets)
|
28
29
|
* [Jobtracker](#section_Configure_Jobtracker)
|
29
30
|
* [Resque](#section_Configure_Resque)
|
30
31
|
* [Resque-Web](#section_Configure_Resque-Web)
|
@@ -214,6 +215,47 @@ production:
|
|
214
215
|
pw: worker002_google_drive_password
|
215
216
|
```
|
216
217
|
|
218
|
+
<a name='section_Configure_Google_Sheets'></a>
|
219
|
+
### Configure Google Sheets
|
220
|
+
|
221
|
+
gsheet.yml needs:
|
222
|
+
* max_cells, which is the number of cells a sheet is allowed to have
|
223
|
+
written to it at one time. Default is 400k cells, which is the max per
|
224
|
+
book. Google Drive will throw its own exception if
|
225
|
+
you try to write more than that.
|
226
|
+
* Because Google Docs ties date formatting to the Locale for the
|
227
|
+
spreadsheet, there are 2 date format parameters:
|
228
|
+
* read_date_format, which is the format that should be read FROM google
|
229
|
+
sheets for date columns.
|
230
|
+
* sheet_date_format, which is the format that the google sheet is in.
|
231
|
+
* A date column is defined as one where the column header = "date" or "Date", or ends with "_date" or "Date".
|
232
|
+
* The defaults are set to US locale for sheet_date_format, because in 'Murica (US) we
|
233
|
+
use %m/%d/%Y for some reason, and to %Y-%m-%d format for
|
234
|
+
reading, which is more standard and sorts well as a string. If your
|
235
|
+
locale is NOT 'Murica you will want to change these.
|
236
|
+
|
237
|
+
Sample gsheet.yml
|
238
|
+
|
239
|
+
``` yml
|
240
|
+
---
|
241
|
+
development:
|
242
|
+
max_cells: 400000
|
243
|
+
read_date_format: "%Y-%m-%d"
|
244
|
+
sheet_date_format: "%m/%d/%Y"
|
245
|
+
test:
|
246
|
+
max_cells: 400000
|
247
|
+
read_date_format: "%Y-%m-%d"
|
248
|
+
sheet_date_format: "%m/%d/%Y"
|
249
|
+
staging:
|
250
|
+
max_cells: 400000
|
251
|
+
read_date_format: "%Y-%m-%d"
|
252
|
+
sheet_date_format: "%m/%d/%Y"
|
253
|
+
production:
|
254
|
+
max_cells: 400000
|
255
|
+
read_date_format: "%Y-%m-%d"
|
256
|
+
sheet_date_format: "%m/%d/%Y"
|
257
|
+
```
|
258
|
+
|
217
259
|
<a name='section_Configure_Jobtracker'></a>
|
218
260
|
### Configure Jobtracker
|
219
261
|
|
@@ -7,7 +7,10 @@ module GoogleDrive
|
|
7
7
|
return nil unless header and header.first.to_s.length>0
|
8
8
|
#look for blank cols to indicate end of row
|
9
9
|
row_last_i = (header.index("") || header.length)-1
|
10
|
-
rows.map{|r| r[0..row_last_i]}.map{|r| r.join("\t")}.join("\n")
|
10
|
+
out_tsv = rows.map{|r| r[0..row_last_i]}.map{|r| r.join("\t")}.join("\n")
|
11
|
+
out_tsv.tsv_convert_dates(Mobilize::Gsheet.config['sheet_date_format'],
|
12
|
+
Mobilize::Gsheet.config['read_date_format'])
|
13
|
+
|
11
14
|
end
|
12
15
|
def add_headers(headers)
|
13
16
|
headers.each_with_index do |h,h_i|
|
@@ -105,4 +105,32 @@ class String
|
|
105
105
|
end
|
106
106
|
return row_hash_arr
|
107
107
|
end
|
108
|
+
def tsv_header_array(delim="\t")
|
109
|
+
str = self
|
110
|
+
#up to right before first line break, or whole thing
|
111
|
+
str[0..(str.index("\n") || 0)-1].split(delim)
|
112
|
+
end
|
113
|
+
def tsv_convert_dates(from_date_format,to_date_format)
|
114
|
+
str = self
|
115
|
+
hash_array = str.tsv_to_hash_array
|
116
|
+
headers = str.tsv_header_array.join("\t")
|
117
|
+
rows = hash_array.map do |h|
|
118
|
+
row = h.map do |k,v|
|
119
|
+
if k.to_s.downcase=="date" or
|
120
|
+
k.to_s.downcase.ends_with?("_date") or
|
121
|
+
k.to_s.ends_with?("Date")
|
122
|
+
begin
|
123
|
+
Date.strptime(v,from_date_format).strftime(to_date_format)
|
124
|
+
rescue
|
125
|
+
v
|
126
|
+
end
|
127
|
+
else
|
128
|
+
v
|
129
|
+
end
|
130
|
+
end
|
131
|
+
row.join("\t")
|
132
|
+
end
|
133
|
+
rows = [headers] + rows
|
134
|
+
rows.join("\n")
|
135
|
+
end
|
108
136
|
end
|
@@ -45,7 +45,7 @@ module Mobilize
|
|
45
45
|
r.update_attributes(:started_at=>Time.now.utc)
|
46
46
|
#make sure any updates to activity are processed first
|
47
47
|
#as in when someone runs a "once" job that has completed
|
48
|
-
r.update_gsheet(gdrive_slot)
|
48
|
+
r.update_gsheet(gdrive_slot)
|
49
49
|
#read the jobs in the gsheet and update models with news
|
50
50
|
r.read_gsheet(gdrive_slot)
|
51
51
|
#queue up the jobs that are due and active
|
@@ -153,6 +153,8 @@ module Mobilize
|
|
153
153
|
|
154
154
|
def update_gsheet(gdrive_slot)
|
155
155
|
r = self
|
156
|
+
#there's nothing to update if runner has never had a completed at
|
157
|
+
return false unless r.completed_at
|
156
158
|
jobs_gsheet = r.gsheet(gdrive_slot)
|
157
159
|
upd_jobs = r.jobs.select{|j| j.status_at and j.status_at > j.runner.completed_at}
|
158
160
|
upd_rows = upd_jobs.map{|j| {'name'=>j.name, 'active'=>j.active, 'status'=>j.status}}
|
data/lib/samples/gsheet.yml
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
---
|
2
2
|
development:
|
3
|
-
max_cells: 400000
|
3
|
+
max_cells: 400000 #current google limit is 400k cells per book
|
4
|
+
read_date_format: "%Y-%m-%d" #format to record when reading sheets
|
5
|
+
sheet_date_format: "%m/%d/%Y" #format to use to parse sheets
|
4
6
|
test:
|
5
|
-
max_cells: 400000
|
7
|
+
max_cells: 400000 #current google limit is 400k cells per book
|
8
|
+
read_date_format: "%Y-%m-%d" #format to record when reading sheets
|
9
|
+
sheet_date_format: "%m/%d/%Y" #format to use to parse sheets
|
10
|
+
staging:
|
11
|
+
max_cells: 400000 #current google limit is 400k cells per book
|
12
|
+
read_date_format: "%Y-%m-%d" #format to record when reading sheets
|
13
|
+
sheet_date_format: "%m/%d/%Y" #format to use to parse sheets
|
6
14
|
production:
|
7
|
-
max_cells: 400000
|
15
|
+
max_cells: 400000 #current google limit is 400k cells per book
|
16
|
+
read_date_format: "%Y-%m-%d" #format to record when reading sheets
|
17
|
+
sheet_date_format: "%m/%d/%Y" #format to use to parse sheets
|
data/test/base1_stage1.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
- {
|
2
|
-
- {
|
3
|
-
- {
|
1
|
+
- {date: 2013-01-01, snake_date: 2013-02-01, camelDate: 2013-03-01}
|
2
|
+
- {date: 2013-01-01, snake_date: 2013-02-02, camelDate: 2013-03-02}
|
3
|
+
- {date: 2013-01-01, snake_date: 2013-02-03, camelDate: 2013-03-03}
|
data/test/mobilize-base_test.rb
CHANGED
@@ -31,36 +31,36 @@ describe "Mobilize" do
|
|
31
31
|
puts "Jobtracker created runner with 'jobs' sheet?"
|
32
32
|
r = u.runner
|
33
33
|
jobs_sheet = r.gsheet(gdrive_slot)
|
34
|
-
tsv = jobs_sheet.read(
|
35
|
-
assert tsv.length ==
|
34
|
+
tsv = jobs_sheet.read(user_name)
|
35
|
+
assert tsv.tsv_header_array.join.length == 53 #total header length
|
36
36
|
|
37
37
|
puts "add base1_stage1 input sheet"
|
38
38
|
test_source_sheet = Mobilize::Gsheet.find_or_create_by_path("#{r.path.split("/")[0..-2].join("/")}/base1_stage1.in",gdrive_slot)
|
39
39
|
|
40
40
|
test_source_ha = ::YAML.load_file("#{Mobilize::Base.root}/test/base1_stage1.yml")*40
|
41
41
|
test_source_tsv = test_source_ha.hash_array_to_tsv
|
42
|
-
test_source_sheet.write(test_source_tsv,
|
42
|
+
test_source_sheet.write(test_source_tsv,user_name)
|
43
43
|
|
44
|
-
puts "add row to jobs sheet, wait
|
44
|
+
puts "add row to jobs sheet, wait 300s"
|
45
45
|
test_job_rows = ::YAML.load_file("#{Mobilize::Base.root}/test/base_job_rows.yml")
|
46
46
|
jobs_sheet.add_or_update_rows(test_job_rows)
|
47
|
-
sleep
|
47
|
+
sleep 300
|
48
48
|
|
49
49
|
puts "jobtracker posted test sheet data to test destination, and checksum succeeded?"
|
50
50
|
test_target_sheet_1 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/base1.out",gdrive_slot)
|
51
51
|
test_target_sheet_2 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/base2.out",gdrive_slot)
|
52
52
|
|
53
|
-
assert test_target_sheet_1.
|
53
|
+
assert test_target_sheet_1.read(user_name) == test_source_sheet.read(user_name)
|
54
54
|
|
55
|
-
puts "delete both output sheets, set first job to active=true, wait
|
55
|
+
puts "delete both output sheets, set first job to active=true, wait 300s"
|
56
56
|
[test_target_sheet_1,test_target_sheet_2].each{|s| s.delete}
|
57
57
|
|
58
58
|
jobs_sheet.add_or_update_rows([{'name'=>'base1','active'=>true}])
|
59
|
-
sleep
|
59
|
+
sleep 300
|
60
60
|
|
61
|
-
test_target_sheet_2 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/
|
61
|
+
test_target_sheet_2 = Mobilize::Gsheet.find_by_path("#{r.path.split("/")[0..-2].join("/")}/base2.out",gdrive_slot)
|
62
62
|
puts "jobtracker posted test sheet data to test destination, and checksum succeeded?"
|
63
|
-
assert test_target_sheet_2.
|
63
|
+
assert test_target_sheet_2.read(user_name) == test_source_sheet.read(user_name)
|
64
64
|
|
65
65
|
end
|
66
66
|
|
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.1.
|
4
|
+
version: 1.1.07
|
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-02-
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
239
239
|
version: '0'
|
240
240
|
segments:
|
241
241
|
- 0
|
242
|
-
hash:
|
242
|
+
hash: 1956526465748167234
|
243
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
244
244
|
none: false
|
245
245
|
requirements:
|
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
version: '0'
|
249
249
|
segments:
|
250
250
|
- 0
|
251
|
-
hash:
|
251
|
+
hash: 1956526465748167234
|
252
252
|
requirements: []
|
253
253
|
rubyforge_project: mobilize-base
|
254
254
|
rubygems_version: 1.8.24
|