Class: Segmentor::Session

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/segmentor/session.rb

Overview

Session is a single segmentation session. It can be draft, in progress, or active. at any point, there is only 1 active session per segment is allowed while draft and in progress, there can be multiple sessions in progress is when a source is still generating targets and they are being saved. draft is when a session has the targets, but they are not the ones used for notification. This can be used to test a new source code for example.

Constant Summary collapse

IN_PROGRESS =

default

0
DRAFT =
1
ACTIVE =
2
ARCHIVED =
3
FAILED =
4

Instance Method Summary collapse

Instance Method Details

#mark_as_active!Object



36
37
38
39
40
41
42
# File 'lib/segmentor/session.rb', line 36

def mark_as_active!
  # only draft sessions can be made active
  raise ::Segmentor::Errors::SessionStateError, 'only draft sessions can be made active' unless status == DRAFT

  self.status = ACTIVE
  save!
end

#mark_as_archived!Object



55
56
57
58
59
60
61
62
63
# File 'lib/segmentor/session.rb', line 55

def mark_as_archived!
  # only active and failed sessions can be archived
  unless status == ACTIVE || status == FAILED
    raise ::Segmentor::Errors::SessionStateError, 'only active and failed sessions can be archived'
  end

  self.status = ARCHIVED
  save!
end

#mark_as_draft!Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/segmentor/session.rb', line 44

def mark_as_draft!
  # archived and failed sessions cannot be turned into draft
  if status == ARCHIVED || status == FAILED
    raise ::Segmentor::Errors::SessionStateError, 'failed and archived sessions cannot be turned into draft'
  end

  self.status = DRAFT
  self.reason = nil
  save!
end

#mark_as_failed!(reason) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/segmentor/session.rb', line 65

def mark_as_failed!(reason)
  # archived sessions cannot be marked as failed
  raise ::Segmentor::Errors::SessionStateError, 'archived sessions cannot be marked as failed' if status == ARCHIVED

  self.status = FAILED
  self.reason = reason
  save!
end