Module: Gzr::Plan
- Included in:
- Commands::Dashboard::Cat, Commands::Dashboard::Import, Commands::Look::Cat, Commands::Look::Import, Commands::Plan::Cat, Commands::Plan::Disable, Commands::Plan::Enable, Commands::Plan::Failures, Commands::Plan::Import, Commands::Plan::Ls, Commands::Plan::Rm, Commands::Plan::RunIt
- Defined in:
- lib/gzr/modules/plan.rb
Instance Method Summary collapse
- #create_scheduled_plan(plan) ⇒ Object
- #delete_scheduled_plan(plan_id) ⇒ Object
- #query_all_scheduled_plans(user_id, fields = nil) ⇒ Object
- #query_scheduled_plan(plan_id, fields = nil) ⇒ Object
- #query_scheduled_plans_for_dashboard(dashboard_id, user_id, fields = nil) ⇒ Object
- #query_scheduled_plans_for_look(look_id, user_id, fields = nil) ⇒ Object
- #run_scheduled_plan(plan) ⇒ Object
- #update_scheduled_plan(plan_id, plan) ⇒ Object
- #upsert_plan_for_dashboard(dashboard_id, user_id, source_plan) ⇒ Object
- #upsert_plan_for_look(look_id, user_id, source_plan) ⇒ Object
- #upsert_plan_for_obj(user_id, source_plan, existing_plans) ⇒ Object
- #upsert_plans_for_dashboard(dashboard_id, user_id, source_plans) ⇒ Object
- #upsert_plans_for_look(look_id, user_id, source_plans) ⇒ Object
- #upsert_plans_for_obj(user_id, source_plans, existing_plans, &block) ⇒ Object
Instance Method Details
#create_scheduled_plan(plan) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gzr/modules/plan.rb', line 100 def create_scheduled_plan(plan) begin data = @sdk.create_scheduled_plan(plan) rescue LookerSDK::Error => e say_error "Error creating scheduled_plan(#{JSON.pretty_generate(plan)})" say_error e. raise end data end |
#delete_scheduled_plan(plan_id) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gzr/modules/plan.rb', line 89 def delete_scheduled_plan(plan_id) begin data = @sdk.delete_scheduled_plan(plan_id) rescue LookerSDK::ClientError => e say_error "Unable to delete scheduled_plan(#{plan_id})" say_error e. raise end data end |
#query_all_scheduled_plans(user_id, fields = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gzr/modules/plan.rb', line 26 def query_all_scheduled_plans(user_id,fields=nil) req = {} req[:all_users] = true if user_id == "all" req[:user_id] = user_id if user_id && !(user_id == "all") req[:fields] = fields if fields data = nil id = nil id = user_id unless user_id == "all" begin data = @sdk.all_scheduled_plans(req) rescue LookerSDK::ClientError => e say_error "Unable to get all_scheduled_plans(#{JSON.pretty_generate(req)})" say_error e. raise end data end |
#query_scheduled_plan(plan_id, fields = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gzr/modules/plan.rb', line 76 def query_scheduled_plan(plan_id,fields=nil) req = {} req[:fields] = fields if fields begin data = @sdk.scheduled_plan(plan_id,req) rescue LookerSDK::ClientError => e say_error "Unable to get scheduled_plan(#{plan_id},#{JSON.pretty_generate(req)})" say_error e. raise end data end |
#query_scheduled_plans_for_dashboard(dashboard_id, user_id, fields = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gzr/modules/plan.rb', line 60 def query_scheduled_plans_for_dashboard(dashboard_id,user_id,fields=nil) req = {} req[:all_users] = true if user_id == "all" req[:user_id] = user_id if user_id && !(user_id == "all") req[:fields] = fields if fields data = nil begin data = @sdk.scheduled_plans_for_dashboard(dashboard_id,req) rescue LookerSDK::ClientError => e say_error "Unable to get scheduled_plans_for_dashboard(#{dashboard_id},#{JSON.pretty_generate(req)})" say_error e. raise end data end |
#query_scheduled_plans_for_look(look_id, user_id, fields = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gzr/modules/plan.rb', line 44 def query_scheduled_plans_for_look(look_id,user_id,fields=nil) req = {} req[:all_users] = true if user_id == "all" req[:user_id] = user_id if user_id && !(user_id == "all") req[:fields] = fields if fields data = nil begin data = @sdk.scheduled_plans_for_look(look_id,req) rescue LookerSDK::ClientError => e say_error "Unable to get scheduled_plans_for_look(#{look_id},#{JSON.pretty_generate(req)})" say_error e. raise end data end |
#run_scheduled_plan(plan) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/gzr/modules/plan.rb', line 122 def run_scheduled_plan(plan) begin data = @sdk.scheduled_plan_run_once(plan) rescue LookerSDK::Error => e say_error "Error executing scheduled_plan_run_once(#{JSON.pretty_generate(plan)})" say_error e. raise end data end |
#update_scheduled_plan(plan_id, plan) ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gzr/modules/plan.rb', line 111 def update_scheduled_plan(plan_id,plan) begin data = @sdk.update_scheduled_plan(plan_id,plan) rescue LookerSDK::Error => e say_error "Error updating scheduled_plan(#{plan_id},#{JSON.pretty_generate(plan)})" say_error e. raise end data end |
#upsert_plan_for_dashboard(dashboard_id, user_id, source_plan) ⇒ Object
148 149 150 151 |
# File 'lib/gzr/modules/plan.rb', line 148 def upsert_plan_for_dashboard(dashboard_id,user_id,source_plan) existing_plans = query_scheduled_plans_for_dashboard(dashboard_id,"all") upsert_plan_for_obj(user_id,source_plan,existing_plans) { |p| p[:dashboard_id] = dashboard_id } end |
#upsert_plan_for_look(look_id, user_id, source_plan) ⇒ Object
143 144 145 146 |
# File 'lib/gzr/modules/plan.rb', line 143 def upsert_plan_for_look(look_id,user_id,source_plan) existing_plans = query_scheduled_plans_for_look(look_id,"all") upsert_plan_for_obj(user_id,source_plan,existing_plans) { |p| p[:look_id] = look_id } end |
#upsert_plan_for_obj(user_id, source_plan, existing_plans) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/gzr/modules/plan.rb', line 162 def upsert_plan_for_obj(user_id, source_plan, existing_plans) matches = existing_plans.select { |p| p.name == source_plan[:name] && user_id == p.user_id } if matches.length > 0 then say_ok "Modifying existing plan #{matches.first.id} #{matches.first.name}" plan = keys_to_keep('update_scheduled_plan').collect do |e| [e,nil] end.to_h plan.merge!( source_plan.select do |k,v| (keys_to_keep('update_scheduled_plan') - [:plan_id,:look_id,:dashboard_id,:user_id,:dashboard_filters,:lookml_dashboard_id,:scheduled_plan_destination]).include? k end) plan[:scheduled_plan_destination] = source_plan[:scheduled_plan_destination].collect do |p| p.reject do |k,v| [:id,:scheduled_plan_id,:looker_recipient,:can].include? k end end plan[:user_id] = user_id plan[:enabled] = true if @options[:enabled] plan[:enabled] = false if @options[:disabled] plan[:enabled] = false if plan[:enabled].nil? plan[:require_results] = false if plan[:require_results].nil? plan[:require_no_results] = false if plan[:require_no_results].nil? plan[:require_change] = false if plan[:require_change].nil? plan[:send_all_results] = false if plan[:send_all_results].nil? plan[:run_once] = false if plan[:run_once].nil? plan[:include_links] = false if plan[:include_links].nil? yield plan update_scheduled_plan(matches.first.id,plan) else plan = source_plan.select do |k,v| (keys_to_keep('create_scheduled_plan') - [:plan_id,:dashboard_id,:user_id,:dashboard_filters,:lookml_dashboard_id,:scheduled_plan_destination]).include? k end plan[:scheduled_plan_destination] = source_plan[:scheduled_plan_destination].collect do |p| p.reject do |k,v| [:id,:scheduled_plan_id,:looker_recipient,:can].include? k end end yield plan plan[:enabled] = true if @options[:enabled] plan[:enabled] = false if @options[:disabled] plan[:enabled] = false if plan[:enabled].nil? plan[:require_results] = false if plan[:require_results].nil? plan[:require_no_results] = false if plan[:require_no_results].nil? plan[:require_change] = false if plan[:require_change].nil? plan[:send_all_results] = false if plan[:send_all_results].nil? plan[:run_once] = false if plan[:run_once].nil? plan[:include_links] = false if plan[:include_links].nil? create_scheduled_plan(plan) end end |
#upsert_plans_for_dashboard(dashboard_id, user_id, source_plans) ⇒ Object
138 139 140 141 |
# File 'lib/gzr/modules/plan.rb', line 138 def upsert_plans_for_dashboard(dashboard_id,user_id,source_plans) existing_plans = query_scheduled_plans_for_dashboard(dashboard_id,"all") upsert_plans_for_obj(user_id,source_plans,existing_plans) { |p| p[:dashboard_id] = dashboard_id } end |
#upsert_plans_for_look(look_id, user_id, source_plans) ⇒ Object
133 134 135 136 |
# File 'lib/gzr/modules/plan.rb', line 133 def upsert_plans_for_look(look_id,user_id,source_plans) existing_plans = query_scheduled_plans_for_look(look_id,"all") upsert_plans_for_obj(user_id,source_plans,existing_plans) { |p| p[:look_id] = look_id } end |
#upsert_plans_for_obj(user_id, source_plans, existing_plans, &block) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/gzr/modules/plan.rb', line 153 def upsert_plans_for_obj(user_id,source_plans,existing_plans, &block) plans = nil source_plans.collect do |source_plan| plans = upsert_plan_for_obj(user_id, source_plan, existing_plans, &block) end return nil unless plans.length > 0 plans.first end |