class ShowCreator < Struct.new(:datetimes, :show_params, :chart_params, :event, :organization, :publish) # # If datetime.length < 3, the shows will create right away. Otherwise, they'll be queued # def self.enqueue(datetimes, show_params, chart_params, event, organization, publish = false) datetimes ||= [] creator = ShowCreator.new(datetimes, show_params, chart_params, event, organization, publish) if datetimes.length < 3 creator.perform else Delayed::Job.enqueue(creator) end end def perform ActiveRecord::Base.transaction do datetimes.each do |f| @show = self.event.next_show #clear the sections and replace them with whatever they entered @show.chart.sections = [] @show.chart.update_attributes_from_params(chart_params) @show.update_attributes(show_params) @show.organization = organization @show.chart_id = @show.chart.id @show.datetime = ActiveSupport::TimeZone.create(self.event.time_zone).parse(DateTime.parse(f).to_s) @show.go!(publish) end end end end