Class: SlowListener
- Inherits:
-
Object
- Object
- SlowListener
- Includes:
- Logging
- Defined in:
- lib/flickrup/slow_listener.rb
Overview
modification ->
schedule upload for 5 mins time
upload run ->
for files modified > 5 mins ago
-> do upload
if there are files modified < 5 mins ago
-> schedule upload for minimum time
When scheduling upload, remove all but the nearest When paused, upload run should be a no-op
Constant Summary collapse
- IDLE =
0
- SCHEDULED =
1
- PROCESSING =
2
Instance Method Summary collapse
-
#initialize(config) ⇒ SlowListener
constructor
A new instance of SlowListener.
- #run ⇒ Object
- #schedule ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config) ⇒ SlowListener
Returns a new instance of SlowListener.
26 27 28 29 30 31 32 33 |
# File 'lib/flickrup/slow_listener.rb', line 26 def initialize(config) @wait = config[:timeout] logger.info("Timeout set to #@wait secs") @config = config @scheduler = Rufus::Scheduler.start_new @processor = Processor.new(config) @processing = Atomic.new IDLE end |
Instance Method Details
#run ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/flickrup/slow_listener.rb', line 35 def run logger.debug("Watching #{@config[:watch_dir]}...") @listener = Listen.to(@config[:watch_dir]) @listener.change(&method(:on_change)) @listener.start logger.info("Triggering initial run") schedule end |
#schedule ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/flickrup/slow_listener.rb', line 45 def schedule previous_state = @processing.swap(SCHEDULED) case previous_state when SCHEDULED #ignore, already scheduled logger.info("Already scheduled") when PROCESSING #ignore, processing thread will reschedule logger.info("Scheduling queued") when IDLE schedule_internal @wait end end |