@task
def render_stale_documents(log=None):
 stale_docs = Document.objects.get_by_stale_rendering().distinct()
 stale_docs_count = stale_docs.count()
 if (stale_docs_count == 0):
  return
 if (log is None):
  log = render_stale_documents.get_logger()
 log.info(('Found %s stale documents' % stale_docs_count))
 stale_pks = stale_docs.values_list('pk', flat=True)
 pre_task = acquire_render_lock.si()
 render_tasks = [render_document_chunk.si(pks) for pks in chunked(stale_pks, 5)]
 post_task = release_render_lock.si()
 chord_flow(pre_task, render_tasks, post_task).apply_async()

@ task def render_stale_documents ( log = None ) : stale_docs = Document . objects . get_by_stale_rendering ( ) . distinct ( ) stale_docs_count = stale_docs . count ( ) if ( stale_docs_count == 0 ) : return if ( log is None ) : log = render_stale_documents . get_logger ( ) log . info ( ( 'Found %s stale documents' % stale_docs_count ) ) stale_pks = stale_docs . values_list ( 'pk' , flat = True ) pre_task = acquire_render_lock . si ( ) render_tasks = [ render_document_chunk . si ( pks ) for pks in chunked ( stale_pks , 5 ) ] post_task = release_render_lock . si ( ) chord_flow ( pre_task , render_tasks , post_task ) . apply_async ( )
simple task wrapper for rendering stale documents .