Class: OpenC3::ReingestJobModel

Inherits:
Model show all
Defined in:
lib/openc3/models/reingest_job_model.rb

Overview

Tracks one run of OpenC3::ReingestJob. The job updates this record from a background thread; the storage_controller status endpoint reads it. updated_at doubles as the heartbeat — if a Running record hasn't been touched in STALE_THRESHOLD_SEC, the status endpoint surfaces it as 'Stale'.

Constant Summary collapse

PRIMARY_KEY =
'openc3_reingest_job'
STALE_THRESHOLD_SEC =
60
STATES =
%w[Queued Running Complete Crashed Stale].freeze
PHASES =
%w[downloading enabling_dedup ingesting dedup_cooldown disabling_dedup].freeze

Instance Attribute Summary collapse

Attributes inherited from Model

#name, #plugin, #scope, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#check_disable_erb, #create, #deploy, #destroy, #destroyed?, #diff, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, set, store, store_queued, #undeploy, #update

Constructor Details

#initialize(name:, state: 'Queued', files: [], bucket: nil, path: nil, table_names: [], target_version: 'as_logged', versions_used: [], warnings: [], progress_phase: nil, progress_current: 0, progress_total: 0, packets_written: 0, dedup_enabled_by_us: [], dedup_preexisting: [], dedup_disabled_tables: [], dedup_cooldown_seconds: 60, dedup_enabled_at: nil, dedup_disabled_at: nil, error: nil, started_at: nil, finished_at: nil, updated_at: nil, plugin: nil, scope:) ⇒ ReingestJobModel

Returns a new instance of ReingestJobModel.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/openc3/models/reingest_job_model.rb', line 63

def initialize(
  name:,
  state: 'Queued',
  files: [],
  bucket: nil,
  path: nil,
  table_names: [],
  target_version: 'as_logged',
  versions_used: [],
  warnings: [],
  progress_phase: nil,
  progress_current: 0,
  progress_total: 0,
  packets_written: 0,
  dedup_enabled_by_us: [],
  dedup_preexisting: [],
  dedup_disabled_tables: [],
  dedup_cooldown_seconds: 60,
  dedup_enabled_at: nil,
  dedup_disabled_at: nil,
  error: nil,
  started_at: nil,
  finished_at: nil,
  updated_at: nil,
  plugin: nil,
  scope:
)
  super("#{scope}__#{PRIMARY_KEY}", name: name, updated_at: updated_at, plugin: plugin, scope: scope)
  @state = state
  @files = files
  @bucket = bucket
  @path = path
  @table_names = table_names
  @target_version = target_version
  @versions_used = versions_used
  @warnings = warnings
  @progress_phase = progress_phase
  @progress_current = progress_current
  @progress_total = progress_total
  @packets_written = packets_written
  @dedup_enabled_by_us = dedup_enabled_by_us
  @dedup_preexisting = dedup_preexisting
  @dedup_disabled_tables = dedup_disabled_tables
  @dedup_cooldown_seconds = dedup_cooldown_seconds
  @dedup_enabled_at = dedup_enabled_at
  @dedup_disabled_at = dedup_disabled_at
  @error = error
  @started_at = started_at
  @finished_at = finished_at
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



30
31
32
# File 'lib/openc3/models/reingest_job_model.rb', line 30

def bucket
  @bucket
end

#dedup_cooldown_secondsObject

Returns the value of attribute dedup_cooldown_seconds.



43
44
45
# File 'lib/openc3/models/reingest_job_model.rb', line 43

def dedup_cooldown_seconds
  @dedup_cooldown_seconds
end

#dedup_disabled_atObject

Returns the value of attribute dedup_disabled_at.



45
46
47
# File 'lib/openc3/models/reingest_job_model.rb', line 45

def dedup_disabled_at
  @dedup_disabled_at
end

#dedup_disabled_tablesObject

Returns the value of attribute dedup_disabled_tables.



42
43
44
# File 'lib/openc3/models/reingest_job_model.rb', line 42

def dedup_disabled_tables
  @dedup_disabled_tables
end

#dedup_enabled_atObject

Returns the value of attribute dedup_enabled_at.



44
45
46
# File 'lib/openc3/models/reingest_job_model.rb', line 44

def dedup_enabled_at
  @dedup_enabled_at
end

#dedup_enabled_by_usObject

Returns the value of attribute dedup_enabled_by_us.



40
41
42
# File 'lib/openc3/models/reingest_job_model.rb', line 40

def dedup_enabled_by_us
  @dedup_enabled_by_us
end

#dedup_preexistingObject

Returns the value of attribute dedup_preexisting.



41
42
43
# File 'lib/openc3/models/reingest_job_model.rb', line 41

def dedup_preexisting
  @dedup_preexisting
end

#errorObject

Returns the value of attribute error.



46
47
48
# File 'lib/openc3/models/reingest_job_model.rb', line 46

def error
  @error
end

#filesObject

Returns the value of attribute files.



29
30
31
# File 'lib/openc3/models/reingest_job_model.rb', line 29

def files
  @files
end

#finished_atObject

Returns the value of attribute finished_at.



48
49
50
# File 'lib/openc3/models/reingest_job_model.rb', line 48

def finished_at
  @finished_at
end

#packets_writtenObject

Returns the value of attribute packets_written.



39
40
41
# File 'lib/openc3/models/reingest_job_model.rb', line 39

def packets_written
  @packets_written
end

#pathObject

Returns the value of attribute path.



31
32
33
# File 'lib/openc3/models/reingest_job_model.rb', line 31

def path
  @path
end

#progress_currentObject

Returns the value of attribute progress_current.



37
38
39
# File 'lib/openc3/models/reingest_job_model.rb', line 37

def progress_current
  @progress_current
end

#progress_phaseObject

Returns the value of attribute progress_phase.



36
37
38
# File 'lib/openc3/models/reingest_job_model.rb', line 36

def progress_phase
  @progress_phase
end

#progress_totalObject

Returns the value of attribute progress_total.



38
39
40
# File 'lib/openc3/models/reingest_job_model.rb', line 38

def progress_total
  @progress_total
end

#started_atObject

Returns the value of attribute started_at.



47
48
49
# File 'lib/openc3/models/reingest_job_model.rb', line 47

def started_at
  @started_at
end

#stateObject

Returns the value of attribute state.



28
29
30
# File 'lib/openc3/models/reingest_job_model.rb', line 28

def state
  @state
end

#table_namesObject

Returns the value of attribute table_names.



32
33
34
# File 'lib/openc3/models/reingest_job_model.rb', line 32

def table_names
  @table_names
end

#target_versionObject

Returns the value of attribute target_version.



33
34
35
# File 'lib/openc3/models/reingest_job_model.rb', line 33

def target_version
  @target_version
end

#versions_usedObject

Returns the value of attribute versions_used.



34
35
36
# File 'lib/openc3/models/reingest_job_model.rb', line 34

def versions_used
  @versions_used
end

#warningsObject

Returns the value of attribute warnings.



35
36
37
# File 'lib/openc3/models/reingest_job_model.rb', line 35

def warnings
  @warnings
end

Class Method Details

.all(scope:) ⇒ Object



58
59
60
61
# File 'lib/openc3/models/reingest_job_model.rb', line 58

def self.all(scope:)
  all = super("#{scope}__#{PRIMARY_KEY}")
  all.sort_by { |_key, value| value['updated_at'] }.reverse
end

.get(name:, scope:) ⇒ Object



50
51
52
# File 'lib/openc3/models/reingest_job_model.rb', line 50

def self.get(name:, scope:)
  super("#{scope}__#{PRIMARY_KEY}", name: name)
end

.names(scope:) ⇒ Object



54
55
56
# File 'lib/openc3/models/reingest_job_model.rb', line 54

def self.names(scope:)
  super("#{scope}__#{PRIMARY_KEY}")
end

Instance Method Details

#as_json(*_a) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/openc3/models/reingest_job_model.rb', line 123

def as_json(*_a)
  {
    'name' => @name,
    'state' => stale? ? 'Stale' : @state,
    'files' => @files,
    'bucket' => @bucket,
    'path' => @path,
    'table_names' => @table_names,
    'target_version' => @target_version,
    'versions_used' => @versions_used,
    'warnings' => @warnings,
    'progress_phase' => @progress_phase,
    'progress_current' => @progress_current,
    'progress_total' => @progress_total,
    'packets_written' => @packets_written,
    'dedup_enabled_by_us' => @dedup_enabled_by_us,
    'dedup_preexisting' => @dedup_preexisting,
    'dedup_disabled_tables' => @dedup_disabled_tables,
    'dedup_cooldown_seconds' => @dedup_cooldown_seconds,
    'dedup_enabled_at' => @dedup_enabled_at,
    'dedup_disabled_at' => @dedup_disabled_at,
    'error' => @error,
    'started_at' => @started_at,
    'finished_at' => @finished_at,
    'updated_at' => @updated_at,
    'plugin' => @plugin,
    'scope' => @scope,
  }
end

#stale?Boolean

True if state is Running but the heartbeat (updated_at) is older than STALE_THRESHOLD_SEC. Callers should surface state as 'Stale' in that case.

Returns:

  • (Boolean)


116
117
118
119
120
121
# File 'lib/openc3/models/reingest_job_model.rb', line 116

def stale?
  return false unless @state == 'Running'
  return false unless @updated_at
  age_nsec = Time.now.to_nsec_from_epoch - @updated_at.to_i
  age_nsec > STALE_THRESHOLD_SEC * 1_000_000_000
end