Пример #1
0
def mnt_campaign(request, dajax):
    shop_id = int(request.user.shop_id)
    campaign_id = int(request.POST['campaign_id'])
    rpt_days = int(request.POST.get('rpt_days', 1))

    try:
        mnt_camp = MntCampaign.objects.get(shop_id=shop_id,
                                           campaign_id=int(campaign_id))

        if not mnt_camp.optimize_time:
            mnt_camp.optimize_time = '尚未优化'
        else:
            mnt_camp.optimize_time = time_humanize(mnt_camp.optimize_time)

        is_active = 1
        if mnt_camp.quick_optime and time_is_someday(mnt_camp.quick_optime):
            is_active = 0

        campaign = Campaign.objects.get(shop_id=shop_id,
                                        campaign_id=campaign_id)
        sum_rpt = campaign.get_summed_rpt(rpt_days=rpt_days)
        json_dict = {
            'total_cost': fen2yuan(sum_rpt.cost),
            'imp': sum_rpt.impressions,
            'click': sum_rpt.click,
            'ctr': '%.2f' % sum_rpt.ctr,
            'cpc': fen2yuan(sum_rpt.cpc),
            'total_pay': fen2yuan(sum_rpt.pay),
            'roi': '%.2f' % sum_rpt.roi,
            'conv': '%.2f' % sum_rpt.conv,
            'paycount': sum_rpt.paycount
        }
        max_price = 0
        if hasattr(mnt_camp, 'max_price'):
            max_price = format(mnt_camp.max_price / 100.0, '.2f')

        result = {
            'set': {
                'campaign_id': campaign_id,
                'title': campaign.title,
                'optimize_time': mnt_camp.optimize_time,
                'max_price': max_price,
                'budget': format(campaign.budget / 100.0, '.0f'),
                'is_active': is_active,
                'mnt_status': mnt_camp.mnt_status,
                'mnt_type': mnt_camp.mnt_type,
            },
            'rpt': json_dict,
        }
        dajax.script("PTQN.mnt.mnt_campaign_back(%s)" % json.dumps(result))
    except Exception, e:
        log.error('missing args or campaign not exist, shop_id = %s, e = %s' %
                  (shop_id, e))
        if 'query does not exist' in str(e):  # 删除缓存
            from apps.common.cachekey import CacheKey
            CacheAdpter.delete(CacheKey.WEB_MNT_MENU % shop_id, 'web')
        dajax.script('PTQN.alert("亲,请刷新页面重新操作!");')
Пример #2
0
def init_ad_cfg():
    if ad_coll.find().count() > 0:
        print '已有初始化记录'
        return

    data = [{
        'id':
        1,
        'type':
        'menu',
        'title':
        '免费专家指导',
        'weight':
        '1',
        'flag':
        1,
        'create_time':
        '11/13 17:57:14',
        'html':
        '''<div class="w900 auto"> <a target=_blank href="http://wpa.qq.com/msgrd?v=3&amp;uin=2093327936&amp;site=qq&amp;menu=yes"> <img src=/site_media/jl5/images/pxhb1.jpg /> </a> </div>'''
    }, {
        'id':
        2,
        'type':
        'menu',
        'title':
        '人工托管',
        'weight':
        '2',
        'flag':
        1,
        'create_time':
        '11/13 17:57:15',
        'html':
        '''<div class=rel style="width:900px;margin: 0 auto"> <a href="aliim:sendmsg?uid=cntaobao&amp;siteid=cntaobao&amp;touid=cntaobao人工托管服务"> <img src=/site_media/jl5/images/rgtg1113.gif /> </a> <div id=timer class="timer hide"> <div class=dd><span>8</span><span class=ml4>8</span></div> <div class=hh><span class=ml-10>8</span><span class=ml5>8</span></div> <div class=mm><span class=ml-10>8</span><span class=ml3>8</span></div> <div class=ss><span class=ml-10>8</span><span class=ml3>8</span></div> </div> </div>'''
    }, {
        'id':
        3,
        'type':
        'menu',
        'title':
        '创意优化服务',
        'weight':
        '3',
        'flag':
        1,
        'create_time':
        '11/13 17:57:16',
        'html':
        '''<div class="w900 auto" id=carousel_box> <div id=myCarousel class="carousel slide">  <div class=carousel-inner> <div class="item active"> <img src=/site_media/jl5/images/optimize_creative_2.gif usemap=#talk_map_1 /> <map name=talk_map_1 id=talk_map_1> <area coords=845,249,899,294 href="aliim:sendmsg?uid=cntaobao&amp;siteid=cntaobao&amp;touid=cntaobao派生科技:设计顾问" onclick=PT.sendDajax({&quot;function&quot;:&quot;web_record_click&quot;}) /> <area coords=0,0,900,800 href="http://wpa.qq.com/msgrd?v=3&amp;uin=1460309795&amp;site=qq&amp;menu=yes" target=_blank onclick=PT.sendDajax({&quot;function&quot;:&quot;web_record_click&quot;}) /> </map> </div>  </div>  </div> </div>'''
    }]

    ad_coll.insert(data)
    CacheAdpter.delete(CacheKey.WEB_AD_MENU, 'web')
    print 'finished'
Пример #3
0
 def __is_mutual(self=None, *args, **kwargs):
     key_name = CacheKey.SUBWAY_DOWNLOAD_MUTUAL_LOCK % (self.shop_id,
                                                        dl_type)
     cached_lock = CacheAdpter.get(key_name, 'web')
     if cached_lock:  # 没有缓存,直接下载
         return False
     else:
         CacheAdpter.set(key_name, True, 'web', 30 * 60)
         result = fn(self, *args, **kwargs)
         CacheAdpter.delete(key_name, 'web')
         return result
Пример #4
0
    def get_display_msg(msgs):
        from django.core.urlresolvers import reverse
        from apps.ncrm.models import PSUser
        delete_msg_list, user_msg_list, shop_id_list = [], [], []
        psuser_id_list = [msg.psuser_id for msg in msgs]
        psusers = PSUser.objects.filter(id__in=list(set(psuser_id_list)))
        user_dict = {user.id: user.ww for user in psusers}
        for msg in msgs:
            obj_title, jump_url, ww = '', '', ''
            if msg.object_type == 0:
                obj_title = msg.title and msg.title or '直通车账户'
                jump_url = ''
            elif msg.object_type == 1:
                obj = Campaign.objects.get(shop_id=msg.shop_id,
                                           campaign_id=msg.object_id)
                obj_title = obj.title
                jump_url = reverse('campaign',
                                   kwargs={'campaign_id': msg.object_id})
            elif msg.object_type == 2:
                try:
                    obj = Adgroup.objects.get(shop_id=msg.shop_id,
                                              adgroup_id=msg.object_id)
                    obj_title = obj.item and obj.item.title or ''
                    jump_url = reverse('adgroup_details',
                                       kwargs={'adgroup_id': msg.object_id})
                except DoesNotExist:
                    delete_msg_list.append(msg.id)
                    shop_id_list.append(msg.shop_id)
                    continue

            ww = user_dict.get(msg.psuser_id, '')
            ww = ww or '派生科技'  # 有些psuser_id 没有填写旺旺
            user_msg_list.append({
                'id': '%s' % msg.id,
                'is_prompt': msg.is_prompt,
                'obj_title': obj_title,
                'jump_url': jump_url,
                'content': msg.content,
                'object_type': msg.get_object_type_display(),
                'last_modified': msg.last_modified,
                'ww': ww
            })

        if delete_msg_list:
            PsMessage.objects.filter(id__in=delete_msg_list).delete()
            shop_id_list = list(set(shop_id_list))
            for shop_id in shop_id_list:
                CacheAdpter.delete(CacheKey.WEB_MSG_COUNT % shop_id, 'web')

        return user_msg_list
Пример #5
0
 def close_msg(shop_id, msg_id):
     try:
         msg = PsMessage.objects.get(id=msg_id)
         if msg.is_prompt:
             msg.is_prompt = False
             msg.save()
             klass, klass_id = KLASS_DICT[str(msg.object_type)]
             args = {'shop_id': shop_id, klass_id: msg.object_id}
             obj = globals()[klass].objects.get(**args)
             obj.set_msg_count(msg_type=msg.message_type, add_count=-1)
             CacheAdpter.delete(CacheKey.WEB_MSG_COUNT % shop_id, 'web')
         return True
     except Exception, e:
         log.error('close msg error, shop_id = %s, e = %s' % (shop_id, e))
         return False
Пример #6
0
 def reload_single_cat_synoword(cat_id):
     flag_dict = CacheAdpter.get(CacheKey.KWLIB_SYNOWORD % -1, 'web',
                                 {'init': ''})
     if not flag_dict.has_key('init'):
         objs = SynonymWord.objects.filter(cat_id=cat_id)
         word_dict = {}
         if objs:
             for obj in objs:
                 word_list = obj.word_list.split(',')
                 temp_dict = {
                     word.replace('\r', ''): word_list
                     for word in word_list
                 }
                 word_dict.update(temp_dict)
             CacheAdpter.set(CacheKey.KWLIB_SYNOWORD % cat_id, word_dict,
                             'web', 60 * 60 * 24 * 7)
         else:
             CacheAdpter.delete(CacheKey.KWLIB_SYNOWORD % cat_id, 'web')
         log.info('update synoword into memcache, cat_id=%s' % cat_id)
     else:
         SynonymWord.load_in_cache_if_not()
Пример #7
0
                    % (shop_id, e))
                msg_list.append('%s失败:%s' % (oper_name, humanize_exception(e)))
            else:
                result_list.append('area')
                if para.has_key('area_names'):
                    detail_list = ['修改计划投放地域为:%s' % para['area_names'][0:-1]]
                    record_list.append({
                        'shop_id': shop_id,
                        'campaign_id': campaign_id,
                        'detail_list': detail_list,
                        'op_type': 1,
                        'data_type': 106,
                        'opter': opter,
                        'opter_name': opter_name
                    })
                CacheAdpter.delete(CacheKey.WEB_CAMPAIGN_AREA % campaign_id,
                                   'web')
                campaign.save()

        if para.has_key('schedule'):
            oper_name = '修改计划分时折扣'
            try:
                tapi.simba_campaign_schedule_update(
                    campaign_id=campaign.campaign_id,
                    schedule=para['schedule'])
            except TopError, e:
                log.error(
                    'simba_campaign_schedule_update TopError, shop_id = %s, error = %s'
                    % (shop_id, e))
                msg_list.append('%s失败:%s' % (oper_name, e.humanized_reason))
            except Exception, e:
                log.error(
Пример #8
0
    def set_mnt_camp(campaign_id, flag, mnt_type, opter = 3, opter_name = '', **kwargs):
        """托管计划设置器,flag标识开启或者关闭"""
        from apps.subway.upload import update_campaign, set_cmp_mnt_status_log
        try:
            campaign = Campaign.objects.get(campaign_id = campaign_id)
        except DoesNotExist:
            log.info('can not find campaign, campaign_id = %s' % campaign_id)
            return None

        set_dict = {'mnt_status':flag}
        max_num_dict = {1: 500, 2: 10 , 3: 50, 4: 10}
        max_num = max_num_dict.get(mnt_type, 10)
        if flag:
            # TODO: wangqi 20151019 这里检查是否有权限创建
            if not MntMnger.check_create_mnt(campaign.shop_id):
                raise Exception("no_permission")

            set_dict.update({'online_status':'online',
                             'budget':kwargs['budget'],
                             'use_smooth':'true',
                             })

            if kwargs.get('area', 0) != 0:
                if campaign.area == 'all':
                    area_list = Const.CAMP_AREA
                else:
                    area_list = campaign.area.split(',')
                new_area_list = list(set(area_list) - {'599', '576', '578', '574'}) # 后面的数字,分别是港澳台国外,{1,2,3}是set初始化方法
                new_areas = ','.join(new_area_list)
                set_dict.update({'area': new_areas})
            if kwargs.get('platform', 0) != 0:
                set_dict.update({'search_channels':'1,2,4,8,16',
                                 'nonsearch_channels':'1,2,8,16',
                                 'outside_discount':60,
                                 'mobile_discount':110
                                 })
            if kwargs.get('schedule', 0) != 0:
                set_dict.update({'schedule':'00:00-01:00:45,01:00-08:00:35,08:00-09:00:70,09:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100;\
00:00-01:00:45,01:00-08:00:35,08:00-09:00:70,09:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100;\
00:00-01:00:45,01:00-08:00:35,08:00-09:00:70,09:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100;\
00:00-01:00:45,01:00-08:00:35,08:00-09:00:70,09:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100;\
00:00-01:00:45,01:00-08:00:35,08:00-09:00:70,09:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100;\
00:00-01:00:50,01:00-08:00:35,08:00-10:00:65,10:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100;\
00:00-01:00:50,01:00-08:00:35,08:00-10:00:65,10:00-14:00:75,14:00-17:00:100,17:00-19:00:80,19:00-20:30:100,20:30-23:00:105,23:00-24:00:100'})

#             mnt_desc = mnt_type == 1 and '长尾托管' or '重点托管'
#             set_dict.update({'title':'开车精灵-%s%s' % (mnt_desc, kwargs['mnt_index'])})

            if kwargs.has_key('max_price') and kwargs['max_price'] > 0:
                set_dict.update({'max_price':kwargs['max_price']})

            if kwargs.has_key('mobile_max_price') and kwargs['mobile_max_price'] > 0:
                set_dict.update({'mobile_max_price':kwargs['mobile_max_price']})
            result_list, msg_list = update_campaign(shop_id = campaign.shop_id, campaign_id = campaign.campaign_id, opter = opter, opter_name = opter_name, **set_dict)

            create_args = {'shop_id':campaign.shop_id, 'campaign_id': campaign.campaign_id, 'mnt_index': kwargs['mnt_index'], 'mnt_type': mnt_type,
                           'max_num': max_num, 'mnt_cfg_list': []}
            if mnt_type in [2, 4]:
                create_args.update({
                    'max_price': kwargs.get('max_price', 200),
                    'mobile_max_price': kwargs.get('mobile_max_price', 200),
                    'mnt_rt': kwargs.get('mnt_rt', 0),
                    'mnt_bid_factor': kwargs.get('mnt_bid_factor', 50),
                    'opt_wireless': kwargs.get('opt_wireless', 0),
                })
            elif mnt_type in [1, 3]:
                create_args.update({
                    'max_price': kwargs.get('max_price', 200),
                    'mobile_max_price': kwargs.get('mobile_max_price', 200),
                    'mnt_bid_factor': kwargs.get('mnt_bid_factor', 50),
                    'opt_wireless': kwargs.get('opt_wireless', 0)
                })
            MntCampaign.objects.create(**create_args)
        else:
            msg_list = []
#             campaign.rpt_days = 7
#             if campaign.rpt_sum.roi < 1.5 and '开车精灵' in campaign.title or '开車精灵' in campaign.title:
#                 set_dict['title'] = '推广计划%s' % time.strftime('%m%d%H%M')
            campaign.rpt_sum = campaign.get_summed_rpt(rpt_days = 15)
            if campaign.rpt_sum.roi < 1 and ('开车精灵-' in campaign.title or '开車精灵-' in campaign.title or '无线精灵-' in campaign.title or not flag):
                set_dict['title'] = campaign.title.replace('开车精灵-', '').replace('开車精灵-', '').replace('无线精灵-', '')
                result_list, msg_list = update_campaign(shop_id = campaign.shop_id, campaign_id = campaign.campaign_id, opter = opter, opter_name = opter_name, **set_dict)
            MntMnger.unmnt_campaign(shop_id = campaign.shop_id, campaign_id = campaign.campaign_id)

        CacheAdpter.delete(CacheKey.WEB_MNT_MENU % campaign.shop_id, 'web')
        warn_msg_dict = {}
        if msg_list:
            warn_dict = {'名称或状态': 'title_status', '日限额': 'budget', '投放地域': 'area', '分时折扣': 'schedule', '平台设置': 'platform'}
            for msg in msg_list:
                for warn_str, warn_key in warn_dict.items():
                    if warn_str in msg:
                        warn_msg_dict[warn_key] = msg
                        break

        return warn_msg_dict
Пример #9
0
 def refresh_all_configs(cls):
     CacheAdpter.delete(cls.CACHEKEY, 'web')
     return True
Пример #10
0
        if not is_backend and customer.consult_id:
            login_cache = CacheAdpter.get(
                CacheKey.LOGIN_USERS %
                (customer.consult_id, datetime.date.today()), 'crm', {})
            shop_cache = login_cache.setdefault(
                customer.shop_id,
                [now, customer.nick, customer.phone, customer.qq, 0, ''])
            shop_cache[0] = now
            shop_cache[5] = plateform_type
            CacheAdpter.set(
                CacheKey.LOGIN_USERS %
                (customer.consult_id, datetime.date.today()), login_cache,
                'crm', 24 * 60 * 60)

    # 登陆时删除左侧菜单缓存
    CacheAdpter.delete(CacheKey.WEB_MNT_MENU % user.shop_id, 'web')
    CacheAdpter.delete(CacheKey.WEB_ISNEED_PHONE % user.shop_id, 'web')

    # 将剩余天数,订购版本等标记记录到session中
    left_days = user.get_left_days()
    if left_days < 0:
        left_days = 0
    request.session['left_days'] = left_days
    request.session['deadline'] = datetime_2string(
        datetime.datetime.now() + datetime.timedelta(days=left_days),
        '%Y-%m-%d')
    request.session[
        'highest_version'] = ArticleUserSubscribe.get_highest_version(
            nick=user.nick)
    request.session['item_code'] = ArticleUserSubscribe.get_hightest_item_code(
        nick=user.nick)
Пример #11
0
 def del_cache(cls, shop_id):
     CacheAdpter.delete(cls.KEY % (shop_id), 'web')
Пример #12
0
def del_cache_progress(shop_id):
    '''删除缓存中的信息'''
    download_task_key = CacheKey.SUBWAY_DOWNLOAD_TASK % shop_id
    CacheAdpter.delete(download_task_key, 'web')
Пример #13
0
 def refresh_all_configs(cls):
     strat_cfgs = cls._get_collection().find({}, {'name': 1})
     for sc in strat_cfgs:
         CacheAdpter.delete(CacheKey.MNT_CMDCFG % sc['name'], 'web')
     return
Пример #14
0
                kw_lockers = KeywordLocker.objects.filter(
                    Q(is_stop__in = [0, None], start_time__lte = time_str, end_time__gte = time_str, next_run_time__lte = now)
                    & (Q(is_running__in = [0, None]) | Q(is_running = 1, last_run_time__lte = now - datetime.timedelta(hours = 1)))) \
                    .order_by('-is_running', 'next_run_time', 'adgroup_id').limit(100)
                kw_id_list = [kl.keyword_id for kl in kw_lockers]
                kw_locker_coll.update({'_id': {
                    '$in': kw_id_list
                }}, {'$set': {
                    'is_running': 1,
                    'last_run_time': now
                }},
                                      multi=True)
            except Exception, e:
                log.error("robrank_task get_valid_task error, e=%s" % e)
            finally:
                CacheAdpter.delete(CacheKey.ENGINE_ROBRANK_TASK_MUTUAL_LOCK,
                                   'web')  # 清除缓存,把门打开

            adg_dict = {}
            for kl in kw_lockers:
                adg_dict.setdefault(kl.adgroup_id, []).append(kl)
            for adgroup_id, kl_list in adg_dict.items(
            ):  # 最后一个宝贝可能没有包含这个宝贝下所有的关键词,所以过滤掉,等下次执行
                shop_id = kl_list[0].shop_id
                task = RobRankTask(shop_id=shop_id,
                                   adgroup_id=adgroup_id,
                                   kw_locker_list=kl_list,
                                   opt_type='auto')
                task.init_data()
                if task.is_runnable():
                    new_task_list.append(task)
                else:
Пример #15
0
                args = is_force and {
                    'is_force': True,
                    'rpt_days': kwargs['rpt_days']
                } or {}
                if not dler.sync_all_rpt(**args):
                    raise Exception('dl_rpt_failed', is_force)

                return True, ''
            except Exception, e:
                log.error('download data error,shop_id=%s, e=%s' %
                          (shop_id, e.args))
                return False, e[0]

            finally:
                CacheAdpter.delete(cache_key, 'web')
        else:
            return False, 'doing'

    shop_id = int(request.user.shop_id)
    is_force = False
    cache_key = CacheKey.WEB_SYNC_DATA_FLAG % shop_id
    is_recent_clicked = CacheAdpter.get(cache_key, 'web')
    if is_recent_clicked:
        is_force = True
        CacheAdpter.delete(cache_key, 'web')  # 强制下载时,将缓存删除,下次重新走自动同步路线
    else:
        CacheAdpter.set(cache_key, True, 'web', 60 * 5)  # 自动下载时,标记缓存

    result, reason = download_data(shop_id=shop_id,
                                   is_force=is_force,
Пример #16
0
                if valid_id_list:
                    shopmng_task_coll.update({'_id': {
                        '$in': valid_id_list
                    }}, {
                        '$set': {
                            'status': -1,
                            'last_start_time': datetime.datetime.now()
                        }
                    },
                                             multi=True)
                return valid_id_list
            except Exception, e:
                log.error("shopmng_task get_valid_task error, e=%s" % e)
                return valid_id_list
            finally:
                CacheAdpter.delete(CacheKey.ENGINE_SHOPMNG_TASK_MUTUAL_LOCK,
                                   'web')  # 清除缓存,把门打开

    @staticmethod
    def reset_task(shop_id=None):
        """重置任务状态"""
        update_info = {
            'last_start_time': None,
            'last_end_time': None,
            'run_times': 0,
            'status': 1
        }
        if shop_id:
            query_cond = {'_id': shop_id}
        else:
            query_cond = {'status': {'$ne': 0}}  # 非激活的任务不处理,必须要由用户登录才会重新激活
        shopmng_task_coll.update(query_cond, {'$set': update_info}, multi=True)
Пример #17
0
            warn_msg_dict = MntMnger.set_mnt_camp(campaign_id = campaign_id, flag = set_flag, mnt_type = mnt_type, opter = opter, opter_name = opter_name)
    except Exception, e:
        log.info('mnt_campaign_setter error: %s, mnt_type: %s, campaign_id: %s, shop_id: %s,' % (e, mnt_type, campaign_id, shop_id))
        if str(e) == "no_permission":
            return {'errMsg':'', 'result':0, 'error_msg':'no_permission'}
        try:
            result, error_msg = json.loads(e.message)
        except:
            if hasattr(e, 'reason'):
                error_msg = (eval(e.reason))['error_response'].get('sub_msg', '淘宝发生未知错误,请联系顾问')
            else:
                error_msg = e.message
                if 'need to wait' in error_msg:
                    error_msg = 'API接口超限'
    finally:
        CacheAdpter.delete(CacheKey.WEB_MNT_MENU % shop_id, 'web')
    result = 0 if error_msg else 1
    return {'errMsg':'', 'error_msg':error_msg, 'result':result, 'warn_msg_dict': json.dumps(warn_msg_dict)}

def get_base_rpt(request):
    ''' MNT主页上的基础报表 '''
    shop_id = int(request.user.shop_id)
    campaign_id = int(request.POST['campaign_id'])
    rpt_days = int(request.POST.get('rpt_days', 1))
    start_date = str(request.POST['start_date'])
    end_date = str(request.POST['end_date'])
    try:
        # camp_rpt_dict = Campaign.Report.get_summed_rpt({'shop_id': shop_id, 'campaign_id': campaign_id}, rpt_days = rpt_days)
        if start_date == end_date == datetime.date.today().strftime('%Y-%m-%d'):
            camp_rpt_dict = RealtimeReport.get_summed_rtrpt(rpt_type = 'campaign', args_list = [shop_id])
        else:
Пример #18
0
 def save(self, force_insert=False, force_update=False, *args, **kwargs):
     the_key = '%s+%s+%s' % (self.key, self.sub_key, self.shop_id)
     CacheAdpter.delete(the_key, 'default')
     return super(Config, self).save(force_insert, force_update, *args,
                                     **kwargs)
Пример #19
0
                    mnt_task_coll.update({'_id': {
                        '$in': valid_id_list
                    }}, {
                        '$set': {
                            'status': 'allocated',
                            'start_time': datetime.datetime.now()
                        }
                    },
                                         multi=True)
                return valid_id_list
            except Exception, e:
                log.error("task_type=%s, get_task error, e=%s" %
                          (task_type, e))
                return valid_id_list
            finally:
                CacheAdpter.delete(CacheKey.MNT_MUTUAL_LOCK % task_type,
                                   'web')  # 清除缓存,把门打开

    @classmethod
    def trigger_task_status(cls, shop_id, campaign_id, trigger_flag=True):
        if trigger_flag:  # 将暂停的任务改成准备中
            mnt_task_coll.update(
                {
                    'shop_id': shop_id,
                    'campaign_id': campaign_id,
                    'status': 'paused'
                }, {'$set': {
                    'status': 'ready'
                }},
                multi=True)
        else:  # 将任务状态改成暂停
            mnt_task_coll.update(
Пример #20
0
 def del_status(self):
     return CacheAdpter.delete(self.STATUS_KEY % self.shop_id, 'web')