def handle_feed_sync_trigger(*args, **kwargs): """ Checks to see if there is a task for a feed sync in the queue and if not, adds one. Interval for firing this should be longer than the expected feed sync duration. :param args: :param kwargs: :return: """ system_user = _system_creds() logger.info('init args: {}'.format(kwargs)) cycle_time = kwargs['mythread']['cycle_timer'] while True: config = localconfig.get_config() feed_sync_enabled = config.get('feeds', {}).get('sync_enabled', True) if feed_sync_enabled: try: all_ready = anchore_engine.clients.common.check_services_ready( ['simplequeue']) if not all_ready: logger.info( "simplequeue service not yet ready, will retry") else: logger.info('Feed Sync Trigger activated') if not simplequeue.is_inqueue(userId=system_user, name=feed_sync_queuename, inobj=feed_sync_msg): try: simplequeue.enqueue(userId=system_user, name=feed_sync_queuename, inobj=feed_sync_msg) except: logger.exception( 'Could not enqueue message for a feed sync') logger.info( 'Feed Sync Trigger done, waiting for next cycle.') except Exception as e: logger.exception( 'Error caught in feed sync trigger handler. Will continue. Exception: {}' .format(e)) else: logger.debug( "sync_enabled is set to false in config - skipping feed sync trigger" ) time.sleep(cycle_time) return True
def queue_notification(userId, subscription_key, subscription_type, payload): localconfig = anchore_engine.configuration.localconfig.get_config() system_user_auth = localconfig['system_user_auth'] rc = False try: nobj = { 'userId': userId, 'subscription_key': subscription_key, 'notificationId': str(uuid.uuid4()), } if payload: nobj.update(payload) if not simplequeue.is_inqueue(system_user_auth, subscription_type, nobj): rc = simplequeue.enqueue(system_user_auth, subscription_type, nobj) except Exception as err: logger.warn("failed to create/enqueue notification") raise err return(rc)