|
|
@@ -6,6 +6,7 @@ namespace SixShop\Core\Job;
|
|
|
|
|
|
use Closure;
|
|
|
use Exception;
|
|
|
+use ReflectionFunction;
|
|
|
use think\facade\Log;
|
|
|
use think\queue\Job;
|
|
|
use Throwable;
|
|
|
@@ -27,7 +28,17 @@ abstract class BaseJob
|
|
|
public static function dispatch(mixed $data = '', int $delay = 0, ?string $queue = null): JobDispatcher
|
|
|
{
|
|
|
if ($data instanceof Closure) {
|
|
|
- $data = ['__job_closure__' => serialize($data)];
|
|
|
+ $ref = new ReflectionFunction($data);
|
|
|
+ $file = (string) $ref->getFileName();
|
|
|
+ // 转为相对于 backend/ 的路径
|
|
|
+ $baseDir = dirname(__DIR__, 5);
|
|
|
+ if (str_starts_with($file, $baseDir . '/')) {
|
|
|
+ $file = substr($file, strlen($baseDir) + 1);
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ '__job_closure__' => serialize($data),
|
|
|
+ '__job_name__' => $file . ':' . $ref->getStartLine(),
|
|
|
+ ];
|
|
|
}
|
|
|
return new JobDispatcher(static::class, $data, $delay, $queue);
|
|
|
}
|