Sha256: 88cf352d9e68db703bef15f1cecc3c8fbbc0cc8b5f7e0b3beb7fdbb7e63cda57

Contents?: true

Size: 1.27 KB

Versions: 105

Compression:

Stored size: 1.27 KB

Contents

class Wco::OfficeAction
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'wco_office_actions'

  field     :slug, type: :string
  validates :slug, uniqueness: true, allow_nil: true

  # field :descr, type: :string ## optional

  belongs_to :office_action_template, inverse_of: :office_action
  def tmpl
    office_action_template
  end

  STATUS_ACTIVE   = 'active'
  STATUS_INACTIVE = 'inactive'
  STATUSS         = [ STATUS_ACTIVE, STATUS_INACTIVE ]
  field :status, type: :string
  scope :active, ->{ where( status: STATUS_ACTIVE ) }

  field :perform_at, type: :time

  def do_run
    sch = self
    sch.update!({ status: STATUS_INACTIVE })

    begin
      eval( sch.tmpl.action_exe )
    rescue => err
      puts! err, "Wco::OfficeAction#do_run"
      ::ExceptionNotifier.notify_exception(
        err,
        data: { office_action: self }
      )
    end

    # schedule next actions & update the action
    sch.tmpl.ties.each do |tie|
      next_sch = self.class.find_or_initialize_by({
        office_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

  def to_s
    slug
  end
end
OA ||= Wco::OfficeAction

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
wco_models-3.1.0.202 app/models/wco/office_action.rb
wco_models-3.1.0.201 app/models/wco/office_action.rb
wco_models-3.1.0.199 app/models/wco/office_action.rb
wco_models-3.1.0.198 app/models/wco/office_action.rb
wco_models-3.1.0.197 app/models/wco/office_action.rb
wco_models-3.1.0.196 app/models/wco/office_action.rb
wco_models-3.1.0.195 app/models/wco/office_action.rb
wco_models-3.1.0.194 app/models/wco/office_action.rb
wco_models-3.1.0.193 app/models/wco/office_action.rb
wco_models-3.1.0.192 app/models/wco/office_action.rb
wco_models-3.1.0.191 app/models/wco/office_action.rb
wco_models-3.1.0.190 app/models/wco/office_action.rb
wco_models-3.1.0.189 app/models/wco/office_action.rb
wco_models-3.1.0.188 app/models/wco/office_action.rb
wco_models-3.1.0.187 app/models/wco/office_action.rb
wco_models-3.1.0.184 app/models/wco/office_action.rb
wco_models-3.1.0.183 app/models/wco/office_action.rb
wco_models-3.1.0.182 app/models/wco/office_action.rb
wco_models-3.1.0.181 app/models/wco/office_action.rb
wco_models-3.1.0.180 app/models/wco/office_action.rb