td 0.10.22 → 0.10.23
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/ChangeLog +8 -0
- data/lib/td/command/common.rb +31 -2
- data/lib/td/command/export.rb +84 -0
- data/lib/td/command/help.rb +13 -6
- data/lib/td/command/job.rb +2 -2
- data/lib/td/command/list.rb +11 -12
- data/lib/td/command/query.rb +18 -5
- data/lib/td/command/result.rb +68 -53
- data/lib/td/command/runner.rb +6 -2
- data/lib/td/command/sched.rb +21 -8
- data/lib/td/command/table.rb +1 -0
- data/lib/td/version.rb +1 -1
- metadata +14 -13
data/ChangeLog
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
|
2
|
+
== 2012-04-26 version 0.10.23
|
3
|
+
|
4
|
+
* Added result:list, result:create and result:delete subcommands
|
5
|
+
* query subcommand supports -r <result URL> option
|
6
|
+
* sched:create subcommand supports -r <result URL> option
|
7
|
+
* Added table:export subcommand
|
8
|
+
|
9
|
+
|
2
10
|
== 2012-04-04 version 0.10.22
|
3
11
|
|
4
12
|
* Added missing data/sample_apache.json file
|
data/lib/td/command/common.rb
CHANGED
@@ -15,12 +15,17 @@ module Command
|
|
15
15
|
@render_indent = ''
|
16
16
|
end
|
17
17
|
|
18
|
-
def get_client
|
18
|
+
def get_client(opts={})
|
19
19
|
apikey = Config.apikey
|
20
20
|
unless apikey
|
21
21
|
raise ConfigError, "Account is not configured."
|
22
22
|
end
|
23
|
-
Client.new(apikey)
|
23
|
+
Client.new(apikey, opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_ssl_client(opts={})
|
27
|
+
opts[:ssl] = true
|
28
|
+
get_client(opts)
|
24
29
|
end
|
25
30
|
|
26
31
|
def cmd_render_table(rows, *opts)
|
@@ -96,5 +101,29 @@ module Command
|
|
96
101
|
table
|
97
102
|
end
|
98
103
|
|
104
|
+
def ask_password(max=3, &block)
|
105
|
+
3.times do
|
106
|
+
begin
|
107
|
+
system "stty -echo" # TODO termios
|
108
|
+
print "Password (typing will be hidden): "
|
109
|
+
password = STDIN.gets || ""
|
110
|
+
password = password[0..-2] # strip \n
|
111
|
+
rescue Interrupt
|
112
|
+
$stderr.print "\ncanceled."
|
113
|
+
exit 1
|
114
|
+
ensure
|
115
|
+
system "stty echo" # TODO termios
|
116
|
+
print "\n"
|
117
|
+
end
|
118
|
+
|
119
|
+
if password.empty?
|
120
|
+
$stderr.puts "canceled."
|
121
|
+
exit 0
|
122
|
+
end
|
123
|
+
|
124
|
+
yield password
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
99
128
|
end
|
100
129
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
module TreasureData
|
3
|
+
module Command
|
4
|
+
|
5
|
+
def table_export(op)
|
6
|
+
from = nil
|
7
|
+
to = nil
|
8
|
+
s3_bucket = nil
|
9
|
+
aws_access_key_id = nil
|
10
|
+
aws_secret_access_key = nil
|
11
|
+
file_format = "json.gz"
|
12
|
+
|
13
|
+
op.on('-f', '--from TIME', 'export data which is newer than or same with the TIME') {|s|
|
14
|
+
from = export_parse_time(s)
|
15
|
+
}
|
16
|
+
op.on('-t', '--to TIME', 'export data which is older than the TIME') {|s|
|
17
|
+
to = export_parse_time(s)
|
18
|
+
}
|
19
|
+
op.on('-b', '--s3-bucket NAME', 'name of the destination S3 bucket (required)') {|s|
|
20
|
+
s3_bucket = s
|
21
|
+
}
|
22
|
+
op.on('-k', '--aws-key-id KEY_ID', 'AWS access key id to export data (required)') {|s|
|
23
|
+
aws_access_key_id = s
|
24
|
+
}
|
25
|
+
op.on('-s', '--aws-secret-key SECRET_KEY', 'AWS secret access key to export data (required)') {|s|
|
26
|
+
aws_secret_access_key = s
|
27
|
+
}
|
28
|
+
|
29
|
+
db_name, table_name = op.cmd_parse
|
30
|
+
|
31
|
+
unless s3_bucket
|
32
|
+
$stderr.puts "-b, --s3-bucket NAME option is required."
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
unless aws_access_key_id
|
37
|
+
$stderr.puts "-k, --aws-key-id KEY_ID option is required."
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
unless aws_secret_access_key
|
42
|
+
$stderr.puts "-s, --aws-secret-key SECRET_KEY option is required."
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
client = get_client
|
47
|
+
|
48
|
+
get_table(client, db_name, table_name)
|
49
|
+
|
50
|
+
client = get_ssl_client
|
51
|
+
|
52
|
+
s3_opts = {}
|
53
|
+
s3_opts['from'] = from.to_s if from
|
54
|
+
s3_opts['to'] = to.to_s if to
|
55
|
+
s3_opts['file_format'] = file_format
|
56
|
+
s3_opts['bucket'] = s3_bucket
|
57
|
+
s3_opts['access_key_id'] = aws_access_key_id
|
58
|
+
s3_opts['secret_access_key'] = aws_secret_access_key
|
59
|
+
|
60
|
+
job = client.export(db_name, table_name, "s3", s3_opts)
|
61
|
+
|
62
|
+
$stderr.puts "Export job #{job.job_id} is queued."
|
63
|
+
$stderr.puts "Use '#{$prog} job:show #{job.job_id}' to show the status."
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def export_parse_time(time)
|
68
|
+
if time.to_i.to_s == time.to_s
|
69
|
+
# UNIX time
|
70
|
+
return time.to_i
|
71
|
+
else
|
72
|
+
require 'time'
|
73
|
+
begin
|
74
|
+
return Time.parse(time).to_i
|
75
|
+
rescue
|
76
|
+
$stderr.puts "invalid time format: #{time}"
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
data/lib/td/command/help.rb
CHANGED
@@ -5,14 +5,21 @@ module Command
|
|
5
5
|
def help(op)
|
6
6
|
cmd = op.cmd_parse
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
c = List.get_option(cmd)
|
9
|
+
if c == nil
|
10
|
+
$stderr.puts "'#{cmd}' is not a td command. Run '#{$prog}' to show the list."
|
11
|
+
List.show_guess(cmd)
|
12
|
+
exit 1
|
13
|
+
|
14
|
+
elsif c.name != cmd && c.group == cmd
|
15
|
+
# group command
|
16
|
+
puts List.cmd_usage(cmd)
|
12
17
|
exit 1
|
13
|
-
end
|
14
18
|
|
15
|
-
|
19
|
+
else
|
20
|
+
method = List.get_method(cmd)
|
21
|
+
method.call(['--help'])
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
def help_all(op)
|
data/lib/td/command/job.rb
CHANGED
@@ -38,7 +38,7 @@ module Command
|
|
38
38
|
next if error && !job.error?
|
39
39
|
start = job.start_at
|
40
40
|
elapsed = cmd_format_elapsed(start, job.end_at)
|
41
|
-
rows << {:JobID => job.job_id, :Status => job.status, :Query => job.query.to_s, :Start => (start ? start.localtime : ''), :Elapsed => elapsed, :Result => job.
|
41
|
+
rows << {:JobID => job.job_id, :Status => job.status, :Query => job.query.to_s, :Start => (start ? start.localtime : ''), :Elapsed => elapsed, :Result => job.result_url}
|
42
42
|
}
|
43
43
|
|
44
44
|
puts cmd_render_table(rows, :fields => [:JobID, :Status, :Start, :Elapsed, :Result, :Query])
|
@@ -76,7 +76,7 @@ module Command
|
|
76
76
|
puts "URL : #{job.url}"
|
77
77
|
puts "Status : #{job.status}"
|
78
78
|
puts "Query : #{job.query}"
|
79
|
-
puts "Result table : #{job.
|
79
|
+
puts "Result table : #{job.result_url}"
|
80
80
|
|
81
81
|
if wait && !job.finished?
|
82
82
|
wait_job(job)
|
data/lib/td/command/list.rb
CHANGED
@@ -143,9 +143,10 @@ module List
|
|
143
143
|
|
144
144
|
def self.cmd_usage(name)
|
145
145
|
if c = COMMAND[name]
|
146
|
-
c.create_optparse([]).
|
146
|
+
c.create_optparse([]).to_s
|
147
|
+
else
|
148
|
+
nil
|
147
149
|
end
|
148
|
-
nil
|
149
150
|
end
|
150
151
|
|
151
152
|
def self.get_method(name)
|
@@ -211,24 +212,22 @@ module List
|
|
211
212
|
end
|
212
213
|
|
213
214
|
add_list 'db:list', %w[], 'Show list of tables in a database', 'db:list', 'dbs'
|
214
|
-
add_list 'db:show', %w[db], 'Describe
|
215
|
+
add_list 'db:show', %w[db], 'Describe information of a database', 'db example_db'
|
215
216
|
add_list 'db:create', %w[db], 'Create a database', 'db:create example_db'
|
216
217
|
add_list 'db:delete', %w[db], 'Delete a database', 'db:delete example_db'
|
217
218
|
|
218
219
|
add_list 'table:list', %w[db?], 'Show list of tables', 'table:list', 'table:list example_db', 'tables'
|
219
|
-
add_list 'table:show', %w[db table], 'Describe
|
220
|
+
add_list 'table:show', %w[db table], 'Describe information of a table', 'table example_db table1'
|
220
221
|
add_list 'table:create', %w[db table], 'Create a table', 'table:create example_db table1'
|
221
222
|
add_list 'table:delete', %w[db table], 'Delete a table', 'table:delete example_db table1'
|
222
223
|
add_list 'table:import', %w[db table files_], 'Parse and import files to a table', 'table:import example_db table1 --apache access.log', 'table:import example_db table1 --json -t time - < test.json'
|
223
|
-
add_list 'table:export', %w[db table], 'Dump logs in a table to the specified storage', 'table:export example_db table1 --s3-bucket mybucket'
|
224
|
+
add_list 'table:export', %w[db table], 'Dump logs in a table to the specified storage', 'table:export example_db table1 --s3-bucket mybucket -k KEY_ID -s SECRET_KEY'
|
224
225
|
add_list 'table:tail', %w[db table], 'Get recently imported logs', 'table:tail example_db table1', 'table:tail example_db table1 -t "2011-01-02 03:04:05" -n 30'
|
225
226
|
|
226
|
-
add_list 'result:
|
227
|
-
add_list 'result:
|
228
|
-
add_list 'result:create', %w[name], 'Create a result
|
229
|
-
add_list 'result:delete', %w[name], 'Delete a result
|
230
|
-
add_list 'result:connect', %w[sql?], 'Connect to the server using mysql command', 'result:connect'
|
231
|
-
#add_list 'result:get', %w[name], 'Download dump of the result table'
|
227
|
+
add_list 'result:list', %w[], 'Show list of result URLs', 'result:list', 'results'
|
228
|
+
add_list 'result:show', %w[name], 'Describe information of a result URL', 'result mydb'
|
229
|
+
add_list 'result:create', %w[name URL], 'Create a result URL', 'result:create mydb mysql://my-server/mydb'
|
230
|
+
add_list 'result:delete', %w[name], 'Delete a result URL', 'result:delete mydb'
|
232
231
|
|
233
232
|
add_list 'status', %w[], 'Show schedules, jobs, tables and results', 'status', 's'
|
234
233
|
|
@@ -284,7 +283,7 @@ module List
|
|
284
283
|
add_alias 'table', 'table:show'
|
285
284
|
add_alias 'tables', 'table:list'
|
286
285
|
|
287
|
-
add_alias 'result', '
|
286
|
+
add_alias 'result', 'result:show'
|
288
287
|
add_alias 'results', 'result:list'
|
289
288
|
|
290
289
|
add_alias 'schema', 'schema:show'
|
data/lib/td/command/query.rb
CHANGED
@@ -7,7 +7,9 @@ module Command
|
|
7
7
|
wait = false
|
8
8
|
output = nil
|
9
9
|
format = 'tsv'
|
10
|
-
|
10
|
+
result_url = nil
|
11
|
+
result_user = nil
|
12
|
+
result_ask_password = false
|
11
13
|
|
12
14
|
op.on('-d', '--database DB_NAME', 'use the database (required)') {|s|
|
13
15
|
db_name = s
|
@@ -15,9 +17,6 @@ module Command
|
|
15
17
|
op.on('-w', '--wait', 'wait for finishing the job', TrueClass) {|b|
|
16
18
|
wait = b
|
17
19
|
}
|
18
|
-
op.on('-r', '--result RESULT_TABLE', 'write result to the result table (use result:create command)') {|s|
|
19
|
-
result = s
|
20
|
-
}
|
21
20
|
op.on('-o', '--output PATH', 'write result to the file') {|s|
|
22
21
|
output = s
|
23
22
|
}
|
@@ -27,6 +26,15 @@ module Command
|
|
27
26
|
end
|
28
27
|
format = s
|
29
28
|
}
|
29
|
+
op.on('-r', '--result RESULT_URL', 'write result to the URL (see also result:create subcommand)') {|s|
|
30
|
+
result_url = s
|
31
|
+
}
|
32
|
+
op.on('-u', '--user NAME', 'set user name for the result URL') {|s|
|
33
|
+
result_user = s
|
34
|
+
}
|
35
|
+
op.on('-p', '--password', 'ask password for the result URL') {|s|
|
36
|
+
result_ask_password = true
|
37
|
+
}
|
30
38
|
|
31
39
|
sql = op.cmd_parse
|
32
40
|
|
@@ -35,12 +43,17 @@ module Command
|
|
35
43
|
exit 1
|
36
44
|
end
|
37
45
|
|
46
|
+
if result_url
|
47
|
+
require 'td/command/result'
|
48
|
+
result_url = build_result_url(result_url, result_user, result_ask_password)
|
49
|
+
end
|
50
|
+
|
38
51
|
client = get_client
|
39
52
|
|
40
53
|
# local existance check
|
41
54
|
get_database(client, db_name)
|
42
55
|
|
43
|
-
job = client.query(db_name, sql,
|
56
|
+
job = client.query(db_name, sql, result_url)
|
44
57
|
|
45
58
|
$stderr.puts "Job #{job.job_id} is queued."
|
46
59
|
$stderr.puts "Use '#{$prog} job:show #{job.job_id}' to show the status."
|
data/lib/td/command/result.rb
CHANGED
@@ -2,19 +2,22 @@
|
|
2
2
|
module TreasureData
|
3
3
|
module Command
|
4
4
|
|
5
|
-
def
|
6
|
-
op.cmd_parse
|
5
|
+
def result_show(op)
|
6
|
+
name = op.cmd_parse
|
7
7
|
|
8
8
|
client = get_client
|
9
9
|
|
10
|
-
|
10
|
+
rs = client.results
|
11
|
+
r = rs.find {|r| name == r.name }
|
12
|
+
|
13
|
+
unless r
|
14
|
+
$stderr.puts "Result URL '#{name}' does not exist."
|
15
|
+
$stderr.puts "Use '#{$prog} result:create #{name} <URL>' to create the URL."
|
16
|
+
exit 1
|
17
|
+
end
|
11
18
|
|
12
|
-
puts "
|
13
|
-
puts "
|
14
|
-
puts "Port : #{info.port}"
|
15
|
-
puts "User : #{info.user}"
|
16
|
-
puts "Password : #{info.password}"
|
17
|
-
puts "Database : #{info.database}"
|
19
|
+
puts "Name : #{r.name}"
|
20
|
+
puts "URL : #{r.url}"
|
18
21
|
end
|
19
22
|
|
20
23
|
def result_list(op)
|
@@ -22,39 +25,51 @@ module Command
|
|
22
25
|
|
23
26
|
client = get_client
|
24
27
|
|
25
|
-
|
28
|
+
rs = client.results
|
26
29
|
|
27
30
|
rows = []
|
28
|
-
|
29
|
-
rows << {:Name =>
|
31
|
+
rs.each {|r|
|
32
|
+
rows << {:Name => r.name, :URL => r.url}
|
30
33
|
}
|
31
34
|
rows = rows.sort_by {|map|
|
32
35
|
map[:Name]
|
33
36
|
}
|
34
37
|
|
35
|
-
puts cmd_render_table(rows, :fields => [:Name])
|
38
|
+
puts cmd_render_table(rows, :fields => [:Name, :URL])
|
36
39
|
|
37
|
-
if
|
38
|
-
$stderr.puts "There are result
|
39
|
-
$stderr.puts "Use '#{$prog} result:create <name>' to create a result
|
40
|
+
if rs.empty?
|
41
|
+
$stderr.puts "There are no result URLs."
|
42
|
+
$stderr.puts "Use '#{$prog} result:create <name> <url>' to create a result URL."
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
46
|
def result_create(op)
|
44
|
-
|
47
|
+
result_user = nil
|
48
|
+
result_ask_password = false
|
49
|
+
|
50
|
+
op.on('-u', '--user NAME', 'set user name for authentication') {|s|
|
51
|
+
result_user = s
|
52
|
+
}
|
53
|
+
op.on('-p', '--password', 'ask password for authentication') {|s|
|
54
|
+
result_ask_password = true
|
55
|
+
}
|
56
|
+
|
57
|
+
name, url = op.cmd_parse
|
45
58
|
|
46
59
|
API.validate_database_name(name)
|
47
60
|
|
48
61
|
client = get_client
|
49
62
|
|
63
|
+
url = build_result_url(url, result_user, result_ask_password)
|
64
|
+
|
50
65
|
begin
|
51
|
-
client.
|
66
|
+
client.create_result(name, url)
|
52
67
|
rescue AlreadyExistsError
|
53
|
-
$stderr.puts "Result
|
68
|
+
$stderr.puts "Result URL '#{name}' already exists."
|
54
69
|
exit 1
|
55
70
|
end
|
56
71
|
|
57
|
-
$stderr.puts "Result
|
72
|
+
$stderr.puts "Result URL '#{name}' is created."
|
58
73
|
end
|
59
74
|
|
60
75
|
def result_delete(op)
|
@@ -63,49 +78,49 @@ module Command
|
|
63
78
|
client = get_client
|
64
79
|
|
65
80
|
begin
|
66
|
-
client.
|
81
|
+
client.delete_result(name)
|
67
82
|
rescue NotFoundError
|
68
|
-
$stderr.puts "Result
|
83
|
+
$stderr.puts "Result URL '#{name}' does not exist."
|
69
84
|
exit 1
|
70
85
|
end
|
71
86
|
|
72
|
-
$stderr.puts "Result
|
87
|
+
$stderr.puts "Result URL '#{name}' is deleted."
|
73
88
|
end
|
74
89
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
cmd_start = Time.now
|
91
|
-
|
92
|
-
if sql
|
93
|
-
IO.popen(cmd, "w") {|io|
|
94
|
-
io.write sql
|
95
|
-
io.close
|
96
|
-
}
|
97
|
-
else
|
98
|
-
STDERR.puts "> #{cmd.join(' ')}"
|
99
|
-
system(*cmd)
|
90
|
+
private
|
91
|
+
def build_result_url(url, user, ask_password)
|
92
|
+
if ask_password
|
93
|
+
begin
|
94
|
+
system "stty -echo" # TODO termios
|
95
|
+
print "Password (typing will be hidden): "
|
96
|
+
password = STDIN.gets || ""
|
97
|
+
password = password[0..-2] # strip \n
|
98
|
+
rescue Interrupt
|
99
|
+
$stderr.print "\ncanceled."
|
100
|
+
exit 1
|
101
|
+
ensure
|
102
|
+
system "stty echo" # TODO termios
|
103
|
+
print "\n"
|
104
|
+
end
|
100
105
|
end
|
101
106
|
|
102
|
-
|
103
|
-
if
|
104
|
-
|
105
|
-
|
107
|
+
ups = nil
|
108
|
+
if user && password
|
109
|
+
require 'cgi'
|
110
|
+
ups = "#{CGI.escape(user)}:#{CGI.escape(password)}@"
|
111
|
+
elsif user
|
112
|
+
require 'cgi'
|
113
|
+
ups = "#{CGI.escape(user)}@"
|
114
|
+
elsif password
|
115
|
+
require 'cgi'
|
116
|
+
ups = ":#{CGI.escape(password)}@"
|
117
|
+
end
|
118
|
+
if ups
|
119
|
+
url = url.sub(/\A([\w]+:(?:\/\/)?)/, "\\1#{ups}")
|
106
120
|
end
|
107
|
-
end
|
108
121
|
|
122
|
+
url
|
123
|
+
end
|
109
124
|
end
|
110
125
|
end
|
111
126
|
|
data/lib/td/command/runner.rb
CHANGED
@@ -37,10 +37,10 @@ EOF
|
|
37
37
|
Basic commands:
|
38
38
|
|
39
39
|
db # create/delete/list databases
|
40
|
-
table # create/delete/list/import/tail tables
|
40
|
+
table # create/delete/list/import/export/tail tables
|
41
41
|
query # issue a query
|
42
42
|
job # show/kill/list jobs
|
43
|
-
result # create/delete/list
|
43
|
+
result # create/delete/list result URLs
|
44
44
|
|
45
45
|
Additional commands:
|
46
46
|
|
@@ -83,6 +83,10 @@ EOF
|
|
83
83
|
# $debug = b
|
84
84
|
#}
|
85
85
|
|
86
|
+
op.on('-h', '--help', "show help") {
|
87
|
+
usage nil
|
88
|
+
}
|
89
|
+
|
86
90
|
begin
|
87
91
|
op.order!(argv)
|
88
92
|
usage nil if argv.empty?
|
data/lib/td/command/sched.rb
CHANGED
@@ -11,7 +11,7 @@ module Command
|
|
11
11
|
|
12
12
|
rows = []
|
13
13
|
scheds.each {|sched|
|
14
|
-
rows << {:Name => sched.name, :Cron => sched.cron, :Timezone => sched.timezone, :Delay => sched.delay, :Result => sched.
|
14
|
+
rows << {:Name => sched.name, :Cron => sched.cron, :Timezone => sched.timezone, :Delay => sched.delay, :Result => sched.result_url, :Database => sched.database, :Query => sched.query, :"Next schedule" => sched.next_time ? sched.next_time.localtime : nil }
|
15
15
|
}
|
16
16
|
rows = rows.sort_by {|map|
|
17
17
|
map[:Name]
|
@@ -22,22 +22,30 @@ module Command
|
|
22
22
|
|
23
23
|
def sched_create(op)
|
24
24
|
db_name = nil
|
25
|
-
result = nil
|
26
25
|
timezone = nil
|
27
26
|
delay = 0
|
27
|
+
result_url = nil
|
28
|
+
result_user = nil
|
29
|
+
result_ask_password = false
|
28
30
|
|
29
31
|
op.on('-d', '--database DB_NAME', 'use the database (required)') {|s|
|
30
32
|
db_name = s
|
31
33
|
}
|
32
|
-
op.on('-r', '--result RESULT_TABLE', 'write result to the result table (use result:create command)') {|s|
|
33
|
-
result = s
|
34
|
-
}
|
35
34
|
op.on('-t', '--timezone TZ', 'name of the timezone (like Asia/Tokyo)') {|s|
|
36
35
|
timezone = s
|
37
36
|
}
|
38
37
|
op.on('-D', '--delay SECONDS', 'delay time of the schedule', Integer) {|i|
|
39
38
|
delay = i
|
40
39
|
}
|
40
|
+
op.on('-r', '--result RESULT_URL', 'write result to the URL (see also result:create subcommand)') {|s|
|
41
|
+
result_url = s
|
42
|
+
}
|
43
|
+
op.on('-u', '--user NAME', 'set user name for the result URL') {|s|
|
44
|
+
result_user = s
|
45
|
+
}
|
46
|
+
op.on('-p', '--password', 'ask password for the result URL') {|s|
|
47
|
+
result_ask_password = true
|
48
|
+
}
|
41
49
|
|
42
50
|
name, cron, sql = op.cmd_parse
|
43
51
|
|
@@ -46,13 +54,18 @@ module Command
|
|
46
54
|
exit 1
|
47
55
|
end
|
48
56
|
|
57
|
+
if result_url
|
58
|
+
require 'td/command/result'
|
59
|
+
result_url = build_result_url(result_url, result_user, result_ask_password)
|
60
|
+
end
|
61
|
+
|
49
62
|
client = get_client
|
50
63
|
|
51
64
|
# local existance check
|
52
65
|
get_database(client, db_name)
|
53
66
|
|
54
67
|
begin
|
55
|
-
first_time = client.create_schedule(name, :cron=>cron, :query=>sql, :database=>db_name, :result=>
|
68
|
+
first_time = client.create_schedule(name, :cron=>cron, :query=>sql, :database=>db_name, :result=>result_url, :timezone=>timezone, :delay=>delay)
|
56
69
|
rescue AlreadyExistsError
|
57
70
|
cmd_debug_error $!
|
58
71
|
$stderr.puts "Schedule '#{name}' already exists."
|
@@ -172,14 +185,14 @@ module Command
|
|
172
185
|
puts "Timezone : #{s.timezone}"
|
173
186
|
puts "Delay : #{s.delay} sec"
|
174
187
|
puts "Next : #{s.next_time}"
|
175
|
-
puts "Result : #{s.
|
188
|
+
puts "Result : #{s.result_url}"
|
176
189
|
puts "Database : #{s.database}"
|
177
190
|
puts "Query : #{s.query}"
|
178
191
|
end
|
179
192
|
|
180
193
|
rows = []
|
181
194
|
history.each {|j|
|
182
|
-
rows << {:Time => j.scheduled_at.localtime, :JobID => j.job_id, :Status => j.status, :Result=>j.
|
195
|
+
rows << {:Time => j.scheduled_at.localtime, :JobID => j.job_id, :Status => j.status, :Result=>j.result_url}
|
183
196
|
}
|
184
197
|
|
185
198
|
puts cmd_render_table(rows, :fields => [:JobID, :Time, :Status, :Result])
|
data/lib/td/command/table.rb
CHANGED
data/lib/td/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.23
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70287442084840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70287442084840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70287442084360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.4.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70287442084360
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: hirb
|
38
|
-
requirement: &
|
38
|
+
requirement: &70287442083880 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,21 +43,21 @@ dependencies:
|
|
43
43
|
version: 0.4.5
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70287442083880
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: td-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &70287442083400 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.8.
|
54
|
+
version: 0.8.15
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70287442083400
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: td-logger
|
60
|
-
requirement: &
|
60
|
+
requirement: &70287442082860 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.3.8
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70287442082860
|
69
69
|
description:
|
70
70
|
email:
|
71
71
|
executables:
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/td/command/apikey.rb
|
84
84
|
- lib/td/command/common.rb
|
85
85
|
- lib/td/command/db.rb
|
86
|
+
- lib/td/command/export.rb
|
86
87
|
- lib/td/command/help.rb
|
87
88
|
- lib/td/command/import.rb
|
88
89
|
- lib/td/command/job.rb
|