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.
- #rewrite_deprecated_params ⇒ Object
-
#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_execution_status ⇒ Object
- #trigger_execution_status=(trigger_execution_status) ⇒ 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
119 120 121 122 123 124 125 |
# File 'lib/gooddata/models/schedule.rb', line 119 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.
15 16 17 |
# File 'lib/gooddata/models/schedule.rb', line 15 def dirty @dirty end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
15 16 17 |
# File 'lib/gooddata/models/schedule.rb', line 15 def json @json end |
Class Method Details
.[](id, opts = { :client => GoodData.connection, :project => GoodData.project }) ⇒ GoodData::Schedule|Array<GoodData::Schedule>
Looks for schedule
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gooddata/models/schedule.rb', line 31 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
50 51 52 53 54 55 |
# File 'lib/gooddata/models/schedule.rb', line 50 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
64 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 111 112 |
# File 'lib/gooddata/models/schedule.rb', line 64 def create(process_id, trigger, executable, = {}) c, project = GoodData.get_client_and_project() fail 'Process ID has to be provided' if process_id.blank? process = Process[process_id, project: project, client: c] is_dataload_process = process.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'] else lcm_component = process.type == :lcm add_component = process.add_v2_component? executable_missing = !lcm_component && !add_component && executable.blank? fail 'Executable has to be provided' if executable_missing end 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 if 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.trigger_execution_status = [:trigger_execution_status] 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
528 529 530 |
# File 'lib/gooddata/models/schedule.rb', line 528 def ==(other) other.respond_to?(:uri) && other.uri == uri && other.respond_to?(:to_hash) && other.to_hash == to_hash end |
#after ⇒ Object
127 128 129 |
# File 'lib/gooddata/models/schedule.rb', line 127 def after project.schedules(trigger_id) if trigger_id end |
#after=(schedule) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/gooddata/models/schedule.rb', line 131 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
260 261 262 |
# File 'lib/gooddata/models/schedule.rb', line 260 def cron @json['schedule']['cron'] end |
#cron=(new_cron) ⇒ Object
Assigns execution cron settings
267 268 269 270 271 |
# File 'lib/gooddata/models/schedule.rb', line 267 def cron=(new_cron) @json['schedule']['cron'] = new_cron @json['schedule']['triggerScheduleId'] = nil @dirty = true end |
#delete ⇒ Object
Deletes schedule
139 140 141 |
# File 'lib/gooddata/models/schedule.rb', line 139 def delete saved? ? client.delete(uri) : nil end |
#disable ⇒ GoodData::Schedule
Disables the schedule.
146 147 148 149 150 |
# File 'lib/gooddata/models/schedule.rb', line 146 def disable @json['schedule']['state'] = 'DISABLED' @dirty = true self end |
#disable! ⇒ Boolean
Disables and saves the schedule.
155 156 157 158 |
# File 'lib/gooddata/models/schedule.rb', line 155 def disable! disable save end |
#disabled? ⇒ Boolean
Is schedule disabled?
163 164 165 |
# File 'lib/gooddata/models/schedule.rb', line 163 def disabled? state == 'DISABLED' end |
#enable ⇒ GoodData::Schedule
Enables the schedule
177 178 179 180 181 |
# File 'lib/gooddata/models/schedule.rb', line 177 def enable @json['schedule']['state'] = 'ENABLED' @dirty = true self end |
#enable! ⇒ GoodData::Schedule
Enables and saves the schedule
186 187 188 189 |
# File 'lib/gooddata/models/schedule.rb', line 186 def enable! enable save end |
#enabled? ⇒ Boolean
Is schedule enabled?
170 171 172 |
# File 'lib/gooddata/models/schedule.rb', line 170 def enabled? !disabled? end |
#executable ⇒ String
Returns execution executable
310 311 312 |
# File 'lib/gooddata/models/schedule.rb', line 310 def executable @json['schedule']['params']['EXECUTABLE'] end |
#executable=(new_executable) ⇒ Object
Assigns execution executable
317 318 319 320 |
# File 'lib/gooddata/models/schedule.rb', line 317 def executable=(new_executable) @json['schedule']['params']['EXECUTABLE'] = new_executable @dirty = true end |
#execute(opts = {}) ⇒ Object
Executes schedule
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/gooddata/models/schedule.rb', line 196 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
212 213 214 |
# File 'lib/gooddata/models/schedule.rb', line 212 def execution_url saved? ? @json['schedule']['links']['executions'] : nil end |
#executions ⇒ Array
Returns enumerator of executions
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/gooddata/models/schedule.rb', line 325 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
344 345 346 |
# File 'lib/gooddata/models/schedule.rb', line 344 def hidden_params @json['schedule']['hiddenParams'] end |
#hidden_params=(new_hidden_params = {}) ⇒ Object
Assigns hidden parameters
375 376 377 378 379 |
# File 'lib/gooddata/models/schedule.rb', line 375 def hidden_params=(new_hidden_params = {}) @json['schedule']['hiddenParams'] = GoodData::Helpers.stringify_values(new_hidden_params) @dirty = true self end |
#name ⇒ Object
501 502 503 |
# File 'lib/gooddata/models/schedule.rb', line 501 def name json['schedule']['name'] end |
#name=(name) ⇒ Object
505 506 507 508 509 |
# File 'lib/gooddata/models/schedule.rb', line 505 def name=(name) json['schedule']['name'] = name @dirty = true self end |
#params ⇒ Hash
Returns params as Hash
384 385 386 |
# File 'lib/gooddata/models/schedule.rb', line 384 def params @json['schedule']['params'] end |
#params=(new_params = {}) ⇒ Object
Assigns execution parameters
391 392 393 394 395 396 397 398 399 |
# File 'lib/gooddata/models/schedule.rb', line 391 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
291 292 293 |
# File 'lib/gooddata/models/schedule.rb', line 291 def process project.processes(process_id) end |
#process_id ⇒ String
Returns execution process ID
298 299 300 |
# File 'lib/gooddata/models/schedule.rb', line 298 def process_id @json['schedule']['params']['PROCESS_ID'] end |
#process_id=(new_project_id) ⇒ Object
302 303 304 305 |
# File 'lib/gooddata/models/schedule.rb', line 302 def process_id=(new_project_id) @json['schedule']['params']['PROCESS_ID'] = new_project_id @dirty = true end |
#reschedule ⇒ Integer
Returns reschedule settings
276 277 278 |
# File 'lib/gooddata/models/schedule.rb', line 276 def reschedule @json['schedule']['reschedule'] end |
#reschedule=(new_reschedule) ⇒ Object
Assigns execution reschedule settings
283 284 285 286 |
# File 'lib/gooddata/models/schedule.rb', line 283 def reschedule=(new_reschedule) @json['schedule']['reschedule'] = new_reschedule @dirty = true end |
#rewrite_deprecated_params ⇒ Object
401 402 403 |
# File 'lib/gooddata/models/schedule.rb', line 401 def rewrite_deprecated_params params['EXECUTABLE'] = params.delete('GRAPH') if params['GRAPH'] end |
#save ⇒ Boolean
Saves object if dirty
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/gooddata/models/schedule.rb', line 408 def save fail 'A timezone has to be provided' if timezone.blank? fail 'Schedule type has to be provided' if schedule_type.blank? rewrite_deprecated_params if @dirty if saved? 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
449 450 451 |
# File 'lib/gooddata/models/schedule.rb', line 449 def schedule_type json['schedule']['type'] end |
#schedule_type=(type) ⇒ Object
453 454 455 456 457 |
# File 'lib/gooddata/models/schedule.rb', line 453 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
443 444 445 446 447 |
# File 'lib/gooddata/models/schedule.rb', line 443 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
432 433 434 435 436 |
# File 'lib/gooddata/models/schedule.rb', line 432 def set_parameter(k, v) params[k] = v @dirty = true self end |
#set_trigger(trigger) ⇒ Object
rubocop:disable Style/AccessorMethodName
511 512 513 514 515 516 517 518 519 |
# File 'lib/gooddata/models/schedule.rb', line 511 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
219 220 221 |
# File 'lib/gooddata/models/schedule.rb', line 219 def state @json['schedule']['state'] end |
#state=(a_state) ⇒ Object
223 224 225 |
# File 'lib/gooddata/models/schedule.rb', line 223 def state=(a_state) @json['schedule']['state'] = a_state end |
#time_based? ⇒ Boolean
459 460 461 |
# File 'lib/gooddata/models/schedule.rb', line 459 def time_based? cron != nil end |
#timezone ⇒ String
Returns execution timezone
230 231 232 |
# File 'lib/gooddata/models/schedule.rb', line 230 def timezone @json['schedule']['timezone'] end |
#timezone=(new_timezone) ⇒ Object
Assigns execution timezone
237 238 239 240 |
# File 'lib/gooddata/models/schedule.rb', line 237 def timezone=(new_timezone) @json['schedule']['timezone'] = new_timezone @dirty = true end |
#to_hash ⇒ Object
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/gooddata/models/schedule.rb', line 463 def to_hash { name: name, type: type, state: state, params: params, hidden_params: hidden_params, cron: cron, trigger_id: trigger_id, trigger_execution_status: trigger_execution_status, timezone: timezone, uri: uri, reschedule: reschedule, executable: executable, process_id: process_id } end |
#to_update_payload ⇒ Object
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/gooddata/models/schedule.rb', line 532 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']['triggerExecutionStatus'] = trigger_execution_status if trigger_execution_status res['schedule']['reschedule'] = reschedule if reschedule res end |
#trigger_execution_status ⇒ Object
491 492 493 |
# File 'lib/gooddata/models/schedule.rb', line 491 def trigger_execution_status json['schedule']['triggerExecutionStatus'] end |
#trigger_execution_status=(trigger_execution_status) ⇒ Object
495 496 497 498 499 |
# File 'lib/gooddata/models/schedule.rb', line 495 def trigger_execution_status=(trigger_execution_status) json['schedule']['triggerExecutionStatus'] = trigger_execution_status @dirty = true self # rubocop:disable Lint/Void end |
#trigger_id ⇒ Object
481 482 483 |
# File 'lib/gooddata/models/schedule.rb', line 481 def trigger_id json['schedule']['triggerScheduleId'] end |
#trigger_id=(a_trigger) ⇒ Object
485 486 487 488 489 |
# File 'lib/gooddata/models/schedule.rb', line 485 def trigger_id=(a_trigger) json['schedule']['triggerScheduleId'] = a_trigger @dirty = true self end |
#type ⇒ String
Returns execution type
245 246 247 |
# File 'lib/gooddata/models/schedule.rb', line 245 def type @json['schedule']['type'] end |
#type=(new_type) ⇒ Object
Assigns execution type
252 253 254 255 |
# File 'lib/gooddata/models/schedule.rb', line 252 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
364 365 366 367 368 369 370 |
# File 'lib/gooddata/models/schedule.rb', line 364 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
352 353 354 355 356 357 358 |
# File 'lib/gooddata/models/schedule.rb', line 352 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
524 525 526 |
# File 'lib/gooddata/models/schedule.rb', line 524 def uri @json['schedule']['links']['self'] if @json && @json['schedule'] && @json['schedule']['links'] end |