What's new? | Help | Directory | Sign in
Google
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
62
63
class PinggerWorker < BackgrounDRb::MetaWorker
set_worker_name :pingger_worker

attr :verbose, true
attr :numbers, true
attr :defer_seconds, true
attr :unsave, true
attr :force, true
attr :type, true

def create(args = nil)
# this method is called, when worker is loaded for the first time
@verbose = nil
@unsave = nil
@force = nil
@type = nil
@numbers = 10
@defer_seconds = 600
puts "Starting pingger_worker"
end

def async_send
if @force
pings = DonPing.find(:all, :limit => @numbers,:order => "id DESC")
elsif @defer_seconds
pings = DonPing.find(:all, :conditions => ["counter = 0 OR (counter < 10 AND created_at + INTERVAL '?' * POW(2, counter) SECOND < NOW() AND ( send_at IS NULL OR NOT status = 'success' ))", @defer_seconds],
:limit => @numbers,
:order => "id DESC"
)
else
pings = DonPing.find(:all, :conditions => ["send_at IS NULL OR NOT status = 'success'"],
:limit => @numbers,
:order => "id DESC"
)
end
puts 'Number of ping(s) is ' + pings.length.to_s if @verbose
pings.each do |ping|
pingok, rbody = ping.send_ping2a(@type)
ping.counter += 1

if pingok
ping.send_at = Time.now
ping.status = 'success'
else
ping.status = 'error'
puts 'ping error'
puts rbody if @verbose
end
if rbody
ping.response_body = rbody
end
puts ping.url
puts ping.url if @verbose
if @unsave
puts 'skip DonPing.save' if @verbose
else
ping.save
end
end
end

end

Show details Hide details

Change log

r323 by yasuhiro on Dec 23, 2007   Diff
2007-12-23  ARAKI Yasuhiro
<ar@debian.org>

        * lib/workers/pingger_worker.rb
(PinggerWorker::create): Fix to use defe
r_seconds
Go to: 
Project members, sign in to write a code review

Older revisions

r321 by yasuhiro on Dec 21, 2007   Diff
small fix
r313 by yasuhiro on Dec 19, 2007   Diff
* Pinnger with BackgrounDRb.
* Initial password/username setting in
config/environment.example.rb.
* and some fix..
All revisions of this file

File info

Size: 1747 bytes, 63 lines