def post_event(self, event, new_post_state):
        # update the event with new state
        updates = {'state': get_item_post_state(event, new_post_state), 'pubstatus': new_post_state}
        event['pubstatus'] = new_post_state
        updated_event = get_resource_service('events').update(event['_id'], updates, event)
        event.update(updated_event)

        # enqueue the event
        # these fields are set for enqueue process to work. otherwise not needed
        version, event = get_version_item_for_post(event)
        # save the version into the history
        updates['version'] = version

        get_resource_service('events_history')._save_history(event, updates, 'post')

        version_id = get_resource_service('published_planning').post([{'item_id': event['_id'],
                                                                       'version': version, 'type': 'event',
                                                                       'published_item': event}])
        if version_id:
            # Asynchronously enqueue the item for publishing.
            enqueue_planning_item.apply_async(kwargs={'id': version_id[0]})
        else:
            logger.error('Failed to save planning version for event item id {}'.format(event['_id']))

        return updated_event
    def enqueue_published_item(self, updates, original):
        if updates.get('posted', False):
            plan = deepcopy(original)
            plan.update(updates)
            version, plan = get_version_item_for_post(plan)

            # Create an entry in the planning versions collection for this published version
            version_id = get_resource_service('published_planning').post([{
                'item_id':
                plan['_id'],
                'version':
                version,
                'type':
                'planning_featured',
                'published_item':
                plan
            }])
            if version_id:
                # Asynchronously enqueue the item for publishing.
                enqueue_planning_item.apply_async(kwargs={'id': version_id[0]},
                                                  serializer="eve/json")
            else:
                logger.error(
                    'Failed to save planning_featured version for featured item id {}'
                    .format(plan['_id']))
 def publish_event(self, event, version):
     """Enqueue the items for publish"""
     version_id = get_resource_service('published_planning').post([{'item_id': event['_id'],
                                                                    'version': version,
                                                                    'type': 'event',
                                                                    'published_item': event}])
     if version_id:
         # Asynchronously enqueue the item for publishing.
         enqueue_planning_item.apply_async(kwargs={'id': version_id[0]}, serializer="eve/json")
     else:
         logger.error('Failed to save planning version for event item id {}'.format(event['_id']))
Example #4
0
    def post_planning(self, plan, new_post_state):
        """Post a Planning item

        """
        # update the planning with new state
        new_item_state = get_item_post_state(plan, new_post_state)

        updates = deepcopy(plan)
        updates['state'] = new_item_state
        updates['pubstatus'] = new_post_state
        if plan['state'] != new_item_state and new_item_state in [
                WORKFLOW_STATE.SCHEDULED, WORKFLOW_STATE.KILLED
        ]:
            updates['state_reason'] = None
            for coverage in updates.get('coverages', []):
                if coverage.get('workflow_status') != WORKFLOW_STATE.CANCELLED and \
                        coverage.get('planning', {}).pop('workflow_status_reason', None):
                    coverage['planning']['workflow_status_reason'] = None

        get_resource_service('planning').update(plan['_id'], updates, plan)

        # Set a version number
        plan['pubstatus'] = new_post_state
        version, plan = get_version_item_for_post(plan)
        plan[ITEM_STATE] = updates.get(ITEM_STATE)

        # Save the version into the history
        updates['version'] = version
        get_resource_service('planning_history')._save_history(
            plan, updates, 'post')

        # Create an entry in the planning versions collection for this published version
        version_id = get_resource_service('published_planning').post([{
            'item_id':
            plan['_id'],
            'version':
            version,
            'type':
            'planning',
            'published_item':
            plan
        }])
        if version_id:
            # Asynchronously enqueue the item for publishing.
            enqueue_planning_item.apply_async(kwargs={'id': version_id[0]})
        else:
            logger.error(
                'Failed to save planning version for planning item id {}'.
                format(plan['_id']))
Example #5
0
def enqueue_planning_item(id):
    """
    Get the version of the item to be published from the planning versions collection and enqueue it.

    :param id:
    :return:
    """
    planning_version = get_resource_service('published_planning').find_one(req=None, _id=id)
    if planning_version:
        try:
            get_enqueue_service('publish').enqueue_item(planning_version.get('published_item'), 'event')
        except Exception:
            logger.exception('Failed to queue {} item {}'.format(planning_version.get('type'), id))
    else:
        logger.error('Failed to retrieve planning item from planning versions with id: {}'.format(id))
 def publish_planning(self, plan, version):
     """Enqueue the planning item"""
     # Create an entry in the planning versions collection for this published version
     version_id = get_resource_service('published_planning').post([{
         'item_id':
         plan['_id'],
         'version':
         version,
         'type':
         'planning',
         'published_item':
         plan
     }])
     if version_id:
         # Asynchronously enqueue the item for publishing.
         enqueue_planning_item.apply_async(kwargs={'id': version_id[0]})
     else:
         logger.error(
             'Failed to save planning version for planning item id {}'.
             format(plan['_id']))
    def post_planning(self, plan, new_post_state):
        """Post a Planning item

        """
        # update the planning with new state
        updates = {
            'state': get_item_post_state(plan, new_post_state),
            'pubstatus': new_post_state
        }
        plan['pubstatus'] = new_post_state
        get_resource_service('planning').update(plan['_id'], updates, plan)

        # Set a version number
        version, plan = get_version_item_for_post(plan)
        plan[ITEM_STATE] = updates.get(ITEM_STATE)

        # Save the version into the history
        updates['version'] = version
        get_resource_service('planning_history')._save_history(
            plan, updates, 'post')

        # Create an entry in the planning versions collection for this published version
        version_id = get_resource_service('published_planning').post([{
            'item_id':
            plan['_id'],
            'version':
            version,
            'type':
            'planning',
            'published_item':
            plan
        }])
        if version_id:
            # Asynchronously enqueue the item for publishing.
            enqueue_planning_item.apply_async(kwargs={'id': version_id[0]})
        else:
            logger.error(
                'Failed to save planning version for planning item id {}'.
                format(plan['_id']))