Module: TreasureData::API::BulkLoad
- Included in:
- TreasureData::API
- Defined in:
- lib/td/client/api/bulk_load.rb
Defined Under Namespace
Classes: BulkLoad, BulkLoadPreview, Job
Constant Summary collapse
- LIST =
API definitions
'/v3/bulk_loads'- SESSION =
LIST + '/%s'
- JOB =
SESSION + '/jobs'
Instance Method Summary collapse
-
#bulk_load_create(name, database, table, job, opts = {}) ⇒ Object
name: String, database: String, table: String, job: BulkLoad -> BulkLoad.
-
#bulk_load_delete(name) ⇒ Object
name: String -> BulkLoad.
-
#bulk_load_guess(job) ⇒ Object
job: BulkLoad -> BulkLoad.
-
#bulk_load_history(name) ⇒ Object
name: String -> [Job].
-
#bulk_load_issue(database, table, job) ⇒ Object
job: BulkLoad -> String (job_id).
-
#bulk_load_list ⇒ Object
nil -> [BulkLoad].
-
#bulk_load_preview(job) ⇒ Object
job: BulkLoad -> BulkLoadPreview.
- #bulk_load_run(name, scheduled_time = nil) ⇒ Object
-
#bulk_load_show(name) ⇒ Object
name: String -> BulkLoad.
-
#bulk_load_update(name, job) ⇒ Object
name: String, job: BulkLoad -> BulkLoad.
Instance Method Details
#bulk_load_create(name, database, table, job, opts = {}) ⇒ Object
name: String, database: String, table: String, job: BulkLoad -> BulkLoad
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/td/client/api/bulk_load.rb', line 121 def bulk_load_create(name, database, table, job, opts = {}) job = job.dup job['name'] = name [:cron, :timezone, :delay, :time_column].each do |prop| job[prop.to_s] = opts[prop] if opts.key?(prop) end job['database'] = database job['table'] = table res = api { post(LIST, job.validate.to_json) } unless res.ok? raise_error("BulkLoadSession: #{name} create failed", res) end BulkLoad.from_json(res.body) end |
#bulk_load_delete(name) ⇒ Object
name: String -> BulkLoad
157 158 159 160 161 162 163 164 |
# File 'lib/td/client/api/bulk_load.rb', line 157 def bulk_load_delete(name) path = session_path(name) res = api { delete(path) } unless res.ok? raise_error("BulkLoadSession: #{name} delete failed", res) end BulkLoad.from_json(res.body) end |
#bulk_load_guess(job) ⇒ Object
job: BulkLoad -> BulkLoad
75 76 77 78 79 80 81 82 83 |
# File 'lib/td/client/api/bulk_load.rb', line 75 def bulk_load_guess(job) # retry_request = true path = LIST + '/guess' res = api { post(path, job.validate.to_json) } unless res.ok? raise_error('BulkLoad configuration guess failed', res) end BulkLoad.from_json(res.body) end |
#bulk_load_history(name) ⇒ Object
name: String -> [Job]
167 168 169 170 171 172 173 174 |
# File 'lib/td/client/api/bulk_load.rb', line 167 def bulk_load_history(name) path = job_path(name) res = api { get(path) } unless res.ok? raise_error("history of BulkLoadSession: #{name} retrieve failed", res) end to_ary(res, Job) end |
#bulk_load_issue(database, table, job) ⇒ Object
job: BulkLoad -> String (job_id)
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/td/client/api/bulk_load.rb', line 97 def bulk_load_issue(database, table, job) type = 'bulkload' job = job.dup job['database'] = database job['table'] = table path = "/v3/job/issue/#{e type}/#{e database}" res = api { post(path, job.validate.to_json) } unless res.ok? raise_error('BulkLoad job issuing failed', res) end js = checked_json(res.body) js['job_id'].to_s end |
#bulk_load_list ⇒ Object
nil -> [BulkLoad]
112 113 114 115 116 117 118 |
# File 'lib/td/client/api/bulk_load.rb', line 112 def bulk_load_list res = api { get(LIST) } unless res.ok? raise_error("BulkLoadSession list retrieve failed", res) end to_ary(res, BulkLoad) end |
#bulk_load_preview(job) ⇒ Object
job: BulkLoad -> BulkLoadPreview
86 87 88 89 90 91 92 93 94 |
# File 'lib/td/client/api/bulk_load.rb', line 86 def bulk_load_preview(job) # retry_request = true path = LIST + '/preview' res = api { post(path, job.validate.to_json) } unless res.ok? raise_error('BulkLoad job preview failed', res) end BulkLoadPreview.from_json(res.body) end |
#bulk_load_run(name, scheduled_time = nil) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/td/client/api/bulk_load.rb', line 176 def bulk_load_run(name, scheduled_time = nil) path = job_path(name) opts = {} opts[:scheduled_time] = scheduled_time unless scheduled_time.nil? res = api { post(path, opts) } unless res.ok? raise_error("BulkLoadSession: #{name} job create failed", res) end js = checked_json(res.body) js['job_id'].to_s end |
#bulk_load_show(name) ⇒ Object
name: String -> BulkLoad
137 138 139 140 141 142 143 144 |
# File 'lib/td/client/api/bulk_load.rb', line 137 def bulk_load_show(name) path = session_path(name) res = api { get(path) } unless res.ok? raise_error("BulkLoadSession: #{name} retrieve failed", res) end BulkLoad.from_json(res.body) end |
#bulk_load_update(name, job) ⇒ Object
name: String, job: BulkLoad -> BulkLoad
147 148 149 150 151 152 153 154 |
# File 'lib/td/client/api/bulk_load.rb', line 147 def bulk_load_update(name, job) path = session_path(name) res = api { put(path, job.validate.to_json) } unless res.ok? raise_error("BulkLoadSession: #{name} update failed", res) end BulkLoad.from_json(res.body) end |