Class: EventsCleaner

Inherits:
Object
  • Object
show all
Includes:
Celluloid, ETLConsumer
Defined in:
lib/actors/events_cleaner.rb

Instance Method Summary collapse

Methods included from ETLConsumer

#consume_row, #input=, #notify_hungry, #pop_processed_row, #processed_row, #processed_row=, #start!

Methods included from ETLBase

#empty?, #eof_received?, #logger, #mark_empty!, #receive_eof, #unmark_empty!

Constructor Details

#initialize(input, parent_actor, faculty_semester, event_type) ⇒ EventsCleaner

Returns a new instance of EventsCleaner.


9
10
11
12
13
14
15
# File 'lib/actors/events_cleaner.rb', line 9

def initialize(input, parent_actor, faculty_semester, event_type)
  self.input = input
  @parent_actor = parent_actor
  @seen_event_ids = Set.new
  @faculty_semester = faculty_semester
  @event_type = event_type
end

Instance Method Details

#mark_unseen_events!(faculty_semester, seen_event_ids, event_type) ⇒ Object

Marks events in the database from currently processed faculty semester and having given type that were not generated by the current import run.

These events are marked as deleted, because their source object either disappeared from KOS(api) or semester parameters changed so that they are no longer generated.


38
39
40
41
42
43
44
45
46
# File 'lib/actors/events_cleaner.rb', line 38

def mark_unseen_events!(faculty_semester, seen_event_ids, event_type)
  Event.where(
    faculty: faculty_semester.faculty,
    semester: faculty_semester.code,
    deleted: false,
    event_type: event_type
  ).exclude(id: seen_event_ids.to_a)
  .update(deleted: true, updated_at: Sequel.function(:NOW))
end

#process_eofObject

Performs final action on stored events and then notifies parent actor with EOF message.


28
29
30
31
# File 'lib/actors/events_cleaner.rb', line 28

def process_eof
  mark_unseen_events!(@faculty_semester, @seen_event_ids, @event_type)
  Celluloid::Actor[@parent_actor].async.receive_eof
end

#process_row(saved_events) ⇒ Object

Stores an array of events for later processing by #mark_unseen_events!.

Parameters:

  • saved_events (Array<Event>)

    events that were generated by previous import steps and were synced to the database, meaning that they have their primary key set.


21
22
23
24
# File 'lib/actors/events_cleaner.rb', line 21

def process_row(saved_events)
  @seen_event_ids = @seen_event_ids + saved_events.map(&:id)
  notify_hungry
end