Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在队列(think-queue)中调用出错 #10

Open
xzusoft opened this issue Dec 21, 2018 · 18 comments
Open

在队列(think-queue)中调用出错 #10

xzusoft opened this issue Dec 21, 2018 · 18 comments
Labels
bug Something isn't working

Comments

@xzusoft
Copy link

xzusoft commented Dec 21, 2018

`namespace app\home\queue;
use think\queue\Job;

use Naixiaoxin\ThinkWechat\Facade;
use app\home\model\Wechat;

class ReleaseCode{

public function fire(Job $job, $data){
  $data = json_decode($data, true);
  $openPlatform = Facade::openPlatform();
    $miniProgram = $openPlatform->miniProgram($data['program']['authorizer_appid'], $data['program']['refresh_token']);
    $code = $miniProgram->code;
    $category = $code->getCategory();
    $page = $code->getPage();
    
    $config = json_decode($data['program']['config'], true);
    //获取已授权小程序设置的类目 get_category
    if((int)$category['errcode'] === 0){
        $config['category'] = $category['category_list'];
    }
    //获取小程序的第三方提交代码的页面配置 get_page
    if((int)$page['errcode'] === 0){
        $config['page'] =   $page['page_list'];
    }
    if(!Wechat::update(['id'=>$data['program']['id'],'config'=>json_encode($config)])){
        //TODO  收集错误
        $job->release(2);
    }
    $job->delete();
    if ($job->attempts() > 3) {
        //通过这个方法可以检查这个任务已经重试了几次了
        $job->delete();
    } 
}

}命令端运行报[think\exception\ClassNotFoundException]
class not exists: wechat.open_platform `

这个是怎么回事?

@xzusoft
Copy link
Author

xzusoft commented Dec 21, 2018

"naixiaoxin/think-wechat": "^1.4",
"topthink/think-queue": "^2.0",

@qiqizjl qiqizjl added the bug Something isn't working label Dec 21, 2018
@qiqizjl
Copy link
Owner

qiqizjl commented Dec 21, 2018

#9 一个问题 正在解决中

@xzusoft
Copy link
Author

xzusoft commented Dec 21, 2018

这是什么原因导致的呢?说出来,大家一起来想想办法来解决

@qiqizjl
Copy link
Owner

qiqizjl commented Dec 22, 2018

目前来看是在命令行模式下 容器的关系绑定有些问题 怀疑是本身TP设计缺陷 正在尝试解决

@qiqizjl
Copy link
Owner

qiqizjl commented Dec 28, 2018

hi
尝试在app/tags.php中 app_init增加我的行为扩展

    'app_init'     => [
        \Naixiaoxin\ThinkWechat\Behavior\AppInit::class
    ],

@xzusoft
Copy link
Author

xzusoft commented Dec 28, 2018

错误还是依然存在

@xzusoft
Copy link
Author

xzusoft commented Dec 29, 2018

作者测试是可以的吗?????

@qiqizjl
Copy link
Owner

qiqizjl commented Dec 29, 2018

还以为和Swoole是一个问题~~
确实是有问题。
我是在app_init钩子里注入了我的类。但是app_init只要在\think\App:run里才执行,并不会在queue里执行。我这边还在想另外的办法去解决这个问题

@xzusoft
Copy link
Author

xzusoft commented Dec 29, 2018

看来是无解了 肿么办呢 .....

@qiqizjl
Copy link
Owner

qiqizjl commented Dec 29, 2018

已经给官方提交了issue
top-think/framework#1600

@qiqizjl
Copy link
Owner

qiqizjl commented Dec 29, 2018

我将作为app_init类初始化的原因其实就是因为认为app_init是任何初始化都会执行的。
而且官方文档中说明的也是如此
image
但是事与愿违,app_init却在run函数里才执行。run函数是用来调度路由/执行http业务的。所以在路由中是正常的,但是在命令行中是有异常的。

@browningweb
Copy link

在 Swoole 环境下也出现了如上问题,例如异步任务,目前的解决方案就是调用之前先进行:
$appInit = new AppInit(); $appInit->run();

@qiqizjl
Copy link
Owner

qiqizjl commented May 10, 2019

官方给的方案 其实是建议自己在Console文件里加钩子。。这样就改动了官方的源码了
就因为这个不多导致的。。
详见top-think/framework#1600

@w263756314
Copy link

今天遇到同样的问题 。。。

@w263756314
Copy link

@qiqizjl
我在 think 里加了
$appInit = new \Naixiaoxin\ThinkWechat\Behavior\AppInit();
$appInit->run();
1楼的报错已经绕过,但是出现新的问题
Credential "component_verify_ticket" does not exist in cache.
请问这个应该怎么填 ?

@qiqizjl
Copy link
Owner

qiqizjl commented Aug 10, 2019

@w263756314 你用的是三方开发平台? 三方开发平台需要先让微信回调ticket才可以

@w263756314
Copy link

@qiqizjl 已解决哈,谢谢
解决记录我发在这里了 解决办法

@ideaviewes
Copy link

现在这个问题有办法解决吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants