Module: SpatialFeatures::QueuedSpatialProcessing

Extended by:
ActiveSupport::Concern
Included in:
FeatureImport
Defined in:
lib/spatial_features/has_spatial_features/queued_spatial_processing.rb

Defined Under Namespace

Classes: SpatialProcessingJob

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.update_cached_status(record, method_name, state) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 6

def self.update_cached_status(record, method_name, state)
  return unless record.has_attribute?(:spatial_processing_status_cache)

  cache = record.spatial_processing_status_cache
  cache[method_name] = state
  record.spatial_processing_status_cache = cache
  record.update_column(:spatial_processing_status_cache, cache) if record.will_save_change_to_spatial_processing_status_cache?
end

Instance Method Details

#clear_feature_update_error_statusObject



38
39
40
41
42
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 38

def clear_feature_update_error_status
  with_lock do
    SpatialFeatures::QueuedSpatialProcessing.update_cached_status(self, :update_features!, nil) if updating_features_failed?
  end
end

#delay_update_features!(*args, priority: priority_offset + 0, **kwargs) ⇒ Object



25
26
27
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 25

def delay_update_features!(*args, priority: priority_offset + 0, **kwargs)
  queue_spatial_task('update_features!', *args, priority:, **kwargs)
end

#failed_feature_update_jobsObject



81
82
83
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 81

def failed_feature_update_jobs
  spatial_processing_jobs('update_features!').where.not(failed_at: nil)
end

#feature_update_errorObject



69
70
71
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 69

def feature_update_error
  (failed_feature_update_jobs.first.try(:last_error) || '').split("\n").first
end

#queue_update_spatial_cache(*args, priority: priority_offset + 1, **kwargs) ⇒ Object



21
22
23
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 21

def queue_update_spatial_cache(*args, priority: priority_offset + 1, **kwargs)
  queue_spatial_task('update_spatial_cache', *args, priority:, **kwargs)
end

#queued_feature_update_jobsObject



77
78
79
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 77

def queued_feature_update_jobs
  spatial_processing_jobs('update_features!').where(failed_at: nil, locked_at: nil)
end

#running_feature_update_jobsObject



73
74
75
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 73

def running_feature_update_jobs
  spatial_processing_jobs('update_features!').where(failed_at: nil).where.not(locked_at: nil)
end

#spatial_processing_jobs(method_name = nil) ⇒ Object



85
86
87
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 85

def spatial_processing_jobs(method_name = nil)
  Delayed::Job.where('queue LIKE ?', "#{spatial_processing_queue_name}#{method_name}%")
end

#spatial_processing_status(method_name, use_cache: true) ⇒ Object



48
49
50
51
52
53
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 48

def spatial_processing_status(method_name, use_cache: true)
  if has_attribute?(:spatial_processing_status_cache)
    update_spatial_processing_status(method_name) unless use_cache
    spatial_processing_status_cache[method_name.to_s]&.to_sym
  end
end

#spatial_processing_status_cacheObject



15
16
17
18
19
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 15

def spatial_processing_status_cache
  value = super
  return {} unless value.is_a?(Hash)
  return value
end

#update_spatial_processing_status(method_name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 55

def update_spatial_processing_status(method_name)
  latest_job = spatial_processing_jobs(method_name).last

  if !latest_job
    SpatialFeatures::QueuedSpatialProcessing.update_cached_status(self, method_name, nil)
  elsif latest_job.failed_at?
    SpatialFeatures::QueuedSpatialProcessing.update_cached_status(self, method_name, :failure)
  elsif latest_job.locked_at?
    SpatialFeatures::QueuedSpatialProcessing.update_cached_status(self, method_name, :processing)
  else
    SpatialFeatures::QueuedSpatialProcessing.update_cached_status(self, method_name, :queued)
  end
end

#updating_features?(**options) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 29

def updating_features?(**options)
  case spatial_processing_status(:update_features!, **options)
  when :queued, :processing
    true
  else
    false
  end
end

#updating_features_failed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 44

def updating_features_failed?
  spatial_processing_status(:update_features!) == :failure
end