Method: GoodData::Schedule.create

Defined in:
lib/gooddata/models/schedule.rb

.create(process_id, trigger, executable, options = {}) ⇒ GoodData::Schedule

Creates new schedules from parameters passed

Parameters:

  • process_id (String)

    Process ID

  • trigger (String|GoodData::Schedule)

    Trigger of schedule. Can be cron string or reference to another schedule.

  • executable (String)

    Execution executable

  • options (Hash) (defaults to: {})

    Optional options

Returns:



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, 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