Class: TeacherTimetableSlotImport

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/actors/teacher_timetable_slot_import.rb

Overview

An actor pipeline system for importing teacher timetable slots from KOSapi.

The inputs are: faculty semester, teacher usernames for that semester, semester periods (all from the DB) and teacher timetables slots (fetched from KOSapi).

The output is events of type 'teacher_timetable_slot' that are written to the DB.

Instance Method Summary collapse

Constructor Details

#initialize(semester) ⇒ TeacherTimetableSlotImport

Returns a new instance of TeacherTimetableSlotImport.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/actors/teacher_timetable_slot_import.rb', line 18

def initialize(semester)
  @actors = []
  @semester = semester
  @actors << Actor[:teacher_source] = TeacherSource.new(
    :teacher_timetable_slot_source, semester)
  @actors << Actor[:teacher_timetable_slot_source] = TeacherTimetableSlotSource.new(
    :teacher_source, :teacher_timetable_slot_transformer, semester)
  @actors << Actor[:teacher_timetable_slot_transformer] = TeacherTimetableSlotTransformer.new(
    :teacher_timetable_slot_source, :event_destination, semester)
  @actors << Actor[:event_destination] = EventDestination.new(
    :teacher_timetable_slot_transformer, :events_cleaner)
  @actors << Actor[:events_cleaner] = EventsCleaner.new(
    :event_destination, :teacher_timetable_slot_import, semester, 'teacher_timetable_slot')
  Actor[:teacher_timetable_slot_import] = self.async
  @condition = Celluloid::Condition.new
  @logger = Logging.logger[self]
end

Instance Method Details

#receive_eofObject

Unblock #run! method by signalling condition variable.


57
58
59
# File 'lib/actors/teacher_timetable_slot_import.rb', line 57

def receive_eof
  @condition.signal
end

#run!Object

Runs the import process for the specified semester and blocks until the import is finished.


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

def run!
  @logger.info "Starting TeacherTimetableSlotImport actors for #{@semester.code} (#{@semester.faculty})."
  @actors.each do |actor|
    actor.async.start!
  end  # Send EOF message to teacher source. It will be then passed to TeacherSources
  # output after all rows are read from the database.

  Actor[:teacher_source].async.receive_eof
  @condition.wait # block current thread until condition variable is signalled
end

#shutdown!Object

Terminate all child actors and itself.


50
51
52
53
54
# File 'lib/actors/teacher_timetable_slot_import.rb', line 50

def shutdown!
  @logger.info "Terminating TeacherTimetableSlotImport actors."
  @actors.each(&:terminate)
  terminate
end