1

In Controller:

$smsData = [
            'number'    =>  $customer->phone,
            'message'   =>  'Test',
        ];

        $job = (new SendMessage($smsData))->delay(env('DELAY_QUEUE'))->onQueue(env('SMS_QUEUE'));

        $this->dispatch($job);

SendMessage class:

<?php

namespace App\Jobs;

use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
//use Guzzle\Http\Client;

class SendMessage extends Job implements ShouldQueue {

    protected $data, $url;

    use InteractsWithQueue, SerializesModels;

    public function __construct(array $data) {
        $this->data = $data;
        $this->url = 'https://reguler.zenziva.net/apps/smsapi.php?userkey=' . env('ZENZIVA_USERKEY') . '&passkey=' . env('ZENZIVA_PASSKEY');
    }

    public function handle() {
        $client = new \GuzzleHttp\Client();
        $smsData = $this->data;
        $res = $client->request('GET', $this->url . '&nohp=' . $smsData['number'] . '&pesan=' . $smsData['message']);
        if ($res->getStatusCode() !== 200) { \Log::info($res->getBody()); }
        $this->delete();
        return \Response::json(['type' => 'success'], 200);
    }

}

The SMS does go through, but the queue is not removed from iron (thus sending multiple same SMS, returning NO RESPONSE CODE AT ALL).

Weirdly, if I skip the guzzle request, the queue is removed from iron, thus the POST returns response 200.

Any idea how to fix this?

user2002495
  • 2,126
  • 8
  • 31
  • 61
  • Sure your code isn't hitting a fatal error, preventing it from reaching the line where you delete the queue job? Might want to try/catch. Or add debug logging when you delete, so you can confirm that it ran. – jszobody Mar 02 '16 at 15:39
  • @jszobody already did that, no logs, no errors, the sms DOES go through – user2002495 Mar 02 '16 at 15:42

1 Answers1

0

Most likely, you're using a deprecated version of IronMQ plugin for Laravel. The new IronMQ version requires 2 parameters to delete a job: message_id and reservation_id. The old plugin passes only message_id so the job is not deleted and continue staying in queue.

Feel free to use this Laravel driver for IronMQ. It's designed for different Laravel versions including 5.2.

Alex
  • 16
  • 2