当前位置: 首页>>代码示例>>Python>>正文


Python functions.Now方法代码示例

本文整理汇总了Python中django.db.models.functions.Now方法的典型用法代码示例。如果您正苦于以下问题:Python functions.Now方法的具体用法?Python functions.Now怎么用?Python functions.Now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.models.functions的用法示例。


在下文中一共展示了functions.Now方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: submit_run

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def submit_run(self, parameters=None, scheduled_time=None):
        """Create a run of this template"""
        from yawn.task.models import Task

        run_parameters = self.parameters.copy()
        run_parameters.update(parameters or {})

        run = Run.objects.create(
            workflow=self,
            submitted_time=functions.Now(),
            scheduled_time=scheduled_time,
            parameters=run_parameters,
        )
        for template in self.template_set.all():
            task = Task.objects.create(
                run=run,
                template=template,
            )
            if not template.upstream.exists():
                task.enqueue()

        # refresh to get the actual DB submitted time
        run.refresh_from_db()
        return run 
开发者ID:aclowes,项目名称:yawn,代码行数:26,代码来源:models.py

示例2: find_lost

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def find_lost(timeout):
        from yawn.task.models import Execution

        # Make a sparse index so looking up active workers is fast:
        # CREATE INDEX yawn_worker_active ON yawn_worker (status) WHERE status = 'active'
        lost = Worker.objects.filter(
            status=Worker.ACTIVE, last_heartbeat__lt=functions.Now() - timedelta(seconds=timeout)
        )
        for worker in lost:
            logger.warning('Marking %r as lost', worker)
            worker.status = Worker.LOST
            worker.save()

            executions = worker.execution_set.filter(status=Execution.RUNNING)

            for execution in executions:
                logger.warning('Marking %r as lost', execution)
                execution.mark_finished(lost=True) 
开发者ID:aclowes,项目名称:yawn,代码行数:20,代码来源:models.py

示例3: test_now

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def test_now(self):
        """
        Checks that queries with a Now() parameter are not cached.
        """
        obj = Test.objects.create(datetime='1992-07-02T12:00:00')
        qs = Test.objects.filter(
            datetime__lte=Now())
        with self.assertNumQueries(1):
            obj1 = qs.get()
        with self.assertNumQueries(1):
            obj2 = qs.get()
        self.assertEqual(obj1, obj2)
        self.assertEqual(obj1, obj) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:15,代码来源:read.py

示例4: mark_finished

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def mark_finished(self, exit_code=None, lost=False):
        """
        Update the execution status after it has finished:
         successfully, in error, or because it was lost.

        Also update the task and workflow; re-queue the task if
         it should be retried.
        """
        if lost:
            self.status = Execution.LOST
            self.task.enqueue()

        elif exit_code == 0:
            self.task.status = Task.SUCCEEDED
            self.status = Execution.SUCCEEDED

        else:
            # queue another run if there are remaining retries
            # (current execution is not in count b/c it hasn't been saved yet)
            failed_count = self.task.execution_set.filter(status=Task.FAILED).count()
            if failed_count < self.task.template.max_retries:
                self.task.enqueue()
            else:
                self.task.status = Task.FAILED

            self.status = Execution.FAILED

        if self.task.status != Task.RUNNING:
            self.task.save()
            with transaction.atomic():
                self.task.update_downstream()
            if self.task.run:
                self.task.run.update_status()

        self.stop_timestamp = functions.Now()
        self.exit_code = exit_code
        # need to be careful not to overwrite stdout/stderr
        self.save(update_fields=['status', 'stop_timestamp', 'exit_code']) 
开发者ID:aclowes,项目名称:yawn,代码行数:40,代码来源:models.py

示例5: update_worker

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def update_worker(self):
        """
        Look for executors where the connection has broken and tasks need to be re-submitted.
        """
        if not self.worker:
            self.worker = Worker.objects.create(
                name=self.name,
                start_timestamp=functions.Now(),
                last_heartbeat=functions.Now()
            )
        else:
            self.worker.refresh_from_db()

        if self.worker.status == Worker.LOST:
            # someone else marked us as lost, terminate all tasks and exit
            logger.warning('Marked as lost, committing harakiri')
            self.state = State.terminate
            self.executor.mark_terminated(self.executor.get_running_ids())
            return

        # update our timestamp so no one marks us as lost
        self.worker.last_heartbeat = functions.Now()
        self.worker.save()

        # look for lost workers and re-queue their tasks
        Worker.find_lost(self.timeout) 
开发者ID:aclowes,项目名称:yawn,代码行数:28,代码来源:main.py

示例6: test_basic

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def test_basic(self):
        a1 = Article.objects.create(
            title='How to Django',
            text=lorem_ipsum,
            written=timezone.now(),
        )
        a2 = Article.objects.create(
            title='How to Time Travel',
            text=lorem_ipsum,
            written=timezone.now(),
        )
        num_updated = Article.objects.filter(id=a1.id, published=None).update(published=Now())
        self.assertEqual(num_updated, 1)
        num_updated = Article.objects.filter(id=a1.id, published=None).update(published=Now())
        self.assertEqual(num_updated, 0)
        a1.refresh_from_db()
        self.assertIsInstance(a1.published, datetime)
        a2.published = Now() + timedelta(days=2)
        a2.save()
        a2.refresh_from_db()
        self.assertIsInstance(a2.published, datetime)
        self.assertQuerysetEqual(
            Article.objects.filter(published__lte=Now()),
            ['How to Django'],
            lambda a: a.title
        )
        self.assertQuerysetEqual(
            Article.objects.filter(published__gt=Now()),
            ['How to Time Travel'],
            lambda a: a.title
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:33,代码来源:test_now.py

示例7: reschedule_scheduled_jobs

# 需要导入模块: from django.db.models import functions [as 别名]
# 或者: from django.db.models.functions import Now [as 别名]
def reschedule_scheduled_jobs(self):
        ScheduledJob = self.get_model('ScheduledJob')
        jobs = ScheduledJob.objects.filter(
            enabled=True, scheduled_time__lte=Now())
        self.reschedule_jobs(jobs) 
开发者ID:isl-x,项目名称:django-rq-scheduler,代码行数:7,代码来源:apps.py


注:本文中的django.db.models.functions.Now方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。