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
Constant Summary
collapse
- WARNINGS_CACHE_KEY =
Non-fatal messages from the most recent successful feature import (e.g. parts of the source that were skipped). Stored alongside the status cache so they survive job completion, since successful Delayed::Jobs are deleted and can’t be read back.
'feature_update_warnings'.freeze
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_status ⇒ Object
#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_jobs ⇒ Object
105
106
107
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 105
def failed_feature_update_jobs
spatial_processing_jobs('update_features!').where.not(failed_at: nil)
end
|
#feature_update_error ⇒ Object
93
94
95
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 93
def feature_update_error
(failed_feature_update_jobs.first.try(:last_error) || '').split("\n").first
end
|
#feature_update_warnings ⇒ Object
53
54
55
56
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 53
def feature_update_warnings
return [] unless has_attribute?(:spatial_processing_status_cache)
Array(spatial_processing_status_cache[WARNINGS_CACHE_KEY])
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_jobs ⇒ Object
101
102
103
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 101
def queued_feature_update_jobs
spatial_processing_jobs('update_features!').where(failed_at: nil, locked_at: nil)
end
|
#running_feature_update_jobs ⇒ Object
97
98
99
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 97
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
109
110
111
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 109
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
72
73
74
75
76
77
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 72
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_cache ⇒ Object
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
|
#store_feature_update_warnings(warnings) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/spatial_features/has_spatial_features/queued_spatial_processing.rb', line 58
def store_feature_update_warnings(warnings)
return unless has_attribute?(:spatial_processing_status_cache)
cache = spatial_processing_status_cache
warnings = Array(warnings).reject(&:blank?)
if warnings.present?
cache[WARNINGS_CACHE_KEY] = warnings
else
cache.delete(WARNINGS_CACHE_KEY)
end
self.spatial_processing_status_cache = cache
update_column(:spatial_processing_status_cache, cache) if persisted? && will_save_change_to_spatial_processing_status_cache?
end
|
#update_spatial_processing_status(method_name) ⇒ Object
#updating_features?(**options) ⇒ 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
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
|