Class: GoodData::Schedule
- Inherits:
-
Rest::Resource
- Object
- Rest::Object
- Rest::Resource
- GoodData::Schedule
- Defined in:
- lib/gooddata/models/schedule.rb
Constant Summary collapse
- SCHEDULE_TEMPLATE =
{ :schedule => { :type => nil, :timezone => nil, :params => {}, :hiddenParams => {}, # :reschedule => nil } }
Instance Attribute Summary collapse
-
#dirty ⇒ Object
readonly
Returns the value of attribute dirty.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
Attributes inherited from Rest::Object
Class Method Summary collapse
-
.[](id, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ GoodData::Schedule|Array<GoodData::Schedule>
Looks for schedule.
-
.all(opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::Schedule>
Returns list of all schedules for active project.
-
.create(process_id, trigger, executable, options = {}) ⇒ GoodData::Schedule
Creates new schedules from parameters passed.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #after ⇒ Object
- #after=(schedule) ⇒ Object
-
#cron ⇒ String
Returns execution cron settings.
-
#cron=(new_cron) ⇒ Object
Assigns execution cron settings.
-
#delete ⇒ Object
Deletes schedule.
-
#disable ⇒ GoodData::Schedule
Disables the schedule.
-
#disable! ⇒ Boolean
Disables and saves the schedule.
-
#disabled? ⇒ Boolean
Is schedule disabled?.
-
#enable ⇒ GoodData::Schedule
Enables the schedule.
-
#enable! ⇒ GoodData::Schedule
Enables and saves the schedule.
-
#enabled? ⇒ Boolean
Is schedule enabled?.
-
#executable ⇒ String
Returns execution executable.
-
#executable=(new_executable) ⇒ Object
Assigns execution executable.
-
#execute(opts = {}) ⇒ Object
Executes schedule.
-
#execution_url ⇒ String
Returns execution URL.
-
#executions ⇒ Array
Returns enumerator of executions.
-
#hidden_params ⇒ Hash
Returns hidden_params as Hash.
-
#hidden_params=(new_hidden_params = {}) ⇒ Object
Assigns hidden parameters.
-
#initialize(json) ⇒ GoodData::Schedule
constructor
Initializes object from raw json.
- #name ⇒ Object
- #name=(name) ⇒ Object
-
#params ⇒ Hash
Returns params as Hash.
-
#params=(new_params = {}) ⇒ Object
Assigns execution parameters.
-
#process ⇒ GoodData::Process
Returns execution process related to this schedule.
-
#process_id ⇒ String
Returns execution process ID.
- #process_id=(new_project_id) ⇒ Object
-
#reschedule ⇒ Integer
Returns reschedule settings.
-
#reschedule=(new_reschedule) ⇒ Object
Assigns execution reschedule settings.
-
#save ⇒ Boolean
Saves object if dirty.
- #schedule_type ⇒ Object
- #schedule_type=(type) ⇒ Object
-
#set_hidden_parameter(k, v) ⇒ GoodData::Schedule
Updates hidden params at key k with val v.
-
#set_parameter(k, v) ⇒ GoodData::Schedule
Updates params at key k with val v.
-
#set_trigger(trigger) ⇒ Object
rubocop:disable Style/AccessorMethodName.
-
#state ⇒ String
Returns execution state.
- #state=(a_state) ⇒ Object
- #time_based? ⇒ Boolean
-
#timezone ⇒ String
Returns execution timezone.
-
#timezone=(new_timezone) ⇒ Object
Assigns execution timezone.
- #to_hash ⇒ Object
- #to_update_payload ⇒ Object
- #trigger_id ⇒ Object
- #trigger_id=(a_trigger) ⇒ Object
-
#type ⇒ String
Returns execution type.
-
#type=(new_type) ⇒ Object
Assigns execution type.
-
#update_hidden_params(params_to_merge) ⇒ GoodData::Schedule
Updates hidden params by merging the current params with new ones.
-
#update_params(params_to_merge) ⇒ GoodData::Schedule
Updates params by merging the current params with new ones.
-
#uri ⇒ String
Returns URL.
Methods included from Mixin::ObjId
Methods inherited from Rest::Object
client, default_client, #saved?
Methods included from Mixin::DataPropertyReader
Methods included from Mixin::DataPropertyWriter
Methods included from Mixin::MetaPropertyReader
Methods included from Mixin::MetaPropertyWriter
Methods included from Mixin::MetaGetter
Methods included from Mixin::DataGetter
Methods included from Mixin::RootKeyGetter
Methods included from Mixin::ContentGetter
Constructor Details
#initialize(json) ⇒ GoodData::Schedule
Initializes object from raw json
117 118 119 120 121 122 123 |
# File 'lib/gooddata/models/schedule.rb', line 117 def initialize(json) json = GoodData::Helpers.stringify_keys(json) super @json = json self.params = GoodData::Helpers.decode_params(json['schedule']['params'] || {}) self.hidden_params = GoodData::Helpers.decode_params(json['schedule']['hiddenParams'] || {}) end |
Instance Attribute Details
#dirty ⇒ Object (readonly)
Returns the value of attribute dirty.
16 17 18 |
# File 'lib/gooddata/models/schedule.rb', line 16 def dirty @dirty end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
16 17 18 |
# File 'lib/gooddata/models/schedule.rb', line 16 def json @json end |
Class Method Details
.[](id, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ GoodData::Schedule|Array<GoodData::Schedule>
Looks for schedule
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gooddata/models/schedule.rb', line 32 def [](id, opts = { :client => GoodData.connection, :project => GoodData.project }) c, project = GoodData.get_client_and_project(opts) if id == :all GoodData::Schedule.all(opts) else if id =~ %r{\/gdc\/projects\/[a-zA-Z\d]+\/schedules\/?[a-zA-Z\d]*} url = id tmp = c.get url return c.create(GoodData::Schedule, tmp) end tmp = c.get "/gdc/projects/#{project.pid}/schedules/#{id}" c.create(GoodData::Schedule, tmp, project: project) end end |
.all(opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ Array<GoodData::Schedule>
Returns list of all schedules for active project
51 52 53 54 55 56 |
# File 'lib/gooddata/models/schedule.rb', line 51 def all(opts = { :client => GoodData.connection, :project => GoodData.project }) c, project = GoodData.get_client_and_project(opts) tmp = c.get "/gdc/projects/#{project.pid}/schedules" tmp['schedules']['items'].map { |schedule| c.create(GoodData::Schedule, schedule, project: project) } end |
.create(process_id, trigger, executable, options = {}) ⇒ GoodData::Schedule
Creates new schedules from parameters passed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gooddata/models/schedule.rb', line 65 def create(process_id, trigger, executable, = {}) c, project = GoodData.get_client_and_project() fail 'Process ID has to be provided' if process_id.blank? is_dataload_process = Process[process_id, project: project, client: c].type == :dataload if is_dataload_process dataload_datasets = [:dataload_datasets] || ['GDC_DATALOAD_DATASETS'] dataload_datasets = '[]' unless dataload_datasets de_synchronize_all = [:de_synchronize_all] || ['GDC_DE_SYNCHRONIZE_ALL'] de_synchronize_all = 'true' unless de_synchronize_all else fail 'Executable has to be provided' if executable.blank? end fail 'Trigger schedule has to be provided' if trigger.blank? schedule = c.create(GoodData::Schedule, GoodData::Helpers.stringify_keys(GoodData::Helpers.deep_dup(SCHEDULE_TEMPLATE)), client: c, project: project) params = { 'PROCESS_ID' => process_id } if is_dataload_process params['GDC_DATALOAD_DATASETS'] = dataload_datasets params['GDC_DE_SYNCHRONIZE_ALL'] = de_synchronize_all else params['EXECUTABLE'] = executable end default_opts = { :type => 'MSETL', :timezone => 'UTC', :state => 'ENABLED', :params => params, # :reschedule => nil } schedule.name = [:name] schedule.set_trigger(trigger) schedule.params = default_opts[:params].merge([:params] || {}) schedule.hidden_params = [:hidden_params] || {} schedule.timezone = [:timezone] || default_opts[:timezone] schedule.state = [:state] || default_opts[:state] schedule.schedule_type = [:type] || default_opts[:type] schedule.reschedule = [:reschedule] if [:reschedule] schedule end |
Instance Method Details
#==(other) ⇒ Object
512 513 514 |
# File 'lib/gooddata/models/schedule.rb', line 512 def ==(other) other.respond_to?(:uri) && other.uri == uri && other.respond_to?(:to_hash) && other.to_hash == to_hash end |
#after ⇒ Object
125 126 127 |
# File 'lib/gooddata/models/schedule.rb', line 125 def after project.schedules(trigger_id) if trigger_id end |
#after=(schedule) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/gooddata/models/schedule.rb', line 129 def after=(schedule) fail 'After trigger has to be a schedule object' unless schedule.is_a?(Schedule) json['schedule']['triggerScheduleId'] = schedule.obj_id @json['schedule']['cron'] = nil @dirty = true end |
#cron ⇒ String
Returns execution cron settings
258 259 260 |
# File 'lib/gooddata/models/schedule.rb', line 258 def cron @json['schedule']['cron'] end |
#cron=(new_cron) ⇒ Object
Assigns execution cron settings
265 266 267 268 269 |
# File 'lib/gooddata/models/schedule.rb', line 265 def cron=(new_cron) @json['schedule']['cron'] = new_cron @json['schedule']['triggerScheduleId'] = nil @dirty = true end |
#delete ⇒ Object
Deletes schedule
137 138 139 |
# File 'lib/gooddata/models/schedule.rb', line 137 def delete saved? ? client.delete(uri) : nil end |
#disable ⇒ GoodData::Schedule
Disables the schedule.
144 145 146 147 148 |
# File 'lib/gooddata/models/schedule.rb', line 144 def disable @json['schedule']['state'] = 'DISABLED' @dirty = true self end |
#disable! ⇒ Boolean
Disables and saves the schedule.
153 154 155 156 |
# File 'lib/gooddata/models/schedule.rb', line 153 def disable! disable save end |
#disabled? ⇒ Boolean
Is schedule disabled?
161 162 163 |
# File 'lib/gooddata/models/schedule.rb', line 161 def disabled? state == 'DISABLED' end |
#enable ⇒ GoodData::Schedule
Enables the schedule
175 176 177 178 179 |
# File 'lib/gooddata/models/schedule.rb', line 175 def enable @json['schedule']['state'] = 'ENABLED' @dirty = true self end |
#enable! ⇒ GoodData::Schedule
Enables and saves the schedule
184 185 186 187 |
# File 'lib/gooddata/models/schedule.rb', line 184 def enable! enable save end |
#enabled? ⇒ Boolean
Is schedule enabled?
168 169 170 |
# File 'lib/gooddata/models/schedule.rb', line 168 def enabled? !disabled? end |
#executable ⇒ String
Returns execution executable
308 309 310 |
# File 'lib/gooddata/models/schedule.rb', line 308 def executable @json['schedule']['params']['EXECUTABLE'] end |
#executable=(new_executable) ⇒ Object
Assigns execution executable
315 316 317 318 |
# File 'lib/gooddata/models/schedule.rb', line 315 def executable=(new_executable) @json['schedule']['params']['EXECUTABLE'] = new_executable @dirty = true end |
#execute(opts = {}) ⇒ Object
Executes schedule
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/gooddata/models/schedule.rb', line 194 def execute(opts = {}) return nil unless saved? opts = { :wait => true }.merge(opts) data = { :execution => {} } res = client.post(execution_url, data) execution = client.create(GoodData::Execution, res, client: client, project: project) return execution unless opts[:wait] execution.wait_for_result(opts) end |
#execution_url ⇒ String
Returns execution URL
210 211 212 |
# File 'lib/gooddata/models/schedule.rb', line 210 def execution_url saved? ? @json['schedule']['links']['executions'] : nil end |
#executions ⇒ Array
Returns enumerator of executions
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/gooddata/models/schedule.rb', line 323 def executions return nil unless @json url = @json['schedule']['links']['executions'] Enumerator.new do |y| loop do res = client.get url res['executions']['paging']['next'] res['executions']['items'].each do |execution| y << client.create(Execution, execution, :project => project) end url = res['executions']['paging']['next'] break unless url end end end |
#hidden_params ⇒ Hash
Returns hidden_params as Hash
342 343 344 |
# File 'lib/gooddata/models/schedule.rb', line 342 def hidden_params @json['schedule']['hiddenParams'] end |
#hidden_params=(new_hidden_params = {}) ⇒ Object
Assigns hidden parameters
373 374 375 376 377 |
# File 'lib/gooddata/models/schedule.rb', line 373 def hidden_params=(new_hidden_params = {}) @json['schedule']['hiddenParams'] = GoodData::Helpers.stringify_values(new_hidden_params) @dirty = true self end |
#name ⇒ Object
485 486 487 |
# File 'lib/gooddata/models/schedule.rb', line 485 def name json['schedule']['name'] end |
#name=(name) ⇒ Object
489 490 491 492 493 |
# File 'lib/gooddata/models/schedule.rb', line 489 def name=(name) json['schedule']['name'] = name @dirty = true self end |
#params ⇒ Hash
Returns params as Hash
382 383 384 |
# File 'lib/gooddata/models/schedule.rb', line 382 def params @json['schedule']['params'] end |
#params=(new_params = {}) ⇒ Object
Assigns execution parameters
389 390 391 392 393 394 395 396 397 |
# File 'lib/gooddata/models/schedule.rb', line 389 def params=(new_params = {}) default_params = { 'PROCESS_ID' => process_id, 'EXECUTABLE' => executable } @json['schedule']['params'] = default_params.merge(GoodData::Helpers.stringify_values(new_params)) @dirty = true self end |
#process ⇒ GoodData::Process
Returns execution process related to this schedule
289 290 291 |
# File 'lib/gooddata/models/schedule.rb', line 289 def process project.processes(process_id) end |
#process_id ⇒ String
Returns execution process ID
296 297 298 |
# File 'lib/gooddata/models/schedule.rb', line 296 def process_id @json['schedule']['params']['PROCESS_ID'] end |
#process_id=(new_project_id) ⇒ Object
300 301 302 303 |
# File 'lib/gooddata/models/schedule.rb', line 300 def process_id=(new_project_id) @json['schedule']['params']['PROCESS_ID'] = new_project_id @dirty = true end |
#reschedule ⇒ Integer
Returns reschedule settings
274 275 276 |
# File 'lib/gooddata/models/schedule.rb', line 274 def reschedule @json['schedule']['reschedule'] end |
#reschedule=(new_reschedule) ⇒ Object
Assigns execution reschedule settings
281 282 283 284 |
# File 'lib/gooddata/models/schedule.rb', line 281 def reschedule=(new_reschedule) @json['schedule']['reschedule'] = new_reschedule @dirty = true end |
#save ⇒ Boolean
Saves object if dirty
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/gooddata/models/schedule.rb', line 402 def save fail 'trigger schedule has to be provided' if cron.blank? && trigger_id.blank? fail 'A timezone has to be provided' if timezone.blank? fail 'Schedule type has to be provided' if schedule_type.blank? if @dirty if saved? puts JSON.pretty_generate(to_update_payload) res = client.put(uri, to_update_payload) @json = Schedule.new(res).json else res = client.post "/gdc/projects/#{project.pid}/schedules", to_update_payload fail 'Unable to create new schedule' if res.nil? new_obj_json = client.get res['schedule']['links']['self'] @json = Schedule.new(new_obj_json).json end @dirty = false end self end |
#schedule_type ⇒ Object
444 445 446 |
# File 'lib/gooddata/models/schedule.rb', line 444 def schedule_type json['schedule']['type'] end |
#schedule_type=(type) ⇒ Object
448 449 450 451 452 |
# File 'lib/gooddata/models/schedule.rb', line 448 def schedule_type=(type) json['schedule']['type'] = type @dirty = true self end |
#set_hidden_parameter(k, v) ⇒ GoodData::Schedule
Updates hidden params at key k with val v
438 439 440 441 442 |
# File 'lib/gooddata/models/schedule.rb', line 438 def set_hidden_parameter(k, v) hidden_params[k] = v @dirty = true self end |
#set_parameter(k, v) ⇒ GoodData::Schedule
Updates params at key k with val v
427 428 429 430 431 |
# File 'lib/gooddata/models/schedule.rb', line 427 def set_parameter(k, v) params[k] = v @dirty = true self end |
#set_trigger(trigger) ⇒ Object
rubocop:disable Style/AccessorMethodName
495 496 497 498 499 500 501 502 503 |
# File 'lib/gooddata/models/schedule.rb', line 495 def set_trigger(trigger) # rubocop:disable Style/AccessorMethodName if trigger.is_a?(String) && trigger =~ /[a-fA-Z0-9]{24}/ self.trigger_id = trigger elsif trigger.is_a?(GoodData::Schedule) self.trigger_id = trigger.obj_id else self.cron = trigger end end |
#state ⇒ String
Returns execution state
217 218 219 |
# File 'lib/gooddata/models/schedule.rb', line 217 def state @json['schedule']['state'] end |
#state=(a_state) ⇒ Object
221 222 223 |
# File 'lib/gooddata/models/schedule.rb', line 221 def state=(a_state) @json['schedule']['state'] = a_state end |
#time_based? ⇒ Boolean
454 455 456 |
# File 'lib/gooddata/models/schedule.rb', line 454 def time_based? cron != nil end |
#timezone ⇒ String
Returns execution timezone
228 229 230 |
# File 'lib/gooddata/models/schedule.rb', line 228 def timezone @json['schedule']['timezone'] end |
#timezone=(new_timezone) ⇒ Object
Assigns execution timezone
235 236 237 238 |
# File 'lib/gooddata/models/schedule.rb', line 235 def timezone=(new_timezone) @json['schedule']['timezone'] = new_timezone @dirty = true end |
#to_hash ⇒ Object
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/gooddata/models/schedule.rb', line 458 def to_hash { name: name, type: type, state: state, params: params, hidden_params: hidden_params, cron: cron, trigger_id: trigger_id, timezone: timezone, uri: uri, reschedule: reschedule, executable: executable, process_id: process_id } end |
#to_update_payload ⇒ Object
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/gooddata/models/schedule.rb', line 516 def to_update_payload res = { 'schedule' => { 'name' => name, 'type' => type, 'state' => state, 'timezone' => timezone, 'cron' => cron, 'triggerScheduleId' => trigger_id, 'params' => GoodData::Helpers.encode_public_params(params), 'hiddenParams' => GoodData::Helpers.encode_hidden_params(hidden_params) } } res['schedule']['reschedule'] = reschedule if reschedule res end |
#trigger_id ⇒ Object
475 476 477 |
# File 'lib/gooddata/models/schedule.rb', line 475 def trigger_id json['schedule']['triggerScheduleId'] end |
#trigger_id=(a_trigger) ⇒ Object
479 480 481 482 483 |
# File 'lib/gooddata/models/schedule.rb', line 479 def trigger_id=(a_trigger) json['schedule']['triggerScheduleId'] = a_trigger @dirty = true self end |
#type ⇒ String
Returns execution type
243 244 245 |
# File 'lib/gooddata/models/schedule.rb', line 243 def type @json['schedule']['type'] end |
#type=(new_type) ⇒ Object
Assigns execution type
250 251 252 253 |
# File 'lib/gooddata/models/schedule.rb', line 250 def type=(new_type) @json['schedule']['type'] = new_type @dirty = true end |
#update_hidden_params(params_to_merge) ⇒ GoodData::Schedule
Updates hidden params by merging the current params with new ones
362 363 364 365 366 367 368 |
# File 'lib/gooddata/models/schedule.rb', line 362 def update_hidden_params(params_to_merge) params_to_merge.each do |k, v| set_hidden_parameter(k, v) end @dirty = true self end |
#update_params(params_to_merge) ⇒ GoodData::Schedule
Updates params by merging the current params with new ones
350 351 352 353 354 355 356 |
# File 'lib/gooddata/models/schedule.rb', line 350 def update_params(params_to_merge) params_to_merge.each do |k, v| set_parameter(k, v) end @dirty = true self end |
#uri ⇒ String
Returns URL
508 509 510 |
# File 'lib/gooddata/models/schedule.rb', line 508 def uri @json['schedule']['links']['self'] if @json && @json['schedule'] && @json['schedule']['links'] end |