Class: ConfidenceBatchJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/confidence_batch_job.rb

Instance Method Summary collapse

Instance Method Details

#max_attemptsObject



8
9
10
# File 'app/jobs/confidence_batch_job.rb', line 8

def max_attempts
  1
end

#max_run_timeObject



4
5
6
# File 'app/jobs/confidence_batch_job.rb', line 4

def max_run_time
  1.hour
end

#perform(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: nil, project_id: nil, user_id: nil) ⇒ Object

At this point filter_query is already validated as good in terms of params, etc., see confidence.rb



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/jobs/confidence_batch_job.rb', line 13

def perform(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: nil, project_id: nil, user_id: nil)
  begin
    q = ::Queries::Query::Filter.instantiated_base_filter(filter_query)

    case mode
    when :add
      q.all.find_each do |o|
        Confidence.create(
          confidence_object: o,
          confidence_level_id:,
          by: user_id,
          project_id:,
        )
      end

    when :replace
      Confidence
        .where(
          confidence_object_id: q.all.pluck(:id),
          confidence_object_type: q.referenced_klass.name,
          confidence_object_type: q.referenced_klass.base_class.name,
          confidence_level_id: replace_confidence_level_id
        ).find_each do |c|
          c.update(confidence_level_id:)
        end
    end

  rescue  => ex
    ExceptionNotifier.notify_exception(
      ex,
      data: { project: target_project&.id, download: download&.id&.to_s }
    )
    raise
  end
end