Class: Writefully::Process
- Inherits:
-
Object
- Object
- Writefully::Process
- Includes:
- Singleton
- Defined in:
- lib/writefully/process.rb
Constant Summary collapse
- JOBS =
{ write: -> (index) { Writefully.add_job :journalists, index.merge({task: :publish}) }, remove: -> (index) { Writefully.add_job :journalists, index.merge({task: :remove}) } }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#boot_listener! ⇒ Object
this listener listens to the specified content folder queues the changes detected into the job queue.
-
#connect_to_database! ⇒ Object
connect to db.
- #listen(config) ⇒ Object
- #load_models ⇒ Object
- #log_start ⇒ Object
- #process_message ⇒ Object
- #queue_jobs(indices, action) ⇒ Object
- #set_options ⇒ Object
- #set_title ⇒ Object
-
#start_dispatcher! ⇒ Object
Dispatcher monitors job queue and throws job at workers.
-
#start_news_agency! ⇒ Object
Supervises the actors that manage all the work with converting content and sorting it into its place.
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/writefully/process.rb', line 27 def config @config end |
Instance Method Details
#boot_listener! ⇒ Object
this listener listens to the specified content folder queues the changes detected into the job queue
87 88 89 90 91 92 93 |
# File 'lib/writefully/process.rb', line 87 def boot_listener! listener = Listen.to config[:content], wait_for_delay: 2, & listener.start while listener.listen? sleep 0.5 end end |
#connect_to_database! ⇒ Object
connect to db
57 58 59 |
# File 'lib/writefully/process.rb', line 57 def connect_to_database! ActiveRecord::Base.establish_connection(Writefully.db_config) end |
#listen(config) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/writefully/process.rb', line 29 def listen config @config = config set_title log_start load_models connect_to_database! start_news_agency! start_dispatcher! boot_listener! end |
#load_models ⇒ Object
50 51 52 53 54 |
# 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 ⇒ Object
73 74 75 |
# File 'lib/writefully/process.rb', line 73 def log_start Writefully.logger.info("This is doctor Frasier Crane. I'm listening...") end |
#process_message ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/writefully/process.rb', line 77 def 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) ⇒ Object
100 101 102 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/writefully/process.rb', line 46 def Writefully. = config end |
#set_title ⇒ Object
42 43 44 |
# File 'lib/writefully/process.rb', line 42 def set_title $0 = "Writefully #{Writefully::VERSION}" end |
#start_dispatcher! ⇒ Object
Dispatcher monitors job queue and throws job at workers
62 63 64 65 |
# File 'lib/writefully/process.rb', line 62 def start_dispatcher! Tools::Dispatcher.supervise_as :dispatch Tools::Retryer.supervise_as :retryer end |
#start_news_agency! ⇒ Object
Supervises the actors that manage all the work with converting content and sorting it into its place
69 70 71 |
# File 'lib/writefully/process.rb', line 69 def start_news_agency! NewsAgency.run! end |