tunga_manage_task_status.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:tunga-api 作者: tunga-io 项目源码 文件源码
def handle(self, *args, **options):
        """
        Update periodic update events and send notifications for upcoming update events.
        """
        # command to run: python manage.py tunga_manage_task_status

        # Choose tasks that aren't closed or under review already
        tasks_filter = Task.objects.filter(
            scope=TASK_SCOPE_TASK, closed=False, review=False
        ).annotate(
            activated_at=Case(
                When(
                    approved_at__isnull=True,
                    then='created_at'
                ),
                default='approved_at',
                output_field=DateTimeField()
            )
        )

        utc_now = datetime.datetime.utcnow()

        # Remind admins and devs about approved tasks with no applications 2 days after creation or approval
        min_date_no_applications = utc_now - relativedelta(days=2)
        min_date_no_developer_selected = utc_now - relativedelta(days=10)
        tasks_no_applications = tasks_filter.filter(
            approved=True, participants__isnull=False, activated_at__range=[
                min_date_no_developer_selected, min_date_no_applications
            ]
        )
        for task in tasks_no_applications:
            # Remind admins
            remind_no_task_applications.delay(task.id, admin=True)

            # Remind devs
            remind_no_task_applications.delay(task.id, admin=False)

        # Remind admins to take action on tasks with no accepted applications 10 days after creation or approval
        tasks_no_developers_selected = tasks_filter.filter(
            participants__isnull=True, created_at__lte=min_date_no_developer_selected
        )
        for task in tasks_no_developers_selected:
            # Put task in review
            task.review = True
            task.save()

            # Notify admins to take action
            notify_review_task_admin.delay(task.id)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号