Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[已回应] 后台自定义的计划任务重复执行怎么解决

[复制链接]
slfhelgq 发表于 2015-6-25 08:05:39 | 显示全部楼层 |阅读模式
            前段时间,给 forum_thread   表 加了个分表 ,每天早上 6:00  执行此计划,  在添加数据的时候,有时正常执行添加数据,有时会出现 重复添加的现象。            网上找了找相关问题:说 后台计划任务,由于服务器不稳定,或者其他原因,在计划任务时,没有执行完成,导致计划任务重复执行,引起添加数据重复。
           求助大神,或遇到此类问题的挚友伸出援助之手



 楼主| slfhelgq 发表于 2015-6-25 09:33:51 | 显示全部楼层
    求助大神,或遇到此类问题的挚友伸出援助之手
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 10:13:29 | 显示全部楼层
:'(:'(:'(:'(:'(:'(:'(   加把劲呀 ,看来 是个高难度问题吗
回复

使用道具 举报

ARCHY` 发表于 2015-6-25 11:48:02 | 显示全部楼层
分表  自动处理?

因为程序自身处理会比较慢,一般出现延时就会导致分表失败或出错,一般需要手动去执行,不要使用自动
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 13:51:04 | 显示全部楼层
你是站帮网的老师吧 我看过你的视频呵呵  您好
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 13:53:46 | 显示全部楼层
ARCHY` 发表于 2015-6-25 11:48
分表  自动处理?

因为程序自身处理会比较慢,一般出现延时就会导致分表失败或出错,一般需要手动去执行 ...

您好,是不是写的程序 有问题呢,“因为程序自身处理会比较慢......”,是 自己写的程序运行慢 还是与  discuz  计划任务运行机制 慢有关系,有时候有些任务计划还不执行的现象 ,站帮网 老师 帮帮忙,我看过您讲的seo视频
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 14:07:07 | 显示全部楼层
slfhelgq 发表于 2015-6-25 13:53
您好,是不是写的程序 有问题呢,“因为程序自身处理会比较慢......”,是 自己写的程序运行慢 还是与  d ...

现在写的计划任务,正常执行时,数据就不会出现重复现象,而且数据 添加对应正确,一有问题就会数据重复出现
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 14:08:29 | 显示全部楼层
slfhelgq 发表于 2015-6-25 13:53
您好,是不是写的程序 有问题呢,“因为程序自身处理会比较慢......”,是 自己写的程序运行慢 还是与  d ...

现在数据大约是16万条(分表中的数据)  主题表中的数据是(500多万条)。  老师 再给点思路吧
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 14:11:10 | 显示全部楼层
ARCHY` 发表于 2015-6-25 11:48
分表  自动处理?

因为程序自身处理会比较慢,一般出现延时就会导致分表失败或出错,一般需要手动去执行 ...


现在写的计划任务,正常执行时,数据就不会出现重复现象,而且数据 添加对应正确,一有问题就会数据重复出现
现在数据大约是16万条(分表中的数据)  主题表中的数据是(500多万条)。  老师 再给点思路吧
回复

使用道具 举报

 楼主| slfhelgq 发表于 2015-6-25 14:17:39 | 显示全部楼层
ARCHY` 发表于 2015-6-25 11:48
分表  自动处理?

因为程序自身处理会比较慢,一般出现延时就会导致分表失败或出错,一般需要手动去执行 ...



if(!defined('IN_DISCUZ'))
{
        exit('Access Denied');
}
        $strsql_forum_fp="select fid from forum_forum where fid !=14 and status=1 and type !='group' order by fid asc ";//版块循环,取出来
        $result_forum_fp=DB::fetch_all($strsql_forum_fp);
        if($result_forum_fp)
        {
        foreach($result_forum_fp as $key =>$val)
          {               
                   $strsql_thread_each_1="select tid from forum_thread_index_20150602 where fid=".$val['fid']." order by tid desc limit 0,1";//查找分表中这一板块的最大 tid
                   $result_thread_each_1=DB::fetch_first($strsql_thread_each_1);
                   if( !$result_thread_each_1['tid'])
                   {
                           $result_thread_each_1['tid']=1;
                   }
                   $strsql_thread_each_2="select tid,fid,sortid,author,authorid,subject,dateline,special,heats,stamp from forum_thread where fid=".$val['fid']." and tid >".$result_thread_each_1['tid']." and hidden=0 order by tid desc limit 0,50"; //获取50条大于分表中取出的最大 tid
                   $result_thread_each_2=DB::fetch_all($strsql_thread_each_2);                         
                   if($result_thread_each_2)
                {  
                      foreach($result_thread_each_2 as $key => $val)
                      {                                            
                            $strsql_check="SELECT tid FROM  forum_thread_index_20150602 where fid=".$val['fid']." and tid =".$val['tid']; //如果分表中有重复的便停止运行计划任务
                            $result_check=DB::fetch_first($strsql_check);
                           if( !$result_check )
                            {
                  $strsql_thread_each_3="select tid,message from forum_post where  tid =".$val['tid']." and invisible = 0 and first=1 limit 0,1";
                          $result_thread_each_3=DB::fetch_first($strsql_thread_each_3);       
                          if( $result_thread_each_3)                                  
                               {
                         $strsql_thread_each_4="select avatarstatus from common_member where uid=".$val['authorid']." limit 0,1";
                         $result_thread_each_4=DB::fetch_first($strsql_thread_each_4);
                         if($val['sortid'] == 23)     
                         {
                           $strsql_thread_each_5="select archy_zj_9_23 as jg,archy_dz_9_23 as dz,archy_lxr_9_23 as lxr from forum_optionvalue23 where tid=".$val['tid']." limit 0,1";
                           $result_thread_each_5=DB::fetch_first($strsql_thread_each_5);
                         }
                         if($val['sortid'] == 24)     
                         {
                           $strsql_thread_each_5="select tzsc_zrjg_24 as jg,tzsc_dzxq_24 as dz,tzsc_lxr_24 as lxr from forum_optionvalue24 where tid=".$val['tid']." limit 0,1";
                           $result_thread_each_5=DB::fetch_first($strsql_thread_each_5);
                         }
                       
                         $strsql_insert_new = DB::insert('forum_thread_index_20150602',array('tid'=>$val['tid'],'fid'=>$val['fid'],'sortid'=>$val['sortid'],'author'=>$val['author'],'authorid'=>$val['authorid'],'subject'=>$val['subject'],'dateline'=>$val['dateline'],'special'=>$val['special'],'heats'=>$val['heats'],'stamp'=>$val['stamp'],'avatarstatus'=>$result_thread_each_4['avatarstatus'],'message'=>$result_thread_each_3['message'],'jg'=>$result_thread_each_5['jg'],'dz'=>$result_thread_each_5['dz'],'lxr'=>$result_thread_each_5['lxr']));                       
                         unset($result_thread_each_3);
                         unset($result_thread_each_4);
                         unset($result_thread_each_5);                                           
                                          
                                         }
                                          
                                  }
                                  else
                                  {

                unset($result_thread_each_1);
                                unset($result_thread_each_2);
                              exit();                                  
                                   }

                }
                      }       
                unset($result_thread_each_1);
                                unset($result_thread_each_2);                             
             }
         }
  unset($result_forum_fp);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-7 07:27 , Processed in 0.133570 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表