collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Cron changes  (Read 1960 times)

0 Members and 1 Guest are viewing this topic.

Offline Wolfbiter

  • Contributor
  • *******
  • Posts: 149
  • Karma: +0/-0
    • KAZE
Cron changes
« on: October 20, 2006, 12:22:22 am »
So I started to work on changing the cron some, not because I was in need of a change right now, but because I had thought about this a while when doing other things.

With the new cron, scripts aren't executed when the bot start, but instead after the cron interval (so for instance, roster update wont happend when the bot start, but 24h later).
RightsManagement and Que both have to be edited, and change "function cron()" to "function cron($cron=false)"

I want comments on this, possible changes etc as it's not meant to be for some newbie to install into their own bot, but to make it into future versions of bebot (and for advance users who like it and doesn't want to upgrade to later bebot versions).

Code: (Bot.php - If you attempt to add this to your bot, you need to know what you're doing) [Select]
var $crons;
....
$this->crons = Array(
"1sec"=>1,
"2sec"=>2,
"5sec"=>5,
"10sec"=>10,
"30sec"=>30,
"1min"=>60,
"2min"=>(2*60),
"5min"=>(5*60),
"1hour"=>(60*60),
"3hour"=>(3*60*60),
"6hour"=>(6*60*60),
"12hour"=>(12*60*60),
"18hour"=>(18*60*60),
"24hour"=>(24*60*60)
);

.....
function cron() {
$time = time();

foreach($this->crons as $cron => $timer) {
if (!isset($this->crontimer[$cron]) && !empty($this->cron[$cron]))
$this->crontimer[$cron] = time() + $timer; //Thoguht about using $this->crondelay here, but this way timers will actually be set with their timer from when they're set instead of from when bot starts
elseif (isset($this->crontimer[$cron]) && (empty($this->cron[$cron]) || !isset($this->cron[$cron])))
unset($this->crontimer[$cron]); //Unset if there's no active cron for it, that way the timer will be reset when a script sets a new cron
elseif (is_numeric($this->crontimer[$cron]) && $this->crontimer[$cron] < $time) {
$this->crontimer[$cron] += $timer;
foreach ($this->cron[$cron] as $ecron=>$val)
$this->cron[$cron][$ecron]->cron((is_numeric($ecron)?"":$ecron)); //the is_numeric is required for backwards compatability
}
}
}

Code: (Example script) [Select]
<?php
$ct = new CronTest($bot);

$cron["7sec"]["7sectest"] = &$ct;
$cron["15sec"]["15sectest"] = &$ct;
$cron["30sec"]["resetcron"] = &$ct;

class CronTest {
var $bot;
function CronTest(&$bot) {
$this->bot = &$bot;
/*
Using 7sec and 15sec as names are not needed, it's just for simplicity of reading.
It's here the time interval is set in seconds.
Not setting for 1min because that interval is default and specificed in Bot.php
*/
$this->bot->crons["7sec"]=7;
$this->bot->crons["15sec"]=15;
}
function cron($cron=false) {
if ($cron == "7sectest") {
echo date("[H:i:s]")." This was the 7 second test - Removing it from cron\n\n";
unset($this->bot->cron["7sec"]["7sectest"]);
}
elseif ($cron == "15sectest") {
echo date("[H:i:s]")." This was the 15 second test - Removing it from cron\n\n";
unset($this->bot->cron["15sec"]["15sectest"]);
}
elseif ($cron == "resetcron") {
echo date("[H:i:s]")." 30 seconds has passed, time to start 7 and 15 second tests again\n\n";
$this->bot->cron["7sec"]["7sectest"] = &$this;
$this->bot->cron["15sec"]["15sectest"] = &$this;
}
}
}
?>

Too many toons.

Offline Naturalistic

  • Contributor
  • *******
  • Posts: 221
  • Karma: +0/-0
Re: Cron changes
« Reply #1 on: October 20, 2006, 07:44:39 am »
Looks good. Could prove to be very useful for future modules.  ;)
220/25 Eternalist Doctor
-----------------------------
Campalot Coding Co-ordinator and Super Admin
http://www.campalot.info/index.php

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 713
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal