Using curl to store jobs on a queue in yii


(Ividal) #1

I’m trying to run a command in order to send a signal to my arduino device so it can turn one of the leds on, the process is made via a queue, the works are pushed into the queue and once they get ran they’re supposed to be ran in a specific time, it’s ran using a curl method but I’m not sure how to write the code.

I run the code with Sublime Text 3 and php, I’ve tried running it with the curl I already have programmed but don’t think it works that way, I tried doing research and seeing if I need a special command for using the curl with the queue, I found this: https://github.com/adawley/php-curl-queuebut not sure how to implement it on my code

This is the code where the jobs get executed from the queue:

namespace app\commands;

use Yii;
use app\models\Equipos;
use app\models\EquiposSearch;
use app\models\Horarios_Equipos;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\data\ActiveDataProvider;
use skeeks\yii2\curl;

class HorarioJob extends \yii\base\BaseObject implements 
\yii\queue\JobInterface
{
public $id_equipo;
public $estado;

public function execute($queue)
{
    if ($estado == 1){

        $curl = new curl\Curl();

    $response = $curl->get($equipo->ip.'/gpio/LEDa=ON');

}




    }
}

This is the code where the jobs get pushed into the queue:

<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\commands;

use yii\console\Controller;
use yii\console\ExitCode;
use app\models\Horarios_Equipos;


/**
 * This command echoes the first argument that you have entered.
 *
 * This command is provided as an example for you to learn how to create 
 console commands.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
 class HorarioController extends Controller
 {
 /**
 * This command echoes what you have entered as the message.
 * @param string $message the message to be echoed.
 * @return int Exit code
 */
public function actionBuscar()
{
    $hora = date("H").":00".":00";
    $dia = date("N");

    $horarios = Horarios_Equipos::find()->where([
        'hora' => $hora,
        'dia' => $dia,
    ])->all();

    foreach($horarios as $horario)
    {

        //echo $horario->id_equipo."\n";
        //echo $horario->estado."\n";
        //enviar a cola

        \Yii::$app->queue->push(
            new HorarioJob([
                'id_equipo' => $horario->id_equipo,
                'estado' => $horario->estado,

            ])
        );
    }

    return ExitCode::OK;
}

}

Once I run the queue, the arduino device should turn the led corresponding to the ID it gets from the database, but so far it hasn’t