@@ -170,55 +170,45 @@ def queue_changes(self, records: Iterable[SourceRecord], store_name: str):
170
170
for view in views :
171
171
view .queue (batch )
172
172
173
- def queue_emu_changes (self , only_one : bool = False ) -> List [date ]:
173
+ def queue_emu_changes (self ) -> Optional [date ]:
174
174
"""
175
- Look for new EMu dumps, upsert the records into the appropriate DataDB and then
176
- queue the changes into the derived views .
175
+ Look for new EMu dumps and if any are found beyond the date of the last queued
176
+ EMu import, add the next day's data to the stores and view queues .
177
177
178
- :param only_one: if True, only process the first set of dumps and then return,
179
- otherwise, process them all (default: False)
180
- :return the dates that were queued
178
+ :return the date that was queued or None if no dumps were found
181
179
"""
182
180
last_queued = self .emu_status .get ()
183
181
dump_sets = find_emu_dumps (self .config .dumps_path , after = last_queued )
184
182
if not dump_sets :
185
- return []
183
+ return None
186
184
187
- if only_one :
188
- dump_sets = dump_sets [:1 ]
185
+ next_day_dump_set = dump_sets [0 ]
189
186
190
187
store_names = {store .name for store in self .stores if store .name != "gbif" }
191
- dates_queued = []
192
- for dump_set in dump_sets :
193
- for dump in dump_set .dumps :
194
- # normal tables are immediately processable, but if the dump is from
195
- # the eaudit table we need to do some additional work because each
196
- # audit record refers to a potentially different table from which it
197
- # is deleting a record
198
- if dump .table != "eaudit" :
199
- self .queue_changes (dump .read (), dump .table )
200
- else :
201
- # wrap the dump stream in a filter to only allow through records
202
- # we want to process
203
- filtered_dump = filter (
204
- partial (is_valid_eaudit_record , tables = store_names ),
205
- dump .read (),
206
- )
207
- # queue the changes to each table's database in turn
208
- for table , records in groupby (
209
- filtered_dump , key = lambda record : record .data ["AudTable" ]
210
- ):
211
- # convert the raw audit records into delete records as we
212
- # queue them
213
- self .queue_changes (
214
- map (convert_eaudit_to_delete , records ), table
215
- )
216
- # we've handled all the dumps from this date, update the last date stored on
217
- # disk in case we fail later to avoid redoing work
218
- self .emu_status .update (dump_set .date )
219
- dates_queued .append (dump_set .date )
220
-
221
- return dates_queued
188
+ for dump in next_day_dump_set .dumps :
189
+ # normal tables are immediately processable, but if the dump is from
190
+ # the eaudit table we need to do some additional work because each
191
+ # audit record refers to a potentially different table from which it
192
+ # is deleting a record
193
+ if dump .table != "eaudit" :
194
+ self .queue_changes (dump .read (), dump .table )
195
+ else :
196
+ # wrap the dump stream in a filter to only allow through records
197
+ # we want to process
198
+ filtered_dump = filter (
199
+ partial (is_valid_eaudit_record , tables = store_names ),
200
+ dump .read (),
201
+ )
202
+ # queue the changes to each table's database in turn
203
+ for table , records in groupby (
204
+ filtered_dump , key = lambda record : record .data ["AudTable" ]
205
+ ):
206
+ # convert the raw audit records into delete records as we
207
+ # queue them
208
+ self .queue_changes (map (convert_eaudit_to_delete , records ), table )
209
+
210
+ self .emu_status .update (next_day_dump_set .date )
211
+ return next_day_dump_set .date
222
212
223
213
def queue_gbif_changes (self ):
224
214
"""
0 commit comments