PHP code example of webpractik / agent

1. Go to this page and download the library: Download webpractik/agent library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webpractik / agent example snippets


use Webpractik\Agent\AgentTask;
use Vendor\Module\TestAgent;
use Bitrix\Main\Type\DateTime;

AgentTask::build()
    ->setClass(TestAgent::class)
    ->setCallChain(
        ['execute' => [$params]]
    )
    ->setModule('vendor.module')
    ->setExecutionTime(DateTime::createFromTimestamp(time() + 60)) // optional
    ->setUserId(1) // optional
    ->create();

namespace Vendor\Module;

class TestAgent
{
    use AgentTrait;

    public function execute()
    {
        // some code

        return $this->getAgentName(['execute' => []]); // метод обязательно должен вернуть имя агента
    }
}