Class: Office::ScheduledEmailAction
- Inherits:
-
Object
- Object
- Office::ScheduledEmailAction
- Includes:
- Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- lib/office/scheduled_email_action.rb
Overview
2023-03-04 vp An instance of an EmailAction.
Constant Summary collapse
- STATE_ACTIVE =
'active'- STATE_INACTIVE =
'inactive'- STATE_TRASH =
'trash'- STATE_UNSUBSCRIBED =
'unsubscribed'- STATES =
[ STATE_ACTIVE, STATE_INACTIVE, STATE_UNSUBSCRIBED, STATE_TRASH ]
Instance Method Summary collapse
Instance Method Details
#act ⇒ Object
26 |
# File 'lib/office/scheduled_email_action.rb', line 26 def act; email_action; end |
#act=(a) ⇒ Object
27 |
# File 'lib/office/scheduled_email_action.rb', line 27 def act= a; email_action= a; end |
#ctxs ⇒ Object
30 |
# File 'lib/office/scheduled_email_action.rb', line 30 def ctxs; email_contexts; end |
#lead ⇒ Object
12 13 14 |
# File 'lib/office/scheduled_email_action.rb', line 12 def lead Lead.find( lead_id ) end |
#send_and_roll ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/office/scheduled_email_action.rb', line 34 def send_and_roll sch = self sch.update({ state: Sch::STATE_INACTIVE }) # send now ctx = Ctx.create!({ email_template_id: sch.act.tmpl.id, from_email: sch.act.tmpl.from_email, lead_id: sch.lead.id, scheduled_email_action_id: sch.act.id, send_at: Time.now, subject: sch.act.tmpl.subject, }) # schedule next actions & update the action sch.act.ties.each do |tie| next_sch = Sch.find_or_initialize_by({ lead_id: sch.lead_id, email_action_id: tie.next_email_action.id, }) next_sch.perform_at = eval(tie.next_at_exe) next_sch.state = Sch::STATE_ACTIVE next_sch.save! end end |