Module: WorkerHelpers

Included in:
Hash, TableManager
Defined in:
lib/background/worker_helpers.rb

Instance Method Summary collapse

Instance Method Details

#delete_state!(match_id) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/background/worker_helpers.rb', line 5

def delete_state!(match_id)
  begin
    @match_id_to_background_processes.delete match_id
    match = Match.find(match_id)
  rescue
  else
    match.delete if match
  end
end

#handle_exception(match_id, e) ⇒ Object

Parameters:

  • match_id (String)

    The ID of the match in which the exception occurred.

  • e (Exception)

    The exception to log.



17
18
19
20
# File 'lib/background/worker_helpers.rb', line 17

def handle_exception(match_id, e)
  log __method__, {match_id: match_id, message: e.message, backtrace: e.backtrace}, Logger::Severity::ERROR
  delete_state! match_id
end

#match_instance(match_id) ⇒ Match

Returns The desired Match instance.

Parameters:

  • match_id (String)

    The ID of the Match instance to retrieve.

Returns:

  • (Match)

    The desired Match instance.



25
26
27
28
29
30
31
32
33
# File 'lib/background/worker_helpers.rb', line 25

def match_instance(match_id)
  begin
    match = Match.find match_id
  rescue => unable_to_find_match_exception
    handle_exception match_id, unable_to_find_match_exception
    raise unable_to_find_match_exception
  end
  match
end

#save_match_instance(match) ⇒ Object

Parameters:

  • The (Match)

    Match instance to save.



37
38
39
40
41
42
43
44
# File 'lib/background/worker_helpers.rb', line 37

def save_match_instance(match)
  begin
    match.save
  rescue => unable_to_save_match_exception
    handle_exception match.id, unable_to_save_match_exception
    raise unable_to_save_match_exception
  end
end