td 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ == 2011-09-13 version 0.9.3
3
+
4
+ * Fixed import subcommand
5
+
6
+
2
7
  == 2011-09-08 version 0.9.2
3
8
 
4
9
  * Added job:kill subcommand
@@ -50,8 +50,7 @@ module Command
50
50
  time_key = s
51
51
  }
52
52
 
53
- table_ident, *paths = op.cmd_parse
54
- db_name, table_name = parse_table_ident(table_ident)
53
+ db_name, table_name, *paths = op.cmd_parse
55
54
 
56
55
  client = get_client
57
56
 
@@ -190,6 +190,11 @@ module List
190
190
  add_list 'schema:add', %w[db table columns_], 'Add new columns to a table'
191
191
  add_list 'schema:remove', %w[db table columns_], 'Remove columns from a table'
192
192
 
193
+ #add_list 'sched:list', %w[], 'Show list of schedules'
194
+ #add_list 'sched:create', %w[name cron sql], 'Create a schedule'
195
+ #add_list 'sched:delete', %w[name], 'Delete a schedule'
196
+ #add_list 'sched:history', %w[name max?], 'Show history of scheduled queries'
197
+
193
198
  add_list 'query', %w[sql], 'Issue a query'
194
199
 
195
200
  add_list 'job:show', %w[job_id], 'Show status and result of a job'
@@ -220,6 +225,16 @@ module List
220
225
 
221
226
  add_alias 'schema', 'schema:show'
222
227
 
228
+ #add_alias 'schedule:list', 'sched:list'
229
+ #add_alias 'schedule:create', 'sched:create'
230
+ #add_alias 'schedule:delete', 'sched:delete'
231
+ #add_alias 'schedule:history', 'sched:history'
232
+ #add_alias 'schedule:hist', 'sched:history'
233
+ #add_alias 'sched:hist', 'sched:history'
234
+ #add_alias 'sched', 'sched:history'
235
+ #add_alias 'scheds', 'sched:list'
236
+ #add_alias 'schedules', 'sched:list'
237
+
223
238
  add_alias 'job', 'job:show'
224
239
  add_alias 'jobs', 'job:list'
225
240
  add_alias 'kill', 'job:kill'
@@ -26,18 +26,19 @@ module Command
26
26
 
27
27
  sql = op.cmd_parse
28
28
 
29
- client = get_client
30
-
31
29
  unless db_name
32
30
  $stderr.puts "-d, --database DB_NAME option is required."
33
31
  exit 1
34
32
  end
35
33
 
34
+ client = get_client
35
+
36
+ # local existance check
36
37
  get_database(client, db_name)
37
38
 
38
39
  job = client.query(db_name, sql)
39
40
 
40
- $stderr.puts "Job #{job.job_id} is started."
41
+ $stderr.puts "Job #{job.job_id} is queued."
41
42
  $stderr.puts "Use '#{$prog} job:show #{job.job_id}' to show the status."
42
43
  $stderr.puts "See #{job.url} to see the progress."
43
44
 
@@ -0,0 +1,109 @@
1
+
2
+ module TreasureData
3
+ module Command
4
+
5
+ def sched_list(op)
6
+ op.cmd_parse
7
+
8
+ client = get_client
9
+
10
+ scheds = client.schedules
11
+
12
+ rows = []
13
+ scheds.each {|sched|
14
+ rows << {:Name => sched.name, :Cron => sched.cron, :Query => sched.query}
15
+ }
16
+ rows = rows.sort_by {|map|
17
+ map[:Name]
18
+ }
19
+
20
+ puts cmd_render_table(rows, :fields => [:Name, :Cron, :Query])
21
+ end
22
+
23
+ def sched_create(op)
24
+ db_name = nil
25
+
26
+ op.on('-d', '--database DB_NAME', 'use the database (required)') {|s|
27
+ db_name = s
28
+ }
29
+
30
+ name, cron, sql = op.cmd_parse
31
+
32
+ unless db_name
33
+ $stderr.puts "-d, --database DB_NAME option is required."
34
+ exit 1
35
+ end
36
+
37
+ client = get_client
38
+
39
+ # local existance check
40
+ get_database(client, db_name)
41
+
42
+ begin
43
+ first_time = client.create_schedule(name, :cron=>cron, :query=>sql, :database=>db_name)
44
+ rescue AlreadyExistsError
45
+ cmd_debug_error $!
46
+ $stderr.puts "Schedule '#{name}' already exists."
47
+ exit 1
48
+ end
49
+
50
+ $stderr.puts "Schedule '#{name}' is created. It starts at #{first_time}."
51
+ end
52
+
53
+ def sched_delete(op)
54
+ name = op.cmd_parse
55
+
56
+ client = get_client
57
+
58
+ begin
59
+ client.delete_schedule(name)
60
+ rescue NotFoundError
61
+ cmd_debug_error $!
62
+ $stderr.puts "Schedule '#{name}' does not exist."
63
+ $stderr.puts "Use '#{$prog} sched:list' to show list of the schedules."
64
+ exit 1
65
+ end
66
+
67
+ $stderr.puts "Schedule '#{name}' is deleted."
68
+ end
69
+
70
+ def sched_history(op)
71
+ page = 0
72
+ skip = 0
73
+
74
+ op.on('-p', '--page PAGE', 'skip N pages', Integer) {|i|
75
+ page = i
76
+ }
77
+ op.on('-s', '--skip N', 'skip N schedules', Integer) {|i|
78
+ skip = i
79
+ }
80
+
81
+ name, max = op.cmd_parse
82
+
83
+ max = (max || 20).to_i
84
+
85
+ if page
86
+ skip += max * page
87
+ end
88
+
89
+ client = get_client
90
+
91
+ begin
92
+ history = client.history(name, skip, skip+max-1)
93
+ rescue NotFoundError
94
+ cmd_debug_error $!
95
+ $stderr.puts "Schedule '#{name}' does not exist."
96
+ $stderr.puts "Use '#{$prog} sched:list' to show list of the schedules."
97
+ exit 1
98
+ end
99
+
100
+ rows = []
101
+ history.each {|j|
102
+ rows << {:Time => j.scheduled_at, :JobID => j.job_id, :Status => j.status}
103
+ }
104
+
105
+ puts cmd_render_table(rows, :fields => [:Time, :JobID, :Status])
106
+ end
107
+
108
+ end
109
+ end
data/lib/td/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
 
3
- VERSION = '0.9.2'
3
+ VERSION = '0.9.3'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 2
10
- version: 0.9.2
9
+ - 3
10
+ version: 0.9.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sadayuki Furuhashi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-09 00:00:00 +09:00
18
+ date: 2011-09-13 00:00:00 +09:00
19
19
  default_executable: td
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -118,6 +118,7 @@ files:
118
118
  - lib/td/command/job.rb
119
119
  - lib/td/command/list.rb
120
120
  - lib/td/command/query.rb
121
+ - lib/td/command/sched.rb
121
122
  - lib/td/command/schema.rb
122
123
  - lib/td/command/server.rb
123
124
  - lib/td/command/table.rb