class WcoEmail::EmailAction
def send_and_roll
def send_and_roll sch = self sch.update!({ status: STATUS_INACTIVE }) # send now ctx = WcoEmail::Context.create!({ email_action: sch, email_template: sch.tmpl.email_template, from_email: sch.tmpl.email_template.from_email, lead: sch.lead, send_at: Time.now, subject: sch.tmpl.email_template.subject, }) # schedule next actions & update the action sch.tmpl.ties.each do |tie| next_sch = self.class.find_or_initialize_by({ lead_id: sch.lead_id, email_action_template_id: tie.next_tmpl.id, }) next_sch.perform_at = eval(tie.next_at_exe) next_sch.status = STATUS_ACTIVE next_sch.save! end end