egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Run a proc delayed

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Elfriede
Halfop


Joined: 07 Aug 2007
Posts: 67

PostPosted: Fri Sep 17, 2010 3:05 am    Post subject: Run a proc delayed Reply with quote

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
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Sat Sep 18, 2010 10:55 am    Post subject: Reply with quote

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 Smile
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Sep 18, 2010 12:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
Elfriede
Halfop


Joined: 07 Aug 2007
Posts: 67

PostPosted: Sun Sep 19, 2010 9:52 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Sep 19, 2010 3:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
game_over
Voice


Joined: 26 Apr 2007
Posts: 29

PostPosted: Tue Sep 21, 2010 5:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber