class GoodData::Schedule
Constants
- SCHEDULE_TEMPLATE
Attributes
Public Class Methods
Looks for schedule @param id [String] URL, ID of schedule or :all @return [GoodData::Schedule|Array<GoodData::Schedule>] List of schedules
# 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
Returns list of all schedules for active project @return [Array<GoodData::Schedule>] List of schedules
# 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
Creates new schedules from parameters passed
@param process_id
[String] Process
ID @param trigger [String|GoodData::Schedule] Trigger of schedule. Can be cron string or reference to another schedule. @param executable [String] Execution
executable @param options [Hash] Optional options @return [GoodData::Schedule] New GoodData::Schedule
instance
# File lib/gooddata/models/schedule.rb, line 64 def create(process_id, trigger, executable, options = {}) c, project = GoodData.get_client_and_project(options) 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 = options[:dataload_datasets] || options['GDC_DATALOAD_DATASETS'] dataload_datasets = '[]' unless dataload_datasets de_synchronize_all = options[:de_synchronize_all] || options['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 = options[:name] schedule.set_trigger(trigger) schedule.trigger_execution_status = options[:trigger_execution_status] schedule.params = default_opts[:params].merge(options[:params] || {}) schedule.hidden_params = options[:hidden_params] || {} schedule.timezone = options[:timezone] || default_opts[:timezone] schedule.state = options[:state] || default_opts[:state] schedule.schedule_type = options[:type] || default_opts[:type] schedule.reschedule = options[:reschedule] if options[:reschedule] schedule end
Initializes object from raw json
@param json [Object] Raw JSON @return [GoodData::Schedule] New GoodData::Schedule
instance
# 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
Public Instance Methods
# 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
# File lib/gooddata/models/schedule.rb, line 127 def after project.schedules(trigger_id) if trigger_id end
# 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
Returns execution cron settings
@return [String] Cron settings
# File lib/gooddata/models/schedule.rb, line 260 def cron @json['schedule']['cron'] end
Assigns execution cron settings
@param new_cron [String] Cron settings to be set
# File lib/gooddata/models/schedule.rb, line 267 def cron=(new_cron) @json['schedule']['cron'] = new_cron @json['schedule']['triggerScheduleId'] = nil @dirty = true end
Deletes schedule
# File lib/gooddata/models/schedule.rb, line 139 def delete saved? ? client.delete(uri) : nil end
Disables the schedule.
@return [GoodData::Schedule]
# File lib/gooddata/models/schedule.rb, line 146 def disable @json['schedule']['state'] = 'DISABLED' @dirty = true self end
Disables and saves the schedule.
@return [Boolean]
# File lib/gooddata/models/schedule.rb, line 155 def disable! disable save end
Is schedule disabled?
@return [Boolean]
# File lib/gooddata/models/schedule.rb, line 163 def disabled? state == 'DISABLED' end
Enables the schedule
@return [GoodData::Schedule]
# File lib/gooddata/models/schedule.rb, line 177 def enable @json['schedule']['state'] = 'ENABLED' @dirty = true self end
Enables and saves the schedule
@return [GoodData::Schedule]
# File lib/gooddata/models/schedule.rb, line 186 def enable! enable save end
Is schedule enabled?
@return [Boolean]
# File lib/gooddata/models/schedule.rb, line 170 def enabled? !disabled? end
Returns execution executable
@return [String] Executable (graph) name
# File lib/gooddata/models/schedule.rb, line 310 def executable @json['schedule']['params']['EXECUTABLE'] end
Assigns execution executable
@param new_executable [String] Executable to be set.
# File lib/gooddata/models/schedule.rb, line 317 def executable=(new_executable) @json['schedule']['params']['EXECUTABLE'] = new_executable @dirty = true end
Executes schedule
@param [Hash] opts execution options. @option opts [Boolean] :wait Wait for execution result @return [Object] Raw Response
# 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
Returns execution URL
@return [String] Executions URL
# File lib/gooddata/models/schedule.rb, line 212 def execution_url saved? ? @json['schedule']['links']['executions'] : nil end
Returns enumerator of executions
@return [Array] Raw Executions JSON
# 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
# File lib/gooddata/models/schedule.rb, line 501 def name json['schedule']['name'] end
# File lib/gooddata/models/schedule.rb, line 505 def name=(name) json['schedule']['name'] = name @dirty = true self end
Returns params as Hash
@return [Hash] Parameters
# File lib/gooddata/models/schedule.rb, line 384 def params @json['schedule']['params'] end
Assigns execution parameters
@param params [String] Params to be set
# 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
Returns execution process related to this schedule
@return [GoodData::Process] Process
ID
# File lib/gooddata/models/schedule.rb, line 291 def process project.processes(process_id) end
Returns execution process ID
@return [String] Process
ID
# File lib/gooddata/models/schedule.rb, line 298 def process_id @json['schedule']['params']['PROCESS_ID'] end
# 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
Returns reschedule settings
@return [Integer] Reschedule settings
# File lib/gooddata/models/schedule.rb, line 276 def reschedule @json['schedule']['reschedule'] end
Assigns execution reschedule settings
@param new_reschedule [Integer] Reschedule settings to be set
# File lib/gooddata/models/schedule.rb, line 283 def reschedule=(new_reschedule) @json['schedule']['reschedule'] = new_reschedule @dirty = true end
# File lib/gooddata/models/schedule.rb, line 401 def rewrite_deprecated_params params['EXECUTABLE'] = params.delete('GRAPH') if params['GRAPH'] end
Saves object if dirty
@return [Boolean] True if saved
# 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
# File lib/gooddata/models/schedule.rb, line 449 def schedule_type json['schedule']['type'] end
# File lib/gooddata/models/schedule.rb, line 453 def schedule_type=(type) json['schedule']['type'] = type @dirty = true self end
Updates params at key k with val v
@param k [String] key @param v [Object] value @return [GoodData::Schedule] Returns self
# File lib/gooddata/models/schedule.rb, line 432 def set_parameter(k, v) params[k] = v @dirty = true self end
# 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
Returns execution state
@return [String] Execution
state
# File lib/gooddata/models/schedule.rb, line 219 def state @json['schedule']['state'] end
# File lib/gooddata/models/schedule.rb, line 223 def state=(a_state) @json['schedule']['state'] = a_state end
# File lib/gooddata/models/schedule.rb, line 459 def time_based? cron != nil end
Returns execution timezone
@return [String] Execution
timezone
# File lib/gooddata/models/schedule.rb, line 230 def timezone @json['schedule']['timezone'] end
Assigns execution timezone
@param new_timezone [String] Timezone to be set
# File lib/gooddata/models/schedule.rb, line 237 def timezone=(new_timezone) @json['schedule']['timezone'] = new_timezone @dirty = true end
# 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
# 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
# File lib/gooddata/models/schedule.rb, line 491 def trigger_execution_status json['schedule']['triggerExecutionStatus'] end
# 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
# File lib/gooddata/models/schedule.rb, line 481 def trigger_id json['schedule']['triggerScheduleId'] end
# File lib/gooddata/models/schedule.rb, line 485 def trigger_id=(a_trigger) json['schedule']['triggerScheduleId'] = a_trigger @dirty = true self end
Returns execution type
@return [String] Execution
type
# File lib/gooddata/models/schedule.rb, line 245 def type @json['schedule']['type'] end
Assigns execution type
@param new_type [String] Execution
type to be set
# File lib/gooddata/models/schedule.rb, line 252 def type=(new_type) @json['schedule']['type'] = new_type @dirty = true end
Updates params by merging the current params with new ones
@param params_to_merge [Hash] params @return [GoodData::Schedule] Returns self
# 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
Returns URL
@return [String] Schedule
URL
# File lib/gooddata/models/schedule.rb, line 524 def uri @json['schedule']['links']['self'] if @json && @json['schedule'] && @json['schedule']['links'] end