Giter Club home page Giter Club logo

thinksns-old-code's People

Contributors

28youth avatar anyibuanyi avatar boxshadow avatar hhhcode avatar medongdong avatar medz avatar this-baishi avatar zsyd avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

thinksns-old-code's Issues

视频异步转换bug,如果原始文件不存在或者转换失败,任务一直卡在错误条数

VideoModel.class.phpvideo_transfer 方法中:

public function video_transfer()
    {
        $video_list = D('video_transfer')->where('status=0')->order('transfer_id Asc')->limit(3)->findAll();
        // dump($video_list);exit;
        if ($video_list) {
            set_time_limit(0);
            $video_config = model('Xdata')->get('admin_Content:video_config');
            if (PATH_SEPARATOR == ':') {  //Linux
                $ffmpegpath = $video_config['ffmpeg_path'];
            } else {     //Windows
                $ffmpegpath = SITE_PATH.$video_config['ffmpeg_path'];
            }
            foreach ($video_list as $k => $v) {
                if (file_exists(SITE_PATH.$v['sourceSavePath'].'/'.$v['video_source_name'])) {
                    $sourceSavePath = SITE_PATH.$v['sourceSavePath'];
                    $savePath = SITE_PATH.$v['savePath'];
                    $command = $ffmpegpath.' -y -i '.$sourceSavePath.'/'.$v['video_source_name'].' -vcodec libx264 '.$savePath.'/'.$v['video_name'];
                    exec($command);

                    if (file_exists($savePath.'/'.$v['video_name'])) {
                        D('video_transfer')->where('transfer_id='.$v['transfer_id'])->setField('status', 1);
                        $feed_id = D('video_transfer')->where('transfer_id='.$v['transfer_id'])->getField('feed_id');
                        model('Feed')->cleanCache(array($feed_id));
                    }
                } else {
                    continue;
                }
            }
        }
    }

如果删除原始视频为止会造成任务一直卡在这里,因为这个转换任务一直存在。如果转换失败,同理也会一直卡在这里。

修复方法

  • 判断原始视频是否存在,如果不存在,删除转换记录。
  • 判断任务创建时间,如果任务时间超过 1 天,则删除任务。
  • video_transfer 增加 转换中状态,现在只有 status 标识 是否在转换,增加 transforming 查询是否已经在转换中。

具体实施

首先查询出所有超过一天 transforming 状态的转换记录,删除,然后查询出 非 transforming 状态 但是 status 为 0 的记录(可能三条),判断这条记录是否超过一天,超过删除,再判断原始文件是否存在,不存在删除,最后判断分片文件是否存在,存在则设置 status 为 1 和 transforming 设置为转换完成状态,如果分片不存在,则执行命令,开始转换视频,同时将该记录的 transforming 设置在正在转换状态,以免下次执行计划任务依旧查询出来。

更多意见

建议重新编辑 转换视频 的计划任务,将任务时间设置为 null 或者 空,或者 000-00-00 00:00:00 达到任务不过期。现在出现的问题是,默认三个任务,有两个任务已经过期了,计划任务不会执行。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.