Horizon 检测不到队列任务和错误
启动Horizon后,可以看到dashboard并且在terminal可以看到Horizon started successfully.
此时还没有进行到 “6. 代码调整” 这一步,也就是说序列化的问题依然存在,可是无论是创建/更新话题,什么也检测不到。请大神们指教。谢谢。
class TopicObserver
{
public function saving(Topic $topic)
{
$topic->body = clean($topic->body, 'user_topic_body');
$topic->excerpt = make_excerpt($topic->body);
// 此处做了小修改,判断title是否未空,如果用slug,无法进行更新
if (!$topic->title) {
// push the 'JOB' into the 'QUEUE'
dispatch(new TranslateSlug($topic));
}
}
}
class TranslateSlug implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $topic;
public function __construct(Topic $topic)
{
$this->topic = $topic;
}
public function handle()
{
//无法注册百度API,所以此处没有采用教程的方法,进行了简化,对$topic->title进行简单处理然后写入slug
//个人觉得,即使不使用百度API,也不应该影响队列的使用
$slug = connect_string_with_dash($this->topic->title);
\DB::table('topics')->where('id', $this->topic->id)->update(['slug' => $slug]);
}
}
//这个方法写在全局helpers.php里面,简单的字符串处理
function connect_string_with_dash($input){
if (!isset($input) && empty($input)) {
return false;
}
$tmp_output = explode(' ', preg_replace('/\s+/', ' ', trim($input)));
$output = implode('-', $tmp_output);
return $output;
}
推荐文章: