Charrua

Charrua

Owner at Charrua

A Coruña

Hire Me

Member Since 1 Year Ago

Experience Points 3,710
Experience
Level
Lessons Completed 15
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

04 Dec
1 week ago

Charrua started a new conversation Vue-router And Vue-stripe-elements-plus Issue

Hi, I'm building a SPA with Vue, two pages are using the <Card> component from vue-stripe-elements-plus.

The views that load the <Card> component are /gala and /seminars.

The problem is when I change from one view to the other, the <Card> component seems not to render again and an error is shown in console:

vue.runtime.esm.js?2b0e:587 [Vue warn]: Error in beforeMount hook: "IntegrationError: Can only create one Element of type card."

My routes are:

import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/gala',
      name: 'gala',
      component: () => import(/* webpackChunkName: "about" */ './views/Gala.vue')
    },
    {
      path: '/seminars',
      name: 'seminars',
      component: () => import(/* webpackChunkName: "about" */ './views/Seminars.vue')
    }
  ]
})

Maybe I'm missing something?

29 Nov
1 week ago

Charrua left a reply on Which OAuth 2.0 Flow Should I Use? Vue Form And API

@D9705996 - That is what I’m looking for now, if I need to authenticate or not... how can I resolve this? Any more ideas? How to determine if I need authentication to send the form data or not...

Charrua left a reply on Which OAuth 2.0 Flow Should I Use? Vue Form And API

@D9705996 - Great answer, thank you. The ticket form will be public and reachable by all guest users (eg domain.com/form), they will not need to login to fill and send the form. And my API will live on anotherdomain.com/api

Maybe I'm confused and is not the case to use authenticated API requests to my app because there is no login on the frontend... I thought on using authenticated requests to add some security to my API but maybe is not the use case here.

Charrua started a new conversation Which OAuth 2.0 Flow Should I Use? Vue Form And API

Hello, I'm new to OAuth and APIs. I have set my Laravel API endpoints to store and send responses for saving a resource. In other webpage I have a Vue public form for users to buy tickets and store them in the Laravel app.

If I use passport, what type of authorization flow (why, benefits) I need to use to authenticate all requests to my API? Thank you.

13 Nov
4 weeks ago

Charrua left a reply on Laravel Storing Images Outside Public Directory

@talinon you are right, that solved my issue. Thank you.

Charrua started a new conversation Laravel Storing Images Outside Public Directory

Hello, I'm trying to store images using the local driver. I have followed docs and created the symbolic link php artisan storage:link

I'm saving a file from a form and in my controller I have the following: $communication->image = Storage::putFile('messages', $request->file('image'));

The problem is that this is creating a directory messages inside storage/app/messages and not in storage/app/public/messages as it should.

My ´config/filesystems.php` is:

return [

    'default' => env('FILESYSTEM_DRIVER', 'local'),

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

    ],

];

Any ideas?

10 Nov
1 month ago

Charrua left a reply on Getting Error OuteNotificationFor() On Batch Email Notifications

This issue was solved. Code has no errors, I was using Supervisor to manage queues and I have forgot to restart it on production server.

09 Nov
1 month ago

Charrua started a new conversation Getting Error OuteNotificationFor() On Batch Email Notifications

Hello, I'm trying to send email to members on my app and I get the following error:

production.ERROR: Call to undefined method Illuminate\Database\Query\Builder::routeNotificationFor() {"exception":"[object] (BadMethodCallException(code: 0): Call to undefined method Illuminate\Database\Query\Builder::routeNotificationFor() at /var/www/vhosts/.../laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2483)

I have the members model with the Notifiable trait and the weird issue is that on my local machine the emails are delivered... The problem is on production... Any ideas?

The notifications are fired with:

Notification::send($members_to_notify, new CommMessage($communication));

And the CommMessageclass is:


namespace App\Notifications\Communications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

use App\Mail\Communications\Message as Mailable;

class CommMessage extends Notification implements ShouldQueue
{
    use Queueable;

    private $communication;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($communication)
    {
        $this->communication = $communication;
       
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return Mailable
     */
    public function toMail($notifiable)
    {
        return (new Mailable($this->communication))->to($notifiable->email);
    }
    
}

The mailable Message class is:

namespace App\Mail\Communications;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class Message extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * The appointment instance.
     *
     * @var Appointment
     */
    public $communication;
    
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($communication)
    {
        $this->communication = $communication;

    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $this->replyTo($this->communication->school->email)->markdown('emails.communications.message');

        $this->subject($this->communication->title);

        $this->withSwiftMessage(function ($message) {
            $message->getHeaders()
                    ->addTextHeader('X-Mailgun-Variables', json_encode([
                        'model_id' => $this->communication->id,
                        'model' => get_class($this->communication),
                        'email_type' => 11 //Communication message (EmailLogType)
                    ]));
        });

    }

}
13 Oct
1 month ago

Charrua left a reply on Scheduler Running With Delay (not On Time)

@hondnl this is the Plesk engineer answer:

This is a known issue with plesk-php7x which have libsodium package included for stronger cryptography.

Forced initialization of crypto library on startup each PHP script depletes entropy (/dev/random) and next processes wait for another portion of randomness. So any php script can cause entropy depletion.

The developers have submitted this issue as a bug PPPM-9444 which is planned to be fixed in one of the future Plesk updates.

Please subscribe to the following article to be notified when the bug is fixed: https://support.plesk.com/hc/en-us/articles/360010129094

11 Oct
2 months ago

Charrua started a new conversation Integrating Facebook Page_insights With Laravel

Hello, what would be a good workflow to integrate facebook page insights in a Laravel dashboard app?

I don't know where to start.

Any ideas would be great!

Charrua left a reply on Scheduler Running Strange

The issue was caused by depleted entropy by PHP script.

To resolve the issue generate entropy by using haveged daemon:

Enable EPEL repository: yum install epel-release

Install daemon with the following command and enable it: yum install haveged

chkconfig haveged on

systemctl start haveged

10 Oct
2 months ago

Charrua left a reply on Scheduler Running With Delay (not On Time)

The issue was caused by depleted entropy by PHP script.

To resolve the issue generate entropy by using haveged daemon:

  1. Enable EPEL repository:

    yum install epel-release

  2. Install daemon with the following command and enable it:

    chkconfig haveged on
    systemctl start haveged```
    
03 Oct
2 months ago

Charrua left a reply on Scheduler Running With Delay (not On Time)

@D9705996 Really strange news. I have talked with plesk support, an engineer logged in and he returns to me that "he cant reproduce the issue.

So I logged in and now even I can't reproduce the issue, apparently all is running on time. I have asked him if he changed anything but I'm still waiting for an answer. All crons are fired on time and tasks on time.

I have checked all logs and there is no accumulation or delay for tasks. Really strange but good (for now). Yesterday and all past days the server failed one time in 10 minutes average. Now it is running for about 5 hours without any issue.

02 Oct
2 months ago

Charrua left a reply on Scheduler Running With Delay (not On Time)

the PHP5.4 is installed by OS vendor

5.4.16 by OS vendor FPM application

This is listed in plesk. Maybe I need to update the digital oceans php version to 7.1 instead of plesk...

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click Yes, Laravel needs PHP >= 7.0, so I can't run it only with php (I have tried to run scheduler but it shows an error)

php /var/www/vhosts/domain***/laravel/artisan schedule:run
PHP Parse error:  syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /var/www/vhosts/winnersmartialarts.com/laravel/artisan on line 33

I'm talking with the plesk support team so I let them finish their investigations and try to remove PHP 5.4 and make 7.1 the default and see what happens. Hope this solves the issue...

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click I think you have discovered some light...

If I run php -v the output is

PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.0.3, Copyright (c) 2002-2017, by ionCube Ltd.

So for my app I needed to use 7.1 so I searched and use /opt/plesk/php/7.1/bin/php so for example my cron's php path is /opt/plesk/php/7.1/bin/php /path/to/file.php and not php /path/to/file.php

Observation: 2 different versions here....

The light comes in when running watch -n1 php test.php or watch -n1 /opt/plesk/php/7.1/bin/php test.php

If I run the one with the php 7.1 path it hangs as cron do, but the other one does not hang...

While the system is lagged, seems that using php instead of /opt/plesk/php/7.1/bin/php keeps running. Hope this helps you to send some light to the solution

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click, yes that's what I'm thinking, something related with php/apache/nginx as you said. The app runs smooth via browser, even when the php scripts that came from cron are delayed, the app runs as usual...

Charrua left a reply on Scheduler Running With Delay (not On Time)

@shez1983 in the logs there is nothing related to what is happening. But I discovered something, someone else told me to create a bash script and test it with cron:

Bash script:

#!/bin/bash
echo $(date);
exit 0

Crontab:

* * * * * /var/www/vhosts/domain***/test.sh >> /var/www/vhosts/winnersmartialarts.com/logs/domain***/date.log

But the results surprised me, they are great:

Tue Oct 2 05:08:01 EDT 2018
Tue Oct 2 05:09:01 EDT 2018
Tue Oct 2 05:10:01 EDT 2018
Tue Oct 2 05:11:01 EDT 2018
Tue Oct 2 05:12:01 EDT 2018
Tue Oct 2 05:13:01 EDT 2018
Tue Oct 2 05:14:01 EDT 2018
Tue Oct 2 05:15:01 EDT 2018
Tue Oct 2 05:16:01 EDT 2018
Tue Oct 2 05:17:01 EDT 2018
Tue Oct 2 05:18:01 EDT 2018
Tue Oct 2 05:19:02 EDT 2018
Tue Oct 2 05:20:01 EDT 2018
Tue Oct 2 05:21:01 EDT 2018
Tue Oct 2 05:22:01 EDT 2018
Tue Oct 2 05:23:01 EDT 2018
Tue Oct 2 05:24:01 EDT 2018
Tue Oct 2 05:25:01 EDT 2018
Tue Oct 2 05:26:01 EDT 2018
Tue Oct 2 05:27:01 EDT 2018
Tue Oct 2 05:28:01 EDT 2018
Tue Oct 2 05:29:01 EDT 2018
Tue Oct 2 05:30:01 EDT 2018
Tue Oct 2 05:31:01 EDT 2018
Tue Oct 2 05:32:01 EDT 2018
Tue Oct 2 05:33:01 EDT 2018
Tue Oct 2 05:34:01 EDT 2018
Tue Oct 2 05:35:01 EDT 2018
Tue Oct 2 05:36:02 EDT 2018
Tue Oct 2 05:37:01 EDT 2018
Tue Oct 2 05:38:01 EDT 2018

So what do you think? this could be an Apache or PHP issue?

01 Oct
2 months ago

Charrua left a reply on Scheduler Running With Delay (not On Time)

I can disable nginx if you have an idea of what can be causing this.

Charrua left a reply on Scheduler Running With Delay (not On Time)

@snapey I use apache with nginx, this is by default what comes with plesk, but I can disable nginx... you can see here: https://docs.plesk.com/en-US/onyx/administrator-guide/web-servers/apache-and-nginx-web-servers-linux/apache-with-nginx.70837/

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click thank you, I will post there too.

Charrua left a reply on Scheduler Only Running Some Tasks

Hi @D9705996 I tried to remove >> /dev/null 2>&1 from the cron job but no errors are in the output. The /var/log/cron does not show any errors, only cron executions.

There is only one schedule:run for all users. Checked.

At this time, I thinking is not a Laravel issue and more of a server issue, I have disabled the scheduler cron and enable a simple plain php cron to log when this is executed, and the same results are shown.

Cron log:

Oct 1 10:01:01 localhost CROND[2315] 
Oct 1 10:02:01 localhost CROND[2388] 
Oct 1 10:03:01 localhost CROND[2440] 
Oct 1 10:04:01 localhost CROND[2493] 
Oct 1 10:05:01 localhost CROND[2566] 
Oct 1 10:06:01 localhost CROND[2627] 
Oct 1 10:07:01 localhost CROND[2743] 

Task log:

Monday, 01-Oct-2018 10:00:01 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:05:42 EDT 
Monday, 01-Oct-2018 10:06:01 EDT 
Monday, 01-Oct-2018 10:07:01 EDT 

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click my understanding of Linux stops here too, I have tried to restart the server but the same happens. This issue is driving me crazy. Thank you for your help.

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click I have disabled the laravel cron and setup another cron to log as you said timestamps, the same happens

Monday, 01-Oct-2018 10:00:01 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:05:42 EDT
Monday, 01-Oct-2018 10:06:01 EDT
Monday, 01-Oct-2018 10:07:01 EDT

Charrua left a reply on Scheduler Running With Delay (not On Time)

@click is not always at the same time:

2018-10-01 13:16:01 app.php
[2018-10-01 09:16:01] production.INFO: schedule call  
2018-10-01 13:17:01 app.php
[2018-10-01 09:17:01] production.INFO: schedule call  
2018-10-01 13:18:01 app.php
[2018-10-01 09:18:01] production.INFO: schedule call  
2018-10-01 13:19:01 app.php
[2018-10-01 09:19:02] production.INFO: schedule call  
2018-10-01 13:20:01 app.php
[2018-10-01 09:20:01] production.INFO: schedule call  
2018-10-01 13:23:22 app.php
2018-10-01 13:23:22 app.php
2018-10-01 13:23:22 app.php
[2018-10-01 09:23:22] production.INFO: schedule call  
[2018-10-01 09:23:22] production.INFO: schedule call  
[2018-10-01 09:23:22] production.INFO: schedule call  
2018-10-01 13:24:01 app.php
[2018-10-01 09:24:01] production.INFO: schedule call  
2018-10-01 13:25:01 app.php
[2018-10-01 09:25:01] production.INFO: schedule call  
2018-10-01 13:26:01 app.php
[2018-10-01 09:26:01] production.INFO: schedule call 

Charrua left a reply on Scheduler Running With Delay (not On Time)

@shez1983 When I say system is locked, I mean that if I run an any artisan command at 16:34:34, it will be queued and run at 16:37:53 (see the scheduler log I posted before). The server does not show any high load or any errors that I can relate to the times that this happens.

@Snapey web server is a Digital Ocean Droplet (if this is your question)

I don't even know if this is a php or more of a server issue... Because cron are executed on time but the artisan commands are like queued. Or maybe cron are queued too..

Charrua left a reply on Scheduler Running With Delay (not On Time)

CentOS 7.4 x64, 1vcpu, 2gbRAM, using Plesk and PHP-FPM 7.1

I think this is more of a server miss-config than a Laravel issue at this moment.

30 Sep
2 months ago

Charrua left a reply on Scheduler Running With Delay (not On Time)

@shez1983 I have tested with another cron job, independent of laravel. And the cron is also delayed when the system is "locked", it seems more of a server failure or php failure than a Laravel issue. The strange is that I can't find any errors related.

Charrua left a reply on Scheduler Running With Delay (not On Time)

Hi @Snapey I have fresh results:

I have discovered that if I execute any artisan command during the "hang up" it takes forever. Lets say you run any artisan command at 16:24 this command is not resolved until 16:27:31 (when the system is "locked out")

I have no more ideas... Have looked in logs and all that but NO CLUE. I think is not Laravel, maybe is a server issue. Server load is really little, is a droplet for a private app with 15 users. Mysql queries are not slow (I have activate the slow query log)

Cron log:

Sep 30 16:20:01 localhost CROND[28616]
Sep 30 16:21:01 localhost CROND[854]
Sep 30 16:22:02 localhost CROND[988]
Sep 30 16:23:01 localhost CROND[1062]
Sep 30 16:24:01 localhost CROND[1132]
Sep 30 16:25:01 localhost CROND[1199]
Sep 30 16:26:01 localhost CROND[1255]
Sep 30 16:27:01 localhost CROND[1315]
Sep 30 16:28:01 localhost CROND[1411]
Sep 30 16:29:01 localhost CROND[1508]
Sep 30 16:30:01 localhost CROND[1599]
Sep 30 16:31:01 localhost CROND[1670]
Sep 30 16:32:01 localhost CROND[1742]
Sep 30 16:33:01 localhost CROND[1807]
Sep 30 16:34:01 localhost CROND[1874]
Sep 30 16:35:01 localhost CROND[1936]
Sep 30 16:36:01 localhost CROND[1995]
Sep 30 16:37:01 localhost CROND[2062]

Scheduler log:

2018-09-30 16:20:12] production.INFO: schedule call  
[2018-09-30 16:21:01] production.INFO: schedule call  
[2018-09-30 16:22:02] production.INFO: schedule call  
[2018-09-30 16:23:01] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:27:31] production.INFO: schedule call  
[2018-09-30 16:28:01] production.INFO: schedule call  
[2018-09-30 16:29:01] production.INFO: schedule call  
[2018-09-30 16:30:01] production.INFO: schedule call  
[2018-09-30 16:31:01] production.INFO: schedule call  
[2018-09-30 16:32:02] production.INFO: schedule call  
[2018-09-30 16:33:01] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  
[2018-09-30 16:37:53] production.INFO: schedule call  

Charrua started a new conversation Scheduler Running With Delay (not On Time)

Laravel 5.5 PHP 7.1

I have a strange issue on production server that delays the scheduler so tasks are not fired on time. It seems that for some reason the command artisan schedule:run sometimes takes time to load. If I run artisan schedule:run from console, it runs immediately, the issue is when is fired with the cron job. I have set the cron to fire by 5 minutes instead of all minutes to see more clear.

Cron log:

Sep 29 10:05:01 localhost CROND[17311]
Sep 29 10:10:01 localhost CROND[17846]
Sep 29 10:15:01 localhost CROND[18165]

Scheduler log:

Received ping at Saturday, 29-Sep-2018 10:06:11 EDT 
Received ping at Saturday, 29-Sep-2018 10:10:01 EDT 
Received ping at Saturday, 29-Sep-2018 10:18:55 EDT

The only task the scheduler has is a simple closure to measure time, no complex tasks.

$schedule->call(function () {
            return true;
        })
        ->everyMinute()
        ->pingBefore('...')

Somebody told me this could be a server load issue or clock sync, after running uptime; sar -q; etc the results are 10:52:05 up 4:29, 1 user, load average: 0,02, 0,04, 0,05 and clock is on sync.

The real issue is that if I have a task set to run eg at 10:05, it never runs, because the scheduler is loaded at 10:06.

Any ideas?

28 Sep
2 months ago

Charrua left a reply on Scheduler Running Strange

@Snapey I agree with you is like queuing somewhere, I'm not queuing mail, and if you see the code I'm using thenPing() function and the time registry in cronhub (cron monitor) is the same.

Charrua left a reply on Scheduler Running Strange

te issue is when running scheduler at a digital ocean server, if I run it locally no problems. Any ideas?

Charrua started a new conversation Scheduler Running Strange

Hello I have a really strange issue in scheduler, sometimes runs the same task for two or three times.. I don't really know what is happening, if there is a server issue or anything else...

This is my simple scheduler code:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [

    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        
        $schedule->call(function () {
            return true;
        })->everyMinute()->emailOutputTo('...')->thenPing('https://cronhub.io/ping/af709030-c0e8-11e8-9b2f-ff58704a871a');

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }


}

Te last outputs where:

19.06
19.07
19.08
19.09
19.10
19.11
19.12
19.13

19.16
19.16
19.16

19.17
19.18

19.21
19.21
19.21

19.22
19.23

19.25
19.25

19.26

Charrua left a reply on Scheduler Only Running Some Tasks

@D9705996 so here I am again, with fresh results.

The tasks are run twice and out of four, only three have run.

Really no clue here in what is going on.

The actual scheduler code is:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\Appointments\AppCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppDayBeforeComm::class,
        \App\Console\Commands\Appointments\AppIntroCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppIntroDayBeforeComm::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        
        //appointments notification group A (vip - new)
        $schedule->command('appt:intro-day-before')->dailyAt('11:35')->emailOutputTo('email');

        $schedule->command('appt:intro-current-day')
                        ->dailyAt('11:30')
                        ->emailOutputTo('email');
                       
        //appointments notification group B (all others and goal appointments)
        $schedule->command('appt:day-before')->dailyAt('11:50')->emailOutputTo('email');

        $schedule->command('appt:current-day')
                        ->dailyAt('11:45')
                        ->emailOutputTo('email');       

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }


}

Charrua left a reply on Scheduler Only Running Some Tasks

@D9705996 yesterday I have deleted the php path and project filesystem artisan to post here, my original cron is:

* * * * *   /opt/plesk/php/7.1/bin/php /var/www/vhosts/DOMAIN/laravel/artisan schedule:run >> /dev/null 2>&1

I'll wait for today and see if the commands are fired on time, without any skip or withoutOverlapping functions.

If I run php artisan schedule:runon project folder I see only No scheduled commands are ready to run.

27 Sep
2 months ago

Charrua left a reply on Scheduler Only Running Some Tasks

@D9705996 confirmed I'm using

* * *   * * php artisan schedule:run >> /dev/null 2>&1

If I run directly php artisan schedule:run I get no errors and No scheduled commands are ready to run.

I will try to temporarily remove skip and withoutOverlap functions to see what is the result, thank you for the Carbon use to be more readable. I have implemented the withoutOverlap because some commands were running duplicate. But I will try it again and see.

@Snapey I don't see any errors in the Laravel Log. I think this is easy to search in logs as I don't have any error at the time of the execution of the commands that do not run.

Charrua started a new conversation Scheduler Only Running Some Tasks

I have my kernel.php to run some artisan commands but it runs only some of them. Any ideas why is this happening? I can run commands without any issues from console.

The commands that run today: 11.35 appt:intro-day-before 11.45 appt:current-day

All commands get a list of members and send email.

This is my file:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        \App\Console\Commands\Appointments\AppCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppDayBeforeComm::class,
        \App\Console\Commands\Appointments\AppIntroCurrentDayComm::class,
        \App\Console\Commands\Appointments\AppIntroDayBeforeComm::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        

        //appointments notification group A (vip - new)
        $schedule->command('appt:intro-day-before')
            ->dailyAt('11:35')
            ->withoutOverlapping()
            ->emailOutputTo('...');

        $schedule->command('appt:intro-current-day')
                        ->dailyAt('11:30')
                        ->skip(function () {
                            return date('N') == 6; //skip on saturday
                        })->withoutOverlapping()
                        ->emailOutputTo('...');
                        
            
        //appointments notification group B (all others and goal appointments)
        $schedule->command('appt:day-before')
            ->dailyAt('11:50')
            ->withoutOverlapping()
            ->emailOutputTo('...');

        $schedule->command('appt:current-day')
                        ->dailyAt('11:45')
                        ->skip(function () {
                            return date('N') == 6; //skip on saturday
                        })
                        ->withoutOverlapping()
                        ->emailOutputTo('...');        

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }

}

26 Sep
2 months ago

Charrua left a reply on Scheduler Running Some Tasks Twice

is more strange even, I have studied the emails results, log results and real life. The email result is the same as the real life, the log results are not all written to file. So the tasks executed where

05.00 auto:fill-twilio-sms
11.30 appt:intro-current-day
11.35 appt:intro-day-before
11.50 appt:day-before

And the only one that was not executed was 11.45 appt:current-day

Maybe is still running from yesterday but how could I know that? What tasks are still running?

Charrua left a reply on Scheduler Running Some Tasks Twice

@aurawindsurfing there are really 5 tasks here, two that run different on saturday. For example today with the code published the task that run where

05.00 auto:fill-twilio-sms
11.30 appt:intro-current-day
11.35 appt:intro-day-before
11.50 appt:day-before

the one that never run was appt:current-day

The tries per task that I have setup in supervisor are one. Maybe the task is still running from yesterday and because of that never runs today. The issue is that today no duplicate tasks run, but a task was never executed. This task send emails to the queue, some maybe have errors, but they are deleted from the current job table because they have set only one try.

Charrua started a new conversation Scheduler Running Some Tasks Twice

I have some tasks on Kernel.php scheduler to run on different times, the problem is that some of them, not all, runs twice. I'm also using supervisor with 2 processes.

My Kernel.php:

´´´

20 Aug
3 months ago

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo

problem solved creating a custom channel and a service provider to resolve NexmoCustomSmsChannel class.

Charrua left a reply on Creating Nexmo Custom Notification Channel

For someone looking for this answer, the problem was that I needed a service provider for NexmoCustomSmsChannel class to resolve.

18 Aug
3 months ago

Charrua started a new conversation Creating Nexmo Custom Notification Channel

Hello, I'm creating a new Nexmo notification channel because I need to add some client-ref parameter to the Nexmo API request.

The original channel that packs with Laravel 5.6 has a send method:

/**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return \Nexmo\Message\Message
     */
    public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }
        $message = $notification->toNexmo($notifiable);
        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }
        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
        ]);
    }

I need to add the parameter as:

        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
        'client-ref' => 'some text...',
        ]);

So I tried to duplicate the channel and instantiate it as Laravel documentation on creating custom channel (https://laravel.com/docs/5.6/notifications#custom-channels)

I have created NexmoCustomSmsChannel and only add my parameter, so the final channel is a duplicate from the original only with one extra parameter:

<?php

namespace App\Channels;

use Nexmo\Client as NexmoClient;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\NexmoMessage;


class NexmoCustomSmsChannel 
{
    /**
     * The Nexmo client instance.
     *
     * @var \Nexmo\Client
     */
    protected $nexmo;

    /**
     * The phone number notifications should be sent from.
     *
     * @var string
     */
    protected $from;

    /**
     * Create a new Nexmo channel instance.
     *
     * @param  \Nexmo\Client  $nexmo
     * @param  string  $from
     * @return void
     */
    public function __construct(NexmoClient $nexmo, $from)
    {
        $this->from = $from;
        $this->nexmo = $nexmo;
    }

    /**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return \Nexmo\Message\Message
     */
    public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }

        $message = $notification->toVoice($notifiable);

        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }

        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
            'client-ref' =>  'some text...',
        ]);
    }
}

And my notification is like:

<?php

namespace App\Notifications\Appointments;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

use App\Channels\NexmoCustomSmsChannel;


class AppIntroNew extends Notification implements ShouldQueue
{
    use Queueable;


    private $appointment;


    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($appointment)
    {
        $this->appointment = $appointment;
    }



    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [NexmoCustomSmsChannel::class];
    }



    /**
     * Get the Nexmo / SMS representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return NexmoMessage
     */
    public function toVoice($notifiable)
    {
        return (new NexmoMessage)->content('some sms content.');
    }
    
}

The error I get is:

[2018-08-18 04:23:58] local.ERROR: Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. {"exception":"[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. at /Users/.../Documents/Web/.../app/vendor/laravel/framework/src/Illuminate/Container/Container.php:918)

Any ideas?

17 Aug
3 months ago

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo

@crnkovic I have created App\Channels\NexmoCustomSmsChannel and copied the code, added the parameter I need but I get an error.

My Nexmo custom channel looks like this:

namespace App\Channels;

use Nexmo\Client as NexmoClient;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\NexmoMessage;

class NexmoCustomSmsChannel 
{
    /**
     * The Nexmo client instance.
     *
     * @var \Nexmo\Client
     */
    protected $nexmo;

    /**
     * The phone number notifications should be sent from.
     *
     * @var string
     */
    protected $from;

    /**
     * Create a new Nexmo channel instance.
     *
     * @param  \Nexmo\Client  $nexmo
     * @param  string  $from
     * @return void
     */
    public function __construct(NexmoClient $nexmo, $from)
    {
        $this->from = $from;
        $this->nexmo = $nexmo;
    }

    /**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return \Nexmo\Message\Message
     */
    public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('nexmo')) {
            return;
        }

        $message = $notification->toVoice($notifiable);

        if (is_string($message)) {
            $message = new NexmoMessage($message);
        }

        return $this->nexmo->message()->send([
            'type' => $message->type,
            'from' => $message->from ?: $this->from,
            'to' => $to,
            'text' => trim($message->content),
            'client-ref' => $message->client_ref,
        ]);
    }
}

And the error I get is:

[2018-08-17 12:22:10] local.ERROR: Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. {"exception":"[object] (Illuminate\Contracts\Container\BindingResolutionException(code: 0): Target [Nexmo\Client\Credentials\CredentialsInterface] is not instantiable while building [App\Channels\NexmoCustomSmsChannel, Nexmo\Client]. at /Users/.../Documents/Web/.../app/vendor/laravel/framework/src/Illuminate/Container/Container.php:918)

Any ideas?

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo

@crnkovic I have also found that file and my understanding is like you said, this method is only sending those parameters, so maybe I need to duplicate this channel as you said and add the client-ref parameter and test.

Maybe this has an easiest way but I cant find any on the web...

Charrua left a reply on Use ClientRef Value When Sending SMS With Nexmo

Yes I understand that, but I'm looking for a way to do it inside the notification (I'm also listening to some events)

Something like return (new NexmoMessage)->content('text')->clientRef('25');

Charrua started a new conversation Use ClientRef Value When Sending SMS With Nexmo

Hello, I'm using SMS notification alerts using Nexmo. Searching their API I can see a custom information field that I can use for sending additional information attached to the SMS, this is the client-ref.

You can see it here 'https://developer.nexmo.com/api/sms#send-an-sms' under 'Request body'

This is my notification code:

    /**
         * Get the Nexmo / SMS representation of the notification.
         *
         * @param  mixed  $notifiable
         * @return NexmoMessage
         */
        public function toNexmo($notifiable)    {
            
    return (new NexmoMessage)->content('Congratulations! You have an appt with .... Please text C to CONFIRM.');

        }

Any ideas in how to send also the client-ref parameter?

13 Aug
3 months ago

Charrua left a reply on Trigger Notification On Bulk Insert

@wilburpowery unfortunately ModelName::create($array-of-data) only creates one at a time, remember I need to create a bulk insert. And ModelName::insert($array-of-data) doesn't fire any events:

Model doesn't have an insert method. Calling Model::insert results in a call to Builder::insert through the __call() magic method.

As I need to insert a maximum of 20 bulk records, I ended up by doing:

foreach ($array-of-data as $item){
    $appointment = \App\GoalAppointment::create($item);
    $appointment->notify(new AppNew($appointment));
}
10 Aug
4 months ago

Charrua left a reply on Trigger Notification On Bulk Insert

@wilburpowery great but instead to use an event, can I fire the notification directly from that method?

For example:

public static function boot()
{
    parent::boot();
    
    static::created(function ($appointment) {
        $appointment->notify(new AppIntroNew($appointment));
    })
}

@Cronix I understand that using DB query builder does not fire any model events. I need to create in some way a bulk insert, lets say 100 records... Why would be the Eloquent way? I have found some information on using ModelName::insert($array);, this would be the Eloquent way? and this will trigger the create method that @wilburpowery refers to? Or this will trigger the event and therefore I need to create the listener with the notification fire?

Thank you both.

09 Aug
4 months ago

Charrua started a new conversation Trigger Notification On Bulk Insert

Hi, I'm actually saving into the database appointments by inserting them in bulk.

DB::table('goals_appointments')->insert( $appointments_array );

Is there a way to trigger a notification to each appointment inserted?