Browse Source

scurve queue

pull/3/head
wahyu 1 year ago
parent
commit
ff353fbf53
  1. 13
      app/Http/Controllers/ProjectController.php
  2. 36
      app/Jobs/ProcessSCurve.php
  3. 36
      database/migrations/2023_08_29_130624_create_jobs_table.php

13
app/Http/Controllers/ProjectController.php

@ -30,6 +30,7 @@ use Illuminate\Support\Facades\DB;
use App\Helpers\MasterFunctionsHelper;
use App\Models\ReportActivityMaterial;
use Illuminate\Support\Facades\Artisan;
use App\Jobs\ProcessSCurve;
const API_GEOLOCATION = "https://nominatim.oslogdev.com/search/ADDR?format=json&addressdetails=1&limit=1";
@ -328,9 +329,15 @@ class ProjectController extends Controller
}
public function sCurveCommand(Request $request){
Artisan::call('calculate:scurve', [
'project_id' => $request->project_id
]);
$project = Project::find($request->project_id);
if ($project) {
dispatch(new ProcessSCurve($project));
return response()->json(['message' => 'S Curve calculation queued']);
}
return response()->json(['message' => 'Project not found'], 404);
}
public function getLinearSCurve(Request $request){

36
app/Jobs/ProcessSCurve.php

@ -0,0 +1,36 @@
<?php
namespace App\Jobs;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Queue;
use App\Helpers\MasterFunctionsHelper;
use App\Models\Project;
class ProcessSCurve extends Job
{
protected $project;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Project $project)
{
$this->project = $project;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$data = MasterFunctionsHelper::CalculateSCurve($this->project->id);
$this->project->scurve = json_encode($data);
$this->project->calculation_status = true;
$this->project->save();
}
}

36
database/migrations/2023_08_29_130624_create_jobs_table.php

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}
Loading…
Cancel
Save