public function perform() { echo "\n\nPerforming job...\n"; $payload = $this->args; $body = $payload['body']; try { $url = $payload['endpoint']['url']; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); } catch (Exception $e) { // if we don't have success with response, or success with no response - re-queue this message $attempt = array_key_exists('attempts', $body) ? $body['attempts'] += 1 : 1; if ($attempt <= $this->retry_max) { $payload['body']['attempts'] = $attempt; $delay = 60 * $attempt * $attempt * $attempt; // retry after 1, 8, 27 minutes before giving up error_log("Exception raised: '" . $e->getMessage() . "' - Retrying job in {$delay}"); ResqueScheduler::enqueueIn($delay, "content", "PostSaved", $payload); } else { error_log("Exception raised: '" . $e->getMessage() . "' - Not retrying"); } } }
/** * Schedule all of the delayed jobs for a given timestamp. * * Searches for all items for a given timestamp, pulls them off the list of * delayed jobs and pushes them across to Resque. * * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule. */ public function enqueueDelayedItemsForTimestamp($timestamp) { $item = null; while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) { $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]'); Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args'])); $payload = array_merge(array($item['queue'], $item['class']), $item['args'], isset($item['trackStatus']) ? array($item['trackStatus']) : array()); call_user_func_array('Resque::enqueue', $payload); } }
/** * Schedule all of the delayed jobs for a given timestamp. * * Searches for all items for a given timestamp, pulls them off the list of * delayed jobs and pushes them across to Resque. * * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule. */ public function enqueueDelayedItemsForTimestamp($timestamp) { $item = null; while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) { $this->log(array('message' => 'Moving scheduled job ' . strtoupper($item['class']) . ' to ' . strtoupper($item['queue']), 'data' => array('type' => 'movescheduled', 'args' => array('timestamp' => (int) $timestamp, 'class' => $item['class'], 'queue' => $item['queue'], 'job_id' => $item['args'][0]['id'], 'wait' => round(microtime(true) - (isset($item['s_time']) ? $item['s_time'] : 0), 3), 's_wait' => $timestamp - floor(isset($item['s_time']) ? $item['s_time'] : 0)))), self::LOG_TYPE_INFO); \Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args'])); $payload = array_merge(array($item['queue'], $item['class']), $item['args'], array($item['track'])); call_user_func_array('\\Resque::enqueue', $payload); } }
protected function enqueueFromConfig($config) { if (isset($config['cron'])) { //ResqueScheduler::removeDelayed($config['args']['queue'], $config['class'], $config['args']); $this->logger->log(Psr\Log\LogLevel::NOTICE, 'queueing {class} in {queue} Scheduled {schedule_at}', array('class' => $config['class'], 'queue' => $config['args']['queue'], 'schedule_at' => $config['schedule_at'])); ResqueScheduler::enqueueAt($config['schedule_at'], $config['args']['queue'], $config['class'], $config['args']); } else { $this->logger->log(Psr\Log\LogLevel::INFO, 'queueing {class} in {queue} [delayed]', array('class' => $config['class'], 'queue' => $config['queue'])); Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $config['queue'], 'class' => $config['class'], 'args' => $config['args'])); $payload = array_merge(array($config['queue'], $config['class']), $config['args']); call_user_func_array('Resque::enqueue', $payload); } }
/** * Schedule all of the delayed jobs for a given timestamp. * * Searches for all items for a given timestamp, pulls them off the list of * delayed jobs and pushes them across to Resque. * * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule. */ public function enqueueDelayedItemsForTimestamp($timestamp) { $item = null; while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) { if ($timestamp instanceof DateTime) { $timestamp = $timestamp->getTimestamp(); } $this->logger->log(Psr\Log\LogLevel::NOTICE, 'Queueing {class} scheduled to {datetime} in {queue} queue with args {args}', array('class' => $item['class'], 'queue' => $item['queue'], 'args' => json_encode($item['args']), 'datetime' => date('Y-m-d H:i:s', $timestamp))); Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args'])); $payload = array_merge(array($item['queue'], $item['class']), $item['args']); call_user_func_array('Resque::enqueue', $payload); } }
/** * Create a new scheduled job and save it to the specified queue. * * @param timestamp $at UNIX timestamp when job should be executed. * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. * * @return string */ public function enqueueJobAt($at, $queue, $class, $args = array()) { return ResqueScheduler::enqueueAt($at, $queue, $class, $args); }
/** * Guardar Formulario de Cliente Juridico * * @return boolean */ function guardar_actividad() { if (Util::is_array_empty($_POST)) { return false; } //Init Fieldset variable $fieldset = array(); //Remover el boton de submit que por default //viene con el valor "Guardar" unset($_POST["campo"]["guardar"]); $modulo_relacionado_con = $this->seleccionar_modulos_relacionado_con(array('valor' => $_POST['campo']['modulo_relacion'])); if (!isset($_POST["campo"]["uuid_cliente"])) { $uuid_cliente = $this->seleccionar_cliente_de_oportunidad($_POST["campo"]["uuid_oportunidad"]); //$uuid_cliente= $uuid_cliente[0]['uuid_cliente']; $fieldset["uuid_cliente"] = $uuid_cliente[0]['uuid_cliente']; } unset($_POST["campo"]["modulo_relacion"]); //Recorrer arreglo e insertar los valores que no estan vacios //en el fieldset foreach ($_POST["campo"] as $fieldname => $fieldvalue) { if (empty($fieldvalue)) { continue; } //check if is an array if (is_array($fieldvalue)) { foreach ($fieldvalue as $name => $value) { if ($value != "") { if (strpos($name, 'uuid_') !== false) { $fieldset["{$name} = UNHEX('{$value}')"] = NULL; } else { $fieldset[$name] = $this->security->xss_clean($value); } } } } else { if (strpos($fieldname, 'uuid_') !== false) { $this->db->set($fieldname, "UNHEX('{$fieldvalue}')", FALSE); } else { $fieldset[$fieldname] = $fieldvalue; } } } if (isset($_POST['campo']['completada'])) { if ($_POST['campo']['completada'] != 0 || $_POST['campo']['completada'] == "") { $fieldset["completada"] = 1; } else { $fieldset["completada"] = 0; } } else { $fieldset["completada"] = 0; } //Si el $fieldset es vacio if (Util::is_array_empty($fieldset)) { return false; } // // Begin Transaction // docs: https://ellislab.com/codeigniter/user-guide/database/transactions.html // $this->db->trans_start(); $fieldset["creado_por"] = $this->session->userdata('id_usuario'); $fieldset["fecha_creacion"] = date('Y-m-d H-i-s'); $fieldset["relacionado_con"] = $modulo_relacionado_con[0]['id_cat']; $fieldset["fecha"] = date('Y-m-d H:i:s', strtotime($fieldset["fecha"])); //Campos adicionales $this->db->set('uuid_actividad', 'ORDER_UUID(uuid())', FALSE); //Guardar Actividad $this->db->insert('act_actividades', $fieldset); $idActividad = $this->db->insert_id(); //--------------------------------------- //End Transaction $this->db->trans_complete(); $uuid_oportunidad = $_POST['campo']['uuid_oportunidad']; $uuid_tipo = $this->db->query("SELECT HEX(uuid_tipo_actividad) AS uuid_tipo,etiqueta FROM act_tipo_actividades WHERE etiqueta LIKE '%telefonica%'")->row_array(); $tipo_actividad = $_POST['campo']['uuid_tipo_actividad']; $oportunidades = $this->db->query("select count(uuid_oportunidad) as oportunidades from act_actividades where HEX(uuid_oportunidad) ='" . $uuid_oportunidad . "'")->row_array(); if ($this->is_redis_as_runnig && $oportunidades['oportunidades'] == 1 && $uuid_tipo['uuid_tipo'] != $tipo_actividad) { //armar datos $uuid_asignado = $_POST["campo"]["uuid_asignado"]; $creado_por = CRM_Controller::$uuid_usuario; $datosOportunidad = $this->db->query("Select id_oportunidad, nombre from opp_oportunidades where HEX(uuid_oportunidad) = '" . $uuid_oportunidad . "' ")->row_array(); $datos_notificaciones = array(); $data_notificacion = array('id_oportunidad' => $datosOportunidad['id_oportunidad'], 'nombre' => $datosOportunidad['nombre'], 'tipo' => 'tiene_oportunidad'); $datos_notificaciones['data'] = json_encode($data_notificacion); $notificacion = Notificaciones::guardar_notificaciones($datos_notificaciones, $uuid_asignado, $creado_por); $args = array('id' => $notificacion['id']); $schedules = Jobs::mostrar_jobs(array('id_job' => 3)); $fecha_tarea = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s ') . $schedule['recurrencia'])); $datetime = new DateTime($fecha_tarea, new DateTimeZone('America/Panama')); if (!empty($schedules)) { foreach ($schedules as $schedule) { $schedule_usuarios = json_decode($schedule['uuid_usuarios']); $args = array_merge($args, array('id_job_conf' => $schedule['id'], 'oportunidad_id' => $datosOportunidad['id_oportunidad'], 'tiempo_ejecucion' => $fecha_tarea, 'recurrencia' => $schedule['recurrencia'])); if (in_array($uuid_asignado, $schedule_usuarios->uuid_usuarios)) { ResqueScheduler::enqueueAt($datetime, 'notificacion', 'Notificaciones', $args); } else { ResqueScheduler::enqueueAt($datetime, 'notificacion', 'Notificaciones', $args); } } } } if ($this->is_redis_as_runnig && $oportunidades['oportunidades'] >= 5) { $oportunidades = $this->db->query("select HEX(uuid_tipo_actividad) as uuid_tipo_actividad from act_actividades where HEX(uuid_oportunidad) ='" . $uuid_oportunidad . "' LIMIT 5")->result_array(); $tipo = $this->db->query("SELECT HEX(uuid_tipo_actividad) AS uuid_tipo FROM act_tipo_actividades WHERE etiqueta LIKE '%reunion%' OR etiqueta LIKE '%visita%'")->result_array(); $array5_opotunidad = array(); $array_tipo = array(); foreach ($oportunidades as $actividades) { array_push($array5_opotunidad, $actividades['uuid_tipo_actividad']); } foreach ($tipo as $actividades) { array_push($array_tipo, $actividades['uuid_tipo']); } $array_conciden = array_intersect($array5_opotunidad, $array_tipo); if (count($array_conciden) == 0) { //armar datos $uuid_asignado = $_POST["campo"]["uuid_asignado"]; $creado_por = CRM_Controller::$uuid_usuario; $datosOportunidad = $this->db->query("Select id_oportunidad, nombre from opp_oportunidades where HEX(uuid_oportunidad) = '" . $uuid_oportunidad . "' ")->row_array(); $datos_notificaciones = array(); $data_notificacion = array('id_oportunidad' => $datosOportunidad['id_oportunidad'], 'nombre' => $datosOportunidad['nombre'], 'tipo' => 'tiene_actividad'); $datos_notificaciones['data'] = json_encode($data_notificacion); $notificacion = Notificaciones::guardar_notificaciones($datos_notificaciones, $uuid_asignado, $creado_por); $args = array('id' => $notificacion['id']); $schedules = Jobs::mostrar_jobs(array('id_job' => 7)); $fecha_tarea = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s ') . $schedule['recurrencia'])); $datetime = new DateTime($fecha_tarea, new DateTimeZone('America/Panama')); if (!empty($schedules)) { foreach ($schedules as $schedule) { $schedule_usuarios = json_decode($schedule['uuid_usuarios']); $args = array_merge($args, array('id_job_conf' => $schedule['id'], 'oportunidad_id' => $datosOportunidad['id_oportunidad'], 'tiempo_ejecucion' => $fecha_tarea, 'recurrencia' => $schedule['recurrencia'])); if (in_array($uuid_asignado, $schedule_usuarios->uuid_usuarios)) { ResqueScheduler::enqueueAt($datetime, 'notificacion', 'Notificaciones', $args); } else { ResqueScheduler::enqueueAt($datetime, 'notificacion', 'Notificaciones', $args); } } } } } // Managing Errors if ($this->db->trans_status() === FALSE) { log_message("error", "MODULO: Actividades --> No se pudo guadar los datos de la actividad en DB."); return false; } else { /* Notifications::guardar_notificacion( array( "tipo_notificacion"=>'actualizacion', "modulo"=>$_POST['campo']['relacionado_con'], "id"=>$_POST['campo']['uuid_relacion'], ));*/ //guardar el id en variable de session $this->session->set_userdata('uuid_actividad', $idActividad); return true; } }
/** * Actualizar Etapa de Oportunidad * * @param string $id_cliente * @return boolean */ function ajax_actualizar_oportunidad($id_oportunidad = NULL) { $id_oportunidad = $this->input->post('id_oportunidad', true); $id_etapa = $this->input->post('id_etapa', true); //Si el $fieldset es vacio if (empty($id_oportunidad) || empty($id_etapa)) { return false; } // // Begin Transaction // docs: https://ellislab.com/codeigniter/user-guide/database/transactions.html // $this->db->trans_start(); $fieldset = array("id_etapa_venta" => $id_etapa); $clause = array("uuid_oportunidad = UNHEX('{$id_oportunidad}')" => NULL); //Actualizar Cliente Potencial $this->db->where($clause)->update('opp_oportunidades', $fieldset); //----------------- // Verificar si la etapa fue actualiza a Vendido //----------------- $fields = array("ocat.valor AS etapa_venta", "HEX(opp.uuid_propiedad) AS uuid_propiedad"); $clause = array("opp.uuid_oportunidad = UNHEX('{$id_oportunidad}')" => NULL); $checkEtapa = $this->db->select($fields)->distinct()->from('opp_oportunidades AS opp')->join('opp_oportunidades_cat AS ocat', 'ocat.id_cat = opp.id_etapa_venta', 'LEFT')->where($clause)->get()->result_array(); //----------------- // Obtener los Estados de las Propiedades //----------------- $listaEstadosPropiedades = $this->db->select("id_cat AS id_estado_propiedad")->distinct()->from('rpo_propiedades_cat')->where("valor", "no_disponible")->get()->result_array(); //verificar si la etapa fue actualiza a Vendido //si es vendido, cambiar la propiedad a No Disponible. if (!empty($checkEtapa) && !empty($checkEtapa[0]["etapa_venta"]) && $checkEtapa[0]["etapa_venta"] == "vendido") { //Actualizar Propiedad $fieldset = array("id_estado_propiedad" => $listaEstadosPropiedades[0]["id_estado_propiedad"]); $clause = array("uuid_propiedad = UNHEX('" . $checkEtapa[0]["uuid_propiedad"] . "')" => NULL); $this->db->where($clause)->update('rpo_propiedades', $fieldset); } //--------------------------------------- //End Transaction $this->db->trans_complete(); //redis if ($this->is_redis_as_runnig && ($checkEtapa[0]["etapa_venta"] != "vendido" && $checkEtapa[0]["etapa_venta"] != "venta_perdida")) { //verifica si el redis esta corriendo //armar datos $creado_por = CRM_Controller::$uuid_usuario; $datosOportunidad = $this->db->query("Select id_oportunidad, nombre, fecha_creacion,HEX(id_asignado) as id_asignado from opp_oportunidades where HEX(uuid_oportunidad) = '" . $id_oportunidad . "' ")->row_array(); $datos_notificaciones = array(); $data_notificacion = array('id_oportunidad' => $datosOportunidad['id_oportunidad'], 'nombre' => $datosOportunidad['nombre'], 'tipo' => 'oportunidad_actualizar_etapa', 'etapa' => $checkEtapa[0]["etapa_venta"]); $datos_notificaciones['data'] = json_encode($data_notificacion); $uuid_asignado = $datosOportunidad['id_asignado']; $notificacion = Notificaciones::guardar_notificaciones($datos_notificaciones, $uuid_asignado, $creado_por); $args = array('id' => $notificacion['id']); //$this->redis->publish('oportunidad',json_encode(array('id_asignado' =>$uuid_asignado, 'id_notificacion' => $notificacion['id'] ))); $schedules = Jobs::mostrar_jobs(array('id_job' => 2)); if (!empty($schedules)) { foreach ($schedules as $schedule) { $fecha_tarea = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s ') . $schedule['recurrencia'])); $datetime = new DateTime($fecha_tarea, new DateTimeZone('America/Panama')); $args = array_merge($args, array('id_job_conf' => $schedule['id'], 'oportunidad_id' => $datosOportunidad['id_oportunidad'], 'fecha_oportunidad' => $datosOportunidad['fecha_creacion'], 'tiempo_ejecucion' => $fecha_tarea, 'recurrencia' => $schedule['recurrencia'])); $schedule_usuarios = json_decode($schedule['uuid_usuarios']); if (in_array($uuid_asignado, $schedule_usuarios->uuid_usuarios)) { ResqueScheduler::enqueueAt($datetime, 'notificacion' . time(), 'Notificaciones', $args); } else { ResqueScheduler::enqueueAt($datetime, 'notificacion' . time(), 'Notificaciones', $args); } } } } // Managing Errors if ($this->db->trans_status() === FALSE) { log_message("error", "MODULO: Oportunidades --> No se pudo actualizar la etapa de la oportunidad en DB."); return array("respuesta" => false, "mensaje" => "Hubo un error al tratar de actualizar la etapa de la oportunidad."); } else { //Limpiar cache @CRM_Controller::$cache->delete("infoOportunidad"); @CRM_Controller::$cache->delete("listado_oportunidades"); return array("respuesta" => true, "mensaje" => "Se ha cambiado la etapa de la oportunidad satisfactoriamente."); } }
/** * The method to run after a Job is finished. */ public function tearDown() { //Verificar si existen argumentos if (!empty($this->args)) { //Establecer variables self::$datetime = $this->args["datetime"]; self::$quequename = $this->args["quequename"]; self::$jobclassname = $this->args["jobclassname"]; self::$id_configuracion_reporte = $this->args["idNotificacionReporte"]; } //DB Conection self::$db = new Database(); self::$db->connect(); ///Fecha y Hora Actual //$current_datetime = new DateTime(date('Y-m-d H:i:s'), new DateTimeZone('America/Panama')) $current_datetime = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s'))); //Calcular nueva fecha para programar la tarea //Sumarle 7 dias a la fecha de Ejecucion //self::$datetime = date('Y-m-d H:i:s', strtotime($current_datetime. ' + 7 days')); self::$datetime = date('Y-m-d H:i:s', strtotime($current_datetime . '+20 minute')); //Actualizar fecha ultima fecha de ejecucion de la tarea //y fecha de proxima ejcucion $fields = array("ultimo_tiempo_ejecucion" => $current_datetime, "proximo_tiempo_ejecucion" => self::$datetime); self::$db->update('configuracion_notificaciones_reportes', $fields, 'id="' . $this->args["idNotificacionReporte"] . '"'); $result = self::$db->getResult(); //print echo "Proxima Fecha de Ejecucion: " . self::$datetime . PHP_EOL; $horas = strtotime(self::$datetime) - strtotime($current_datetime); //Agendar nuevamente el job ResqueScheduler::enqueueIn($horas, self::$quequename, self::$jobclassname, ['datetime' => self::$datetime, 'quequename' => self::$quequename, 'jobclassname' => self::$jobclassname, 'idNotificacionReporte' => "" . $this->args["idNotificacionReporte"] . ""]); //print echo "Proxima Fecha en Horas: " . $horas . PHP_EOL; Resque_Event::listen('afterPerform', function () { //echo "Se envio el correo :)) "; }); Resque_Event::listen('onFailure', function () { echo "Algo paso :-| ...."; }); }
<?php //if(empty($argv[1])) { // die('Specify the name of a job to add. e.g, php queue.php PHP_Job'); //} $job = 'App\\Job\\GetDayCandles'; $job = 'App\\Job\\GetAccountInfo'; require '../../vendor/chrisboulton/php-resque/lib/Resque.php'; require '../../vendor/chrisboulton/php-resque-scheduler/lib/ResqueScheduler.php'; date_default_timezone_set('GMT'); Resque::setBackend('127.0.0.1:6379'); $in = 3; //one hour //$args = array( // 'time' => time(), // 'array' => array( // 'test' => 'test', // ), //); $args = array('time' => time(), 'userid' => 'not needed', 'oanda' => array('apiKey' => '', 'accountId' => '', 'serverType' => 'Demo')); ResqueScheduler::enqueueIn($in, 'default', $job, $args); //$jobId = Resque::enqueue('default', $job, $args, true); echo "Queued job \n\n";
public function delete(Job $job) { if (!$job instanceof ResqueJob) { throw new WrongJobException('Resque queue manager can only delete resque jobs'); } if (!$job->isFutureJob()) { throw new NoSuchJobException('Resque queue manager can only delete future jobs'); } if ($this->debug) { return; } if (\ResqueScheduler::removeDelayedJobFromTimestamp($job->getWhen(), $job->getQueue(), $job->getClass(), $job->getResqueArguments(), $job->isTrackStatus()) < 1) { throw new NoSuchJobException('No jobs were found'); } }
/** * @param mixed $resqueClass */ public static function setResqueClass($resqueClass) { self::$resqueClass = $resqueClass; }
/** * Remove a scheduled job * * @param JobDescription $job * @return int number of deleted jobs */ public function delete(JobDescription $job) { if ($this->debug) { return 0; } if (!$job->isFutureJob()) { return 0; } return \ResqueScheduler::removeDelayedJobFromTimestamp($job->getWhen(), $job->getQueue(), $job->getClass(), $job->getArgs(), $job->getTrackStatus()); }
/** * Create a new scheduled job and save it to the specified queue. * * @param timestamp $at UNIX timestamp when job should be executed. * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. * @param bool $track_status Enable track status * * @return string */ public function enqueueJobAt($at, $queue, $class, $args = array(), $track_status = false) { return ResqueScheduler::enqueueAt($at, $queue, $class, $args, $track_status); }
public function tearDown() { $current_datetime = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s'))); $id_notificacion = $this->args['id']; $this->db->sql('SELECT * FROM notificaciones WHERE id="' . $id_notificacion . '" AND tipo = 0'); $results = $this->db->getResult(); if (!empty($results[0])) { $data = json_decode($results[0]['data']); $fecha_creacion_notificacion = $results[0]['fecha_creacion']; $fecha_oportunidad = $this->args['fecha_oportunidad']; $fecha_ejecucion = $this->args['tiempo_ejecucion']; $tiempo = Subordinados1::get_recurrencia($fecha_creacion_notificacion, $fecha_ejecucion); $condicion = split(" ", $tiempo); echo 'poner notificaciones en redis' . PHP_EOL; switch ($data->tipo) { case 'nueva_oportunidad': if ($condicion[0] >= 24 && ($condicion[1] == 'dias' || $condicion[1] == 'minutos' || $condicion[1] == 'horas')) { $current_datetime = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s ') . '24 hour')); $this->args['tiempo_ejecucion'] = $current_datetime; $datetime = new DateTime($current_datetime, new DateTimeZone('America/Panama')); ResqueScheduler::enqueueAt($datetime, 'notificacion' . time(), 'Notificaciones', $this->args); } break; case 'oportunidad_actualizar_etapa': if ($condicion[0] > 40 && ($condicion[1] == 'dias' || $condicion[1] == 'minutos' || $condicion[1] == 'horas')) { $current_datetime = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s ') . '5 day')); $this->args['tiempo_ejecucion'] = $current_datetime; $datetime = new DateTime($current_datetime, new DateTimeZone('America/Panama')); ResqueScheduler::enqueueAt($datetime, 'notificacion' . time(), 'Notificaciones', $this->args); } break; } } Resque_Event::listen('afterPerform', function () { echo "Se ejecuto la tarea Notificaciones {$this->args}['id'] " . date('Y-m-d H:i:s') . PHP_EOL; }); Resque_Event::listen('onFailure', function () { echo "Algo paso :-| ...."; }); }
/** * @return mixed */ public function getNumberOfDelayedJobs() { return \ResqueScheduler::getDelayedQueueScheduleSize(); }
public static function cleanSchedules() { $redis = Resque::redis(); if ($redis->exists('schedules')) { foreach ($redis->hkeys('schedules') as $name) { if (!self::isSchedulePersisted($name)) { self::removeSchedule($name); } } } self::$schedules = null; return true; }