Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3609400
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:37:22+00:00 2026-05-18T21:37:22+00:00

I’m working on a Django blog and I need to be able to schedule

  • 0

I’m working on a Django blog and I need to be able to schedule posts to publish at a later date. Celery works great for initially scheduling posts, but I run into problems when a user tries to update the post to either have it either reschedule or canceled indefinitely.

Here is what I am trying to do:

def save(self, **kwargs):
    ''' 
    Saves an event. If the event is currently scheduled to publish, 
    sets a celery task to publish the event at the selected time.  
    If there is an existing scheduled task,cancel it and reschedule it 
    if necessary.
    ''' 
    import celery
    this_task_id = 'publish-post-%s' % self.id 
    celery.task.control.revoke(task_id=this_task_id)

    if self.status == self.STATUS_SCHEDULED:
        from blog import tasks
        tasks.publish_post.apply_async(args=[self.id], eta=self.date_published,
                task_id=this_task_id) 
    else:
        self.date_published = datetime.now()

    super(Post, self).save(**kwargs)

The problem is, once a Celery task ID has been listed as revoked, it stays revoked even after I try and reschedule it. This seems like a common enough task that there should be an easy solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:37:23+00:00Added an answer on May 18, 2026 at 9:37 pm

    I don’t know what your tasks.py file looks like, but I assume it’s something like the following:

    from celery.decorators import task
    
    @task
    def publish_post(post_id):
        ''' Sets the status of a post to Published '''
        from blog.models import Post
    
        Post.objects.filter(pk=post_id).update(status=Post.STATUS_PUBLISHED)
    

    You should edit the filter within the task to make sure that the current status is STATUS_SCHEDULED and that the time in date_published has passed. e.g.:

    from celery.decorators import task
    
    @task
    def publish_post(post_id):
        ''' Sets the status of a post to Published '''
        from blog.models import Post
        from datetime import datetime
    
        Post.objects.filter(
            pk=post_id,
            date_published__lte=datetime.now(),
            status=Post.STATUS_SCHEDULED
        ).update(status=Post.STATUS_PUBLISHED)
    

    This way, users can change the status back and forth, change the time, and the task will only ever change the status to publish if the task is running after the date_published column. No need to track ids or revoke tasks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y’all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.