laravel-db2 is a simple DB2 service provider for Laravel. It provides DB2 Connection by extending the Illuminate Database component of the laravel framework.
Other
59
stars
65
forks
source link
could not find driver {"exception":"[object] (PDOException(code: 0): #38
I've setup a scheduled task to run every 5 minutes to update query results in redis cache.
app\Console\Kernel.php
namespace App\Console;
use App\Jobs\QueryLoadsJob;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
protected function schedule(Schedule $schedule)
{
$schedule->job(new QueryLoadsJob())->everyFiveMinutes();
}
QueryLoadsJob.php
namespace App\Jobs;
use App\Repositories\LoadRepositoryEloquent;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class QueryLoadsJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @param LoadRepositoryEloquent $load_repository_eloquent
*
* @return void
*/
public function handle(LoadRepositoryEloquent $load_repository_eloquent)
{
$load_repository_eloquent->getLoads();
}
}
My LoadsRepositoryEloquent.php
namespace App\Repositories;
use Illuminate\Support\Facades\Cache;
use Redis;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\LoadRepository;
use App\Models\Load;
use App\Validators\LoadValidator;
class LoadRepositoryEloquent extends BaseRepository implements LoadRepository
{
/**
* Specify Model class name
*
* @return string
*/
public function model()
{
return Load::class;
}
/**
* Specify Validator class name
*
* @return mixed
*/
public function validator()
{
return LoadValidator::class;
}
public function getLoads() {
$loads = Cache::remember('loads_waiting_cache', 5, function ()
{
return $this->model::doors()
->scheduled()
->admitted()
->notRejected()
->notReturned()
->stillHere()->get();
});
return $loads;
}
}
my model Loads.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
use Carbon\Carbon;
use App\Scopes\gblGateScope;
use App\Scopes\gblLimitScope;
use App\Scopes\gblMillScope;
class Load extends Model implements Transformable
{
use TransformableTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [];
public $connection = 'QISDB';
protected $table = 'USERID.SHIPCAR';
protected $primarykey = null;
public $incrementing = false;
public $timestamps = false;
protected static function boot() {
parent::boot();
// sets the SHPCAR_MILL to M for all queries
static::addGlobalScope(new gblMillScope());
// sets the SHPCAR_GATE_LOC to W for all queries
static::addGlobalScope(new gblGateScope());
// sets the limit to 1000 just in case
static::addGlobalScope(new gblLimitScope());
}
/**
* Door scope for door numbers to be included in query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDoors($query){
return $query->wherein('USERID.SHIPCAR.SHPCAR_DOOR1',['77', '78', '166', '167', '185A', '191']);
}
public function scopeAdmitted($query){
return $query->where('USERID.SHIPCAR.SHPCAR_LOAD_ADMT_D','<>','9999-01-01');
}
public function scopeStillHere($query){
return $query->where('USERID.SHIPCAR.SHPCAR_COMP_LD_DT','=','9999-01-01');
}
public function scopeScheduled($query){
$startTime = Carbon::now()->subHour(36)->format('Y-m-d');
$endTime = Carbon::now()->addHour(12)->format('Y-m-d');
return $query->whereBetween('USERID.SHIPCAR.SHPCAR_SCHD_PU_D',[$startTime, $endTime])
->where('USERID.SHIPCAR.SHPCAR_SCHD_PU_D','<>','9999-01-01');
}
public function scopeNotRejected($query){
return $query->where('USERID.SHIPCAR.SHPCAR_REJECT_DT','=','9999-01-01');
}
public function scopeNotRescheduled($query){
return $query->where('USERID.SHIPCAR.SHPCAR_RESCHD_DT','=','9999-01-01');
}
public function scopeNotReturned($query){
return $query->where('USERID.SHIPCAR.SHPCAR_RETURN_DT','=','9999-01-01');
}
}
If I call the repository's getLoads() from a controller, the results come back fine. Running the QueryLoadsJob results in a 'could not find driver {"exception":"[object] (PDOException(code: 0): could not find driver at /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68)'
Do I need to inject the model somewhere so the Job can find the database connection? Why would the connection work in the controller and not from the job? Any ideas (or a workaround)? Thanks.
I've setup a scheduled task to run every 5 minutes to update query results in redis cache.
app\Console\Kernel.php
QueryLoadsJob.php
My LoadsRepositoryEloquent.php
my model Loads.php
DB2 connection setup
If I call the repository's getLoads() from a controller, the results come back fine. Running the QueryLoadsJob results in a 'could not find driver {"exception":"[object] (PDOException(code: 0): could not find driver at /var/www/ep2/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68)'
Do I need to inject the model somewhere so the Job can find the database connection? Why would the connection work in the controller and not from the job? Any ideas (or a workaround)? Thanks.
First 10 items in stack trace: