IronMQ and Laravel: Implementation

Posted by Unknown on Friday, May 23, 2014

Welcome back to the IronMQ and Laravel series - this is the second and final part in which we finalize our background-job enabled web app.


There are several tutorials out there related to queues already - for example: http://vimeo.com/64703617 where Taylor teaches you how to write to a file using queues. In this tutorial, we will try something different.


We will make a jobs table which has job_id, and the status of the job. When you put a job on the queue, the job status will be queued and when we receive the job, we set the status to running. Accordingly, after finishing it we will mark it finished.


Later, we will resize images.


Jobs Table


Step 1


Let’s create a jobs table:



php artisan migrate:make create_jobs_table


Go to app/database/migrations/xxxxx_create_jobs_table.php and add the following (This code is extracted from app/database/migrations/xxxxx_create_jobs_table.php, so edit your file accordingly):



public function up()
{
Schema::create('jobs', function($table)
{
$table->increments('id');
$table->string('job_id');
$table->enum('status', array('queued', 'running','finished'))->default('queued');
$table->timestamps();
});
}

public function down()
{
Schema::drop('jobs');
}


Here we created a table with the columns job_id, status and timestamps. Run php artisan migrate to create the table.


Step 2


Create a file job.php in app/models with the following content:



<?php

class Job extends Eloquent {

protected $table = 'jobs';

protected $fillable = array('job_id', 'status');

}


Make a JobController using the following command:



php artisan controller:make JobController


and add the following in the app/routes.php file:



Route::resource('job','JobController');


Go to JobController populate the index method.



public function index()
{
$jobs = Job::all();

return View::make('job.index')->with('jobs',$jobs);
}


Continue reading %IronMQ and Laravel: Implementation%




more

{ 0 comments... » IronMQ and Laravel: Implementation read them below or add one }

Post a Comment

Popular Posts