99use Illuminate \Support \Facades \DB ;
1010use Illuminate \Support \Facades \Schema ;
1111use Storvia \Vantage \Models \VantageJob ;
12+ use Storvia \Vantage \Support \JobRestorer ;
1213use Storvia \Vantage \Support \QueueDepthChecker ;
1314use Storvia \Vantage \Support \TagAggregator ;
1415use Storvia \Vantage \Support \VantageLogger ;
@@ -424,7 +425,7 @@ public function retry($id)
424425 }
425426
426427 // Safely restore job from payload with security checks
427- $ job = $ this -> restoreJobFromPayload ($ run , $ jobClass );
428+ $ job = app (JobRestorer::class)-> restore ($ run , $ jobClass );
428429
429430 if (! $ job ) {
430431 return back ()->with ('error ' , 'Unable to restore job. Payload might be missing or corrupted. ' );
@@ -450,92 +451,6 @@ public function retry($id)
450451 }
451452 }
452453
453- /**
454- * Safely restore job from payload with security checks.
455- *
456- * @param VantageJob $run The job run record
457- * @param string $expectedJobClass The expected job class name for validation
458- * @return object|null The restored job object or null on failure
459- */
460- protected function restoreJobFromPayload (VantageJob $ run , string $ expectedJobClass ): ?object
461- {
462- if (! $ run ->payload ) {
463- return null ;
464- }
465-
466- // Validate expected class exists and is a valid job class
467- if (! class_exists ($ expectedJobClass )) {
468- VantageLogger::warning ('Vantage: Expected job class does not exist ' , [
469- 'run_id ' => $ run ->id ,
470- 'expected_class ' => $ expectedJobClass ,
471- ]);
472-
473- return null ;
474- }
475-
476- try {
477- $ payload = is_array ($ run ->payload ) ? $ run ->payload : json_decode ($ run ->payload , true );
478-
479- if (! is_array ($ payload )) {
480- VantageLogger::warning ('Vantage: Invalid payload format ' , ['run_id ' => $ run ->id ]);
481-
482- return null ;
483- }
484-
485- // Get the serialized command from Laravel's raw payload
486- $ serialized = $ payload ['raw_payload ' ]['data ' ]['command ' ] ?? null ;
487-
488- // Fallback to old format if new format not available
489- if (! $ serialized ) {
490- $ serialized = $ payload ['data ' ]['command ' ] ?? null ;
491- }
492-
493- if (! $ serialized || ! is_string ($ serialized )) {
494- VantageLogger::warning ('Vantage: No serialized command in payload ' , ['run_id ' => $ run ->id ]);
495-
496- return null ;
497- }
498-
499- // Unserialize with security: only allow the expected job class
500- $ job = @unserialize ($ serialized , ['allowed_classes ' => [$ expectedJobClass ]]);
501-
502- if (! is_object ($ job )) {
503- VantageLogger::warning ('Vantage: Unserialize did not return object ' , [
504- 'run_id ' => $ run ->id ,
505- 'result_type ' => gettype ($ job ),
506- ]);
507-
508- return null ;
509- }
510-
511- // Double-check the class matches the expected class (security validation)
512- if (! $ job instanceof $ expectedJobClass ) {
513- VantageLogger::warning ('Vantage: Unserialized job class does not match expected class ' , [
514- 'run_id ' => $ run ->id ,
515- 'expected_class ' => $ expectedJobClass ,
516- 'actual_class ' => get_class ($ job ),
517- ]);
518-
519- return null ;
520- }
521-
522- VantageLogger::info ('Vantage: Successfully restored job ' , [
523- 'run_id ' => $ run ->id ,
524- 'job_class ' => get_class ($ job ),
525- ]);
526-
527- return $ job ;
528-
529- } catch (\Throwable $ e ) {
530- VantageLogger::error ('Vantage: Exception while restoring job from payload ' , [
531- 'run_id ' => $ run ->id ,
532- 'error ' => $ e ->getMessage (),
533- ]);
534-
535- return null ;
536- }
537- }
538-
539454 /**
540455 * Get retry chain
541456 */
0 commit comments