PHP code example of pyrowman / pheanstalk-bundle

1. Go to this page and download the library: Download pyrowman/pheanstalk-bundle 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/ */

    

pyrowman / pheanstalk-bundle example snippets




namespace Acme\DemoBundle\Controller;

use Pheanstalk\Structure\Schedule;
use Pheanstalk\Structure\TimeSchedule;
use Pyrowman\PheanstalkBundle\Proxy\PheanstalkProxy;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ContainerInterface;

class HomeController extends AbstractController 
{

    public function indexAction() {
        
        $sc = $this->get('service_container');
        /** @var PheanstalkProxy $pheanstalk */
        $pheanstalk = $sc->get("pheanstalk");

        // Create a simple Worflow with one task inside
        
        $workflow = $pheanstalk->createTask('Sleep', 'Test', '/bin/sleep 80');
        
        // Put the job into instance execution
        
        $pheanstalk->put($workflow);
        
        // ----------------------------------------
        // check server availability
        
        $pheanstalk->getConnection()->isServiceListening(); // true or false
        
        //-----------------------------------------
        // Add a scheduler for the job (by default in continous)
        $schedule = new Schedule($workflow->getId(), new TimeSchedule());
        $workflowSchedule = $pheanstalk->createSchedule($schedule);
        
        //-----------------------------------------
        // Edit a workflow
        
        $workflow->setGroup('2nd test group');
        $pheanstalk->update($workflow);
        
        
        //-----------------------------------------
        // Getting infos on the execution of a workflow
        
        $workflowInstances = $pheanstalk->getWorkflowInstances($workflow);
        
        //-----------------------------------------
        // Delete a job 
        
        if ($workflow = $pheanstalk->workflowExists('Sleep'))
            $pheanstalk->delete($workflow);

    }
    
    public static function getSubscribedServices()
    {
        return array_merge(parent::getSubscribedServices(), [
            // ...
            'service_container' => ContainerInterface::class,
        ]);
    }

}