| View previous topic :: View next topic |
| Author |
Message |
Elfriede Halfop
Joined: 07 Aug 2007 Posts: 67
|
Posted: Fri Sep 17, 2010 3:05 am Post subject: Run a proc delayed |
|
|
Hi : Its me again ^^
Here's my code:
| Code: |
} elseif {$http_status == "timeout"} {
sendmsg # "\002\00304\[ERROR\]\002\003 \002Connection timed out - $the_url ... Retrying ..."
set http_data [::http::data $http_handle]
::http::cleanup $http_handle
set File [::mysql::escape [getPage $the_url]]
.....
proc getPage { the_url } {
::http::register https 443 ::tls::socket
set token [::http::geturl $the_url -binary 1 -timeout 10000]
set data [::http::data $token]
::http::cleanup $token
return $data
}
|
As u can see i have a timeout of 10s in the getPage proc. What i'm looking for is that this part:
set File [::mysql::escape [getPage $the_url]]
would be called for eg lets say 20 seconds later, instead of needing/using such a high timeout in my getPage proc. Everything ive tried till yet ended up in errors :/ |
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Sat Sep 18, 2010 10:55 am Post subject: |
|
|
| Code: | } elseif {$http_status == "timeout"} {
sendmsg # "\002\00304\[ERROR\]\002\003 \002Connection timed out - $the_url ... Retrying ..."
set http_data [::http::data $http_handle]
::http::cleanup $http_handle
set File [::mysql::escape [getPage $the_url]]
.....
proc getPage { the_url } {
putlog "wait"
after 3000 ;# Simulates deep thought
putlog "now"
::http::register https 443 ::tls::socket
set token [::http::geturl $the_url -binary 1 -timeout 10000]
set data [::http::data $token]
::http::cleanup $token
return $data
} |
you could give this a go  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Sep 18, 2010 12:14 pm Post subject: |
|
|
I would not recommend using the after command in blocking mode, as eggdrop is single-threaded, and blocking behavior prevents the eggdrop from taking any actions at all during the block.
I'd rather recommend using the utimer command to schedule a piece of code to be executed at a later time, or if possible, use the -command option with your http-request to use an event-driven mode:
| Code: | ::http::register https 443 ::tls::socket
::http::geturl "http://www.example.com/" -binary 1 -command handle_response
proc handle_response {token} {
if {[::http::status $token] == "ok"} {
set File [::mysql::escape [::http::data $token]]
utimer 20 [list handle_final $File]
}
::http::cleanup
}
proc handle_final {File} {
#this is called 20 seconds after the http-transaction is completed...
putlog "The MySQL-escaped filename was $File"
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Elfriede Halfop
Joined: 07 Aug 2007 Posts: 67
|
Posted: Sun Sep 19, 2010 9:52 am Post subject: |
|
|
I really appreciate ur answer and im quite sure i do "understand", but im unsure how to use that on my proc. Actually it looks like:
| Code: |
::http::register https 443 ::tls::socket
if {![catch {set http_handle [http::geturl $the_url -binary 1 -timeout $::check(timeout)]} error]} {
set http_status [http::status $http_handle]
if {$http_status == "ok"} {
if {[http::ncode $http_handle] == 200} {
set http_data [::http::data $http_handle]
::http::cleanup $http_handle
set File [::mysql::escape $http_data]
::mysql::encoding $db_handle binary
set sql [::mysql::sel $db_handle "INSERT INTO ...
}
} elseif {$http_status == "timeout"} {
sendmsg $channel "\002\00304\[ERROR\]\002\003 \002Connection timed out - $the_url ... Retrying ..."
set http_data [::http::data $http_handle]
::http::cleanup $http_handle
set File [::mysql::escape [getPage $the_url]]
::mysql::encoding $db_handle binary
set sql [::mysql::sel $db_handle "INSERT INTO...
} elseif {[http::ncode $http_handle] == 404} {
|
The first part, as shown here, uses a timeout of 3 seconds. In case of timeout, ur example code should retry xx seconds delayed, but i dunno the best way to use it. May u please help  |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Sep 19, 2010 3:13 pm Post subject: |
|
|
Elfriede,
What you need to do, is to split your proc up into several pieces, thus allowing you to call the second http-transaction separately from the first one using a timer. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
game_over Voice
Joined: 26 Apr 2007 Posts: 29
|
Posted: Tue Sep 21, 2010 5:59 am Post subject: |
|
|
And why not call your procedure again. I mean
| Code: |
proc somename {args} {
....
::http::register https 443 ::tls::socket
if {![catch {set http_handle [http::geturl $the_url -binary 1 -timeout $::check(timeout)]} error]} {
set http_status [http::status $http_handle]
if {$http_status == "ok"} {
if {[http::ncode $http_handle] == 200} {
set http_data [::http::data $http_handle]
::http::cleanup $http_handle
set File [::mysql::escape $http_data]
::mysql::encoding $db_handle binary
set sql [::mysql::sel $db_handle "INSERT INTO ...
}
} elseif {$http_status == "timeout"} {
sendmsg $channel "\002\00304\[ERROR\]\002\003 \002Connection timed out - $the_url ... Retrying ..."
somename $args; #you have already defined all that you need
} elseif {[http::ncode $http_handle] == 404} {
......
}
|
if you use you method you must re-define error like -timeout again and again
, and nml375 is right after block eggdrop for some time but -timeout option all so use after in http.tcl |
|
| Back to top |
|
 |
|