How to try queue again in Laravel 5.2?

I am trying to send SMS using my laravel project for that purpose I wrote function in MessageController named sendSms. I am pushing message data to a queue named SendScheduledSms and handler as follows.

public function handle()
    {
        $sentsms = App::make('App\Http\Controllers\MessageController')->sendSms($this->post_data);
    }

Sending SMS works properly. $sentsms is the status of sent SMS. There are two values for $status, success and fail. I want to re-try sending same SMS if status is fail. How can I do that? Now when sendSms executed, it deletes the queue.

I am using database queue.

Can anyone help?


ANSWERS:


In order to trigger Laravel Queue's native retry functionality, your Job handle method will need to throw an error at some point.

if ($sentsms == 'fail') {
    throw new Exception('SMS failed to send.');
}

If you have a failed_jobs table set up the job should be moved there by Laravel. See the documentation on Retrying failed jobs.

In your console schedule method set the --tries flag to have Laravel automatically rerun failed jobs.

$schedule->command("queue:work --tries=3")->everyMinute();


 MORE:


 ? Not able to update cloudformation stack when having AWS SNS:Topic Resource
 ? AWS Lambda S3 Bucket Notification via CloudFormation
 ? AWS Lambda subscribed to SNS topic doesn't process all messages to the topic
 ? How do we access and respond to CloudFormation custom resources using an AWS Lambda function written in Java?
 ? Not able to update cloudformation stack when having AWS SNS:Topic Resource
 ? How can a SNS topic be specified as a trigger for a CodeDeploy deployment group using CloudFormation?
 ? AWS Scheduled Event Rule for Lambda doesn't work in CloudFormation
 ? How to publish sns to a specific endpoint?
 ? How to confirm subscribe and get SNS Notifications at a HTTP endpoint?
 ? Why Amazon sends confirmation request for SNS several times