示例#1
0
    def update(self, instance, validated_data):
        current_comments = (instance.comments).all()
        current_comments = current_comments.values()
        instance.subject = validated_data.get('subject', instance.subject)
        instance.calendar = validated_data.get('calendar', instance.calendar)
        instance.text = validated_data.get('text', instance.text)
        instance.image = validated_data.get('image', instance.image)
        if instance.status == ('Scheduled' or 'Draft'):
            if 'publishDateTime' in validated_data:
                instance.publishDateTime = validated_data.get('publishDateTime', instance.publishDateTime)
                instance.status = 'Scheduled'
                publish_task = instance.publishTask
                schedule = publish_task.clocked
                if schedule.enabled == True:
                    schedule.clocked_time = instance.publishDateTime
                    schedule.save()
                else:
                    new_schedule = ClockedSchedule(clocked_time=instance.publishDateTime)
                    new_schedule.save()
                    publish_task.clocked = new_schedule
                
                publish_task.enabled = True
                publish_task.one_off = True
                publish_task.save()

        instance.save()
        return instance
示例#2
0
 def create_publish_task(self):
     clocked = ClockedSchedule(clocked_time=self.publish_date)
     clocked.save()
     publish_task = PeriodicTask(
         clocked=clocked,
         name=f'Publish confession with id:{self.pk}',
         task='publish_confession_task',
         kwargs={"instance_id": self.pk},
         one_off=True)
     publish_task.save()
示例#3
0
文件: tasks.py 项目: parisays/markit
def create_tweet_task(post_id):
    """
    Create a django celery beat PeriodicTask with ClockedSchedule for each post.
    """
    post = Post.objects.get(pk=post_id)
    clocked_schedule = ClockedSchedule(clocked_time=post.publishDateTime)
    clocked_schedule.save()

    task_data = dict(name="PublishTweet{}".format(str(post_id)),
                     task="socials.tasks.publish_tweet_job",
                     clocked=clocked_schedule,
                     kwargs=json.dumps({"post_id": str(post_id)}))
    periodic_task = PeriodicTask(**task_data)
    periodic_task.enabled = True
    periodic_task.one_off = True
    periodic_task.save()
    post.publishTask = periodic_task
    post.save()