Documentation

AddAgent

mixed
CAgent::AddAgent(
 string name, 
 string module = "", 
 string period = "N", 
 int interval = 86400, 
 string datecheck = "", 
 string active = "Y",
 string next_exec = "", 
 int sort = 100
)

The method registers new agent function. Static method.

Parameters

ParameterDescription Available from version
name PHP string to launch agent function.
module The module ID. Required to include the module files.
Optional. Empty by default.
period

If "Y", the time of the next run of agent (next_exec) is calculated as follows:

next_exec = next_exec + interval
At the next run, if the amount of time elapsed is more than the interval value, the agent will be run as many times as it was to with respect to the amount of time it failed to run. Then, when next_exec will achieve or exceed the current time it will be further run according to the interval value. Usually this rule applies to agents which are to be run the required number of times with no fail.

If "N", the time of the next run of agent (next_exec) is calculated as follows:

next_exec =  time of the last run + interval
After the first run the agent will be further run according to the interval value. Optional, "N" by default.
interval Interval (in seconds) at which the agent is to be run.
Optional. 86400 (24 hours) by default.
datecheck The time of the first check for the agent pending state, in the format of the current language.
Optional. The current time by default.
active Specifies whether the agent is active or not (Y|N).
Optional. "Y" (active) by default.
next_exec The time of the first run of the agent in the format of the current language..
Optional. The current time by default.
3.1.4
sort The sort weight allows to define the priority of run of this agent in respect to the other agents.
Optional. 100 by default.
3.2.9

Returned values

Returns the newly added agent ID on success, otherwise returns false. If the agent doesn't return anything, it is deleted. Usually it returns its own call.

See Also

Example

<?
// add agent of the"Statistics" module
CAgent::AddAgent(
    "CStatistic::CleanUpStatistics_2();", // function name
    "statistic",                          // module ID
    "N",                                  // the agent is not critical to number of runs
    86400,                                // interval of run is 24 hours
    "07.04.2005 20:03:26",                // time of the first check of the run
    "Y",                                  // the agent is active
    "07.04.2005 20:03:26",                // time of the first run
    30);
?>
<? 
// add agent of the "Techsupport" module
CAgent::AddAgent(
    "CTicket::AutoClose();",  // function name
    "support",                // module ID
    "N",                      // the agent is not critical to number of runs
    86400,                    // interval of run is 24 hours
    "",                       // time of the first check of the run is current
    "Y",                      // the agent is active
    "",                       // time of the first run is current
    30);
?>
<?
// add an arbitrary agent not belonging to any of modules 
CAgent::AddAgent("My_Agent_Function();");
?>

<?
// file /bitrix/php_interface/init.php

function My_Agent_Function()
{
   //perform any actions
   return "My_Agent_Function();";
}
?>
<?
// add an arbitrary agent of the module
// with the ID my_module

CAgent::AddAgent(
   "CMyModule::Agent007(1)", 
   "my_module", 
   "Y", 
    86400);
?>

<?
// this agent will be run 7 times once per 24 hours, 
// after that it will be removed from the agent table.

Class CMyModule
{
   function Agent007($cnt=1)
   {
      echo "Hello!";
      if($cnt>=7)
         return "";
      return "CMyModule::Agent007(".($cnt+1).")";
   }
}
?>


© «Bitrix24», 2001-2024
Up