Class: Gitdocs::Runner
- Inherits:
-
Object
- Object
- Gitdocs::Runner
- Defined in:
- lib/gitdocs/runner.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear_state ⇒ Object
-
#initialize(share) ⇒ Runner
constructor
A new instance of Runner.
- #root ⇒ Object
- #run ⇒ Object
- #sync_changes ⇒ Object
Constructor Details
Class Method Details
Instance Method Details
#clear_state ⇒ Object
63 64 65 |
# File 'lib/gitdocs/runner.rb', line 63 def clear_state @state = nil end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gitdocs/runner.rb', line 22 def run return false unless @repository.valid? @last_synced_revision = @repository.current_oid mutex = Mutex.new @notifier.info('Running gitdocs!', "Running gitdocs in '#{root}'") # Pull changes from remote repository syncer = proc do EM.defer(proc do mutex.synchronize { sync_changes } end, proc do EM.add_timer(@polling_interval) do syncer.call end end) end syncer.call # Listen for changes in local repository EM.defer(proc do listener = Guard::Listener.select_and_init( root, watch_all_modifications: true ) listener.on_change do |directories| directories.uniq! directories.delete_if { |d| d =~ /\/\.git/ } unless directories.empty? EM.next_tick do EM.defer(proc do mutex.synchronize { sync_changes } end, proc {}) end end end listener.start end, proc { EM.stop_reactor }) end |
#sync_changes ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/gitdocs/runner.rb', line 67 def sync_changes # Commit ################################################################# @repository.commit if @share.sync_type == 'full' # Fetch ################################################################## fetch_result = @repository.fetch return unless fetch_result == :ok return if @share.sync_type == 'fetch' # Merge ################################################################## merge_result = @repository.merge merge_result = if merge_result == :ok @notifier.merge_notification(merge_result, root) return if merge_result.is_a?(String) # Push ################################################################### result = @repository.push result = if result == :ok @notifier.push_notification(result, root) rescue => e # Rescue any standard exceptions which come from the push related # commands. This will prevent problems on a single share from killing # the entire daemon. @notifier.error("Unexpected error syncing changes in #{root}", "#{e}") end |