class Writefully::Process
Constants
- JOBS
Attributes
config[R]
Public Instance Methods
boot_listener!()
click to toggle source
this listener listens to the specified content folder queues the changes detected into the job queue
# File lib/writefully/process.rb, line 87 def boot_listener! listener = Listen.to config[:content], wait_for_delay: 2, &process_message listener.start while listener.listen? sleep 0.5 end end
connect_to_database!()
click to toggle source
connect to db
# File lib/writefully/process.rb, line 57 def connect_to_database! ActiveRecord::Base.establish_connection(Writefully.db_config) end
listen(config)
click to toggle source
# File lib/writefully/process.rb, line 29 def listen config @config = config set_title set_options log_start load_models connect_to_database! start_news_agency! start_dispatcher! boot_listener! end
load_models()
click to toggle source
# File lib/writefully/process.rb, line 50 def load_models Writefully::Source.to_load.each do |model| require File.join(config[:app_directory], 'app', 'models', model) end end
log_start()
click to toggle source
# File lib/writefully/process.rb, line 73 def log_start Writefully.logger.info("This is doctor Frasier Crane. I'm listening...") end
process_message()
click to toggle source
# File lib/writefully/process.rb, line 77 def process_message Proc.new do |modified, added, removed| queue_jobs(Indices.build_from(modified), :write) queue_jobs(Indices.build_from(added), :write) queue_jobs(Indices.build_from(removed), :remove) end end
queue_jobs(indices, action)
click to toggle source
# File lib/writefully/process.rb, line 100 def queue_jobs indices, action indices.uniq.each { |index| JOBS[action].call(index) if Source.valid_resources.include?(index[:resource]) } end
set_options()
click to toggle source
# File lib/writefully/process.rb, line 46 def set_options Writefully.options = config end
set_title()
click to toggle source
# File lib/writefully/process.rb, line 42 def set_title $0 = "Writefully #{Writefully::VERSION}" end
start_dispatcher!()
click to toggle source
Dispatcher monitors job queue and throws job at workers
# File lib/writefully/process.rb, line 62 def start_dispatcher! Tools::Dispatcher.supervise_as :dispatch Tools::Retryer.supervise_as :retryer end
start_news_agency!()
click to toggle source
Supervises the actors that manage all the work with converting content and sorting it into its place
# File lib/writefully/process.rb, line 69 def start_news_agency! NewsAgency.run! end