Example #1
0
    def possibly_sharded(self):
        if self.completed_at: return None
        if self.accountsyncshard_set.filter(completed_at__isnull=True).count(): return None

        now = time()
        locked = (self.__class__.objects.filter(id=self.id, sharded_at__isnull=True).update(sharded_at=now) == 1)
        if not locked: return None
        self.sharded_at = now

        from webinars_web.webinars import models as wm
        with wm.EventSync.delayed as d:
            now = time()
            for event in self.account.event_set.filter(deleted_at__isnull=True, current_sync__isnull=True, mothballed=False).select_related('account'):
                d.insert(dict(event_id=event.id, parent_id=self.id, visible=self.visible, debug=self.debug, created_at=now.us))
        from django.db import transaction
        transaction.commit_unless_managed()
        event_syncs = wm.EventSync.objects.filter(parent=self, event__account=self.account)
        if not self.debug:
            tasks = []
            for es in event_syncs:
                url = '%s%s'%(settings.APP_URL,es.kickoff_path)
                uid = 'event_sync|kickoff|%s'%es.id
                qid = es.event.account_id % settings.NUM_QUEUES
                logging.debug('TQDEBUG: qid id %s' % qid)
                tasks.append(Task(queue=settings.TASK_QUEUES[qid], url=url, method='POST', uid=uid))
            Task._enqueue(tasks)
            
        self.possibly_done()
Example #2
0
 def create_shards(self, shard_kls, hashcodes, shard_limit):
     now = time()
     with shard_kls.delayed as d:
         for sd in self._assemble_shard_dicts(hashcodes, shard_limit, 1, 0):
             d.insert(merge(sd,dict(created_at=now.us)))
     from django.db import transaction
     transaction.commit_unless_managed()
     shards = shard_kls.objects.filter(parent_sync=self)
     if not self.debug: Task._enqueue([s.trigger_task for s in shards])
     return shards