Class: GitRestart::Task
- Inherits:
-
Object
- Object
- GitRestart::Task
- Defined in:
- lib/git-restart/task.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#ci_task ⇒ Object
Returns the value of attribute ci_task.
-
#expect_clean_exit ⇒ Object
Returns the value of attribute expect_clean_exit.
-
#lastStatus ⇒ Object
readonly
Returns the value of attribute lastStatus.
-
#name ⇒ Object
Returns the value of attribute name.
-
#report_status ⇒ Object
Returns the value of attribute report_status.
-
#signal ⇒ Object
Returns the value of attribute signal.
-
#status_file ⇒ Object
Returns the value of attribute status_file.
-
#status_message ⇒ Object
readonly
Returns the value of attribute status_message.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Class Method Summary collapse
Instance Method Summary collapse
- #_get_statusline ⇒ Object
- #_rm_logfile ⇒ Object
- #branch ⇒ Object
- #current_commit ⇒ Object
-
#initialize {|_self| ... } ⇒ Task
constructor
A new instance of Task.
- #join ⇒ Object
- #modified ⇒ Object
- #on_branches(branches) ⇒ Object
- #runner ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #triggered? ⇒ Boolean
- #valid? ⇒ Boolean
- #watch(regEx) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Task
Returns a new instance of Task.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/git-restart/task.rb', line 54 def initialize() @statuschange_mutex = Mutex.new(); @targets = Array.new(); @watched = Array.new(); @signal = "INT" @expect_clean_exit = true; @exiting = false; @lastStatus = 0; @chdir = File.dirname(runner().current_task_file); watch(File.basename(runner().current_task_file)); yield(self); valid? @status_file ||= "/tmp/TaskLog_#{@name}_#{current_commit()}"; if(runner().next_tasks[@name]) raise TaskValidityError, "A task of name #{@name} already exists!" else runner().next_tasks[@name] = self; end end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
15 16 17 |
# File 'lib/git-restart/task.rb', line 15 def active @active end |
#ci_task ⇒ Object
Returns the value of attribute ci_task.
12 13 14 |
# File 'lib/git-restart/task.rb', line 12 def ci_task @ci_task end |
#expect_clean_exit ⇒ Object
Returns the value of attribute expect_clean_exit.
10 11 12 |
# File 'lib/git-restart/task.rb', line 10 def expect_clean_exit @expect_clean_exit end |
#lastStatus ⇒ Object (readonly)
Returns the value of attribute lastStatus.
17 18 19 |
# File 'lib/git-restart/task.rb', line 17 def lastStatus @lastStatus end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/git-restart/task.rb', line 13 def name @name end |
#report_status ⇒ Object
Returns the value of attribute report_status.
11 12 13 |
# File 'lib/git-restart/task.rb', line 11 def report_status @report_status end |
#signal ⇒ Object
Returns the value of attribute signal.
9 10 11 |
# File 'lib/git-restart/task.rb', line 9 def signal @signal end |
#status_file ⇒ Object
Returns the value of attribute status_file.
13 14 15 |
# File 'lib/git-restart/task.rb', line 13 def status_file @status_file end |
#status_message ⇒ Object (readonly)
Returns the value of attribute status_message.
18 19 20 |
# File 'lib/git-restart/task.rb', line 18 def end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
7 8 9 |
# File 'lib/git-restart/task.rb', line 7 def targets @targets end |
Class Method Details
.runner ⇒ Object
23 24 25 |
# File 'lib/git-restart/task.rb', line 23 def self.runner() return @runner; end |
.runner=(runner) ⇒ Object
20 21 22 |
# File 'lib/git-restart/task.rb', line 20 def self.runner=(runner) @runner = runner; end |
Instance Method Details
#_get_statusline ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/git-restart/task.rb', line 115 def _get_statusline() return "No status specified" unless File.exist? @status_file sMsg = "" File.open(@status_file, "r") do |sFile| sFile.each_line do |l| sMsg = l; end end return sMsg; end |
#_rm_logfile ⇒ Object
110 111 112 113 114 |
# File 'lib/git-restart/task.rb', line 110 def _rm_logfile() if File.exist?("/tmp/TaskLog_#{@name}_#{current_commit()}") then File.delete("/tmp/TaskLog_#{@name}_#{current_commit()}"); end end |
#branch ⇒ Object
30 31 32 |
# File 'lib/git-restart/task.rb', line 30 def branch() runner().current_branch(); end |
#current_commit ⇒ Object
33 34 35 |
# File 'lib/git-restart/task.rb', line 33 def current_commit() runner().current_commit(); end |
#join ⇒ Object
190 191 192 |
# File 'lib/git-restart/task.rb', line 190 def join() @executionThread.join(); end |
#modified ⇒ Object
36 37 38 |
# File 'lib/git-restart/task.rb', line 36 def modified() runner().current_modified(); end |
#on_branches(branches) ⇒ Object
48 49 50 51 52 |
# File 'lib/git-restart/task.rb', line 48 def on_branches(branches) [branches].flatten.each do |b| @active |= (b == branch()); end end |
#runner ⇒ Object
26 27 28 |
# File 'lib/git-restart/task.rb', line 26 def runner() return self.class.runner(); end |
#start ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/git-restart/task.rb', line 136 def start() puts "Starting Task: #{@name}" if @targets.empty? _report_status(:success, "No tasks to run!"); return end @executionThread = Thread.new do _report_status(:pending); @targets.each do |target| @statuschange_mutex.synchronize { break if @exiting _rm_logfile(); = { [:out, :err] => "/tmp/TaskLog_#{@name}_#{current_commit()}" } [:chdir] = @chdir if @chdir @currentPID = Process.spawn(target, ); } status = Process.wait2(@currentPID)[1]; @currentPID = nil; @lastStatus = status.exitstatus(); break unless @lastStatus == 0; end if(@lastStatus == 0) _report_status(:success); _rm_logfile(); elsif(!@exiting || @expect_clean_exit) _report_status(:failure); end end @executionThread.abort_on_exception = true; sleep 0.01 end |
#stop ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/git-restart/task.rb', line 178 def stop() puts "Stopping Task: #{@name}" return if @signal.nil? @statuschange_mutex.synchronize { @exiting = true; if(p = @currentPID) Process.kill(@signal, p); end } end |
#triggered? ⇒ Boolean
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/git-restart/task.rb', line 82 def triggered? return true if modified().nil? return true if @ci_task @watched.each do |regEx| modified().each do |f| if regEx.to_s =~ /^\(\?\-mix:\\\/(.*)\)$/ then return true if f =~ Regexp.new($1); else next unless f =~ /#{Regexp.quote(@chdir)}(.*)/ return true if $1 =~ regEx; end end end return false; end |
#valid? ⇒ Boolean
100 101 102 103 104 105 106 107 108 |
# File 'lib/git-restart/task.rb', line 100 def valid?() unless Signal.list[@signal] or @signal.nil? raise TaskValidityError, "The specified kill-signal is not valid!" end unless @name raise TaskValidityError, "A name needs to be set for identification!" end end |
#watch(regEx) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/git-restart/task.rb', line 40 def watch(regEx) if(regEx.is_a? String) regEx = Regexp.quote(regEx); end @watched << Regexp.new(regEx); end |