Class: Action

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/action.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.ignored_exceptionsObject

Returns the value of attribute ignored_exceptions.



28
29
30
# File 'app/models/action.rb', line 28

def ignored_exceptions
  @ignored_exceptions
end

Class Method Details

.record(action_name, params, trigger) ⇒ 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/action.rb', line 34

def record(action_name, params, trigger)
  action = create!(name: action_name, started_at: Time.now, trigger: trigger, params: params)
  begin
    exception = nil

    Houston.reconnect do
      yield
    end

  rescue *ignored_exceptions

    # Note that the action failed, but do not report _these_ exceptions
    exception = $!

  rescue Exception # rescues StandardError by default; but we want to rescue and report all errors

    # Report all other exceptions
    exception = $!
    Houston.report_exception($!, parameters: {
      action_id: action.id,
      action_name: action_name,
      trigger: trigger,
      params: params
    })

  ensure
    begin
      Houston.reconnect do
        action.finish! exception
      end
    rescue Exception # rescues StandardError by default; but we want to rescue and report all errors
      Houston.report_exception($!, parameters: {
        action_id: action.id,
        action_name: action_name,
        trigger: trigger,
        params: params
      })
    end
  end
end

.started_before(time) ⇒ Object



30
31
32
# File 'app/models/action.rb', line 30

def started_before(time)
  where arel_table[:started_at].lteq time
end

Instance Method Details

#durationObject



90
91
92
93
# File 'app/models/action.rb', line 90

def duration
  return nil unless finished?
  finished_at - started_at
end

#exception=(exception) ⇒ Object



82
83
84
# File 'app/models/action.rb', line 82

def exception=(exception)
  self.error = Error.find_or_create_for_exception(exception) if exception
end

#finish!(exception) ⇒ Object



86
87
88
# File 'app/models/action.rb', line 86

def finish!(exception)
  update_attributes! finished_at: Time.now, succeeded: exception.nil?, exception: exception
end

#finished?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/action.rb', line 95

def finished?
  finished_at.present?
end

#in_progress?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/action.rb', line 99

def in_progress?
  finished_at.nil?
end

#retry!Object



78
79
80
# File 'app/models/action.rb', line 78

def retry!
  Houston.actions.run name, params
end