summaryrefslogtreecommitdiff
path: root/app/models/bulk_imports/tracker.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/bulk_imports/tracker.rb')
-rw-r--r--app/models/bulk_imports/tracker.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/bulk_imports/tracker.rb b/app/models/bulk_imports/tracker.rb
index 182c0bbaa8a..282ba9e19ac 100644
--- a/app/models/bulk_imports/tracker.rb
+++ b/app/models/bulk_imports/tracker.rb
@@ -3,6 +3,8 @@
class BulkImports::Tracker < ApplicationRecord
self.table_name = 'bulk_import_trackers'
+ alias_attribute :pipeline_name, :relation
+
belongs_to :entity,
class_name: 'BulkImports::Entity',
foreign_key: :bulk_import_entity_id,
@@ -16,6 +18,29 @@ class BulkImports::Tracker < ApplicationRecord
validates :stage, presence: true
+ DEFAULT_PAGE_SIZE = 500
+
+ scope :next_pipeline_trackers_for, -> (entity_id) {
+ entity_scope = where(bulk_import_entity_id: entity_id)
+ next_stage_scope = entity_scope.with_status(:created).select('MIN(stage)')
+
+ entity_scope.where(stage: next_stage_scope)
+ }
+
+ def self.stage_running?(entity_id, stage)
+ where(stage: stage, bulk_import_entity_id: entity_id)
+ .with_status(:created, :started)
+ .exists?
+ end
+
+ def pipeline_class
+ unless BulkImports::Stage.pipeline_exists?(pipeline_name)
+ raise NameError.new("'#{pipeline_name}' is not a valid BulkImport Pipeline")
+ end
+
+ pipeline_name.constantize
+ end
+
state_machine :status, initial: :created do
state :created, value: 0
state :started, value: 1