Class: Workety::TestThread
- Inherits:
-
Object
- Object
- Workety::TestThread
- Defined in:
- lib/workety/test/test_thread.rb
Overview
Copyright 2006-2011 Stanislav Senotrusov <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Instance Method Summary collapse
-
#initialize ⇒ TestThread
constructor
Before dropping privileges.
- #join ⇒ Object
-
#start ⇒ Object
After changing privileges to some user/group.
- #stop ⇒ Object
Constructor Details
#initialize ⇒ TestThread
Before dropping privileges
18 19 20 |
# File 'lib/workety/test/test_thread.rb', line 18 def initialize STDOUT.write "#{self.class} init, pid #{Process.pid}\n" end |
Instance Method Details
#join ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/workety/test/test_thread.rb', line 75 def join STDOUT.write "#{self.class} join\n" @t.join @ws.join STDOUT.write "#{self.class} done join\n" STDOUT.write "#{self.class} sleep\n" #sleep 30 STDOUT.write "#{self.class} done sleep\n" end |
#start ⇒ Object
After changing privileges to some user/group
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 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/workety/test/test_thread.rb', line 23 def start STDOUT.write "#{self.class} start, pid #{Process.pid}\n" # nonexistant_method STDOUT.write "STDOUT test\n" STDERR.write "STDERR test\n" Thread.workety do sleep 5 bad_method end # Thread.new do # begin # sleep 5 # STDOUT.write "Workety.stop\n" # Workety.stop # rescue Exception => e # e.report! # end # end @ws = Thread.new do begin until Workety.must_stop? do STDOUT.write "Workety.must_stop?\n" sleep 1 end STDOUT.write "Workety.must_stop? is true\n" rescue Exception => e e.report! end end @t = Thread.new do 600.times do |t| STDOUT.write "#{self.class} Doing #{t}\n" sleep 1 end end # 1000.times do # Thread.new { 1000.times { Rails.logger.error "test" } } # Thread.new { 1000.times { STDOUT.write "test\n" } } # end # cat log/workety-test_thread.log |grep -v "^test$" end |
#stop ⇒ Object
85 86 87 88 |
# File 'lib/workety/test/test_thread.rb', line 85 def stop STDOUT.write "#{self.class} stop\n" @t.kill end |