Store state of events in memory
    :param event: Event object
    :param state: EventState object
    :param service_name: Name of service name
164542
async def track_event(event, state, service_name):
    
    redis = await aioredis.create_redis(
        (EVENT_TRACKING_HOST, 6379), loop=loop)

    now = datetime.utcnow()
    event_id = event.event_id

    tracking_data = json.dumps({
        "event_id": event_id,
        "timestamp": str(now),
        "state": state
    })
    await redis.rpush(service_name, tracking_data)
    redis.close()
    await redis.wait_closed()
269709
def put(self, event, *args, **kwargs):
        
        self._queue.put((event, args, kwargs))
374798
function(event) {
            var state = self.state();

            for ( var i in self._callbacks ) {
                self._callbacks[i].call(self._doc, event, state);
            }
        }
336817
function Store(name, handler, id) {
    this.setId(id);
    this.__name = name;
    this.__handler = handler;

    /**
     * The session attributes.
     *
     * @var {Object}
     * @protected
     */
    this.__attributes = {};

    /**
     * Session store started status.
     *
     * @var {Boolean}
     */
    this.__started = false;
}
1096392
def state(self):
        """"""
        if self._proto.HasField('state'):
            return yamcsManagement_pb2.ServiceState.Name(self._proto.state)
        return None
1080001
def service_changed(self, event):
        # type: (ServiceEvent) -> None
        
        # Call sub-methods
        kind = event.get_kind()
        svc_ref = event.get_service_reference()

        if kind == ServiceEvent.REGISTERED:
            # Service coming
            with self.__instances_lock:
                self.__add_handler_factory(svc_ref)

        elif kind == ServiceEvent.UNREGISTERING:
            # Service gone
            with self.__instances_lock:
                self.__remove_handler_factory(svc_ref)
278341
def bind(self, event_name, callback, *args, **kwargs):
        
        self.event_callbacks[event_name].append((callback, args, kwargs))
364590
def process(self, buff):
        '''
            
        '''
        (self._stack, self._memory, scstateidx, self._state, 
            tmpevents, self._waitingforprop, self._parentismap) = process( buff, self.create_parser_info(), self._deserializers);
        self._scstate = self.scstatelist[scstateidx-1]
        
        self._events = tmpevents
894710
def _report_replica_set_state(self, state, clean_server_name, replset_name):
        
        last_state = self._last_state_by_server.get(clean_server_name, -1)
        self._last_state_by_server[clean_server_name] = state
        if last_state != state and last_state != -1:
            return self.create_event(last_state, state, clean_server_name, replset_name)
1020171
function (event) {
      var id = event.target.parentNode.getAttribute('data-id');
      // By getting collection through this.state you get an hash of the collection
      this.setState(_.findWhere(this.state.collection, {id: id}));
    }
171422
def event(from_states=None, to_state=None):
    
    from_states_tuple = (from_states, ) if isinstance(from_states, State) else tuple(from_states or [])
    if not len(from_states_tuple) >= 1:
        raise ValueError()
    if not all(isinstance(state, State) for state in from_states_tuple):
        raise TypeError()
    if not isinstance(to_state, State):
        raise TypeError()

    def wrapper(wrapped):

        @functools.wraps(wrapped)
        def transition(instance, *a, **kw):
            if instance.current_state not in from_states_tuple:
                raise InvalidStateTransition()
            try:
                result = wrapped(instance, *a, **kw)
            except Exception as error:
                error_handlers = getattr(instance, '___pystatemachine_transition_failure_handlers', [])
                for error_handler in error_handlers:
                    error_handler(instance, wrapped, instance.current_state, to_state, error)
                if not error_handlers:
                    raise error
            else:
                StateInfo.set_current_state(instance, to_state)
                return result

        return transition

    return wrapper
1123916
def get_service_state(self, service_id: str) -> str:
        
        # Get service
        service = self._client.services.get(service_id)

        # Get the state of the service
        for service_task in service.tasks():
            service_state = service_task['DesiredState']
        return service_state
875466
def _change_state(name, action, expected, *args, **kwargs):
    '''
    
    '''
    pre = state(name)
    if action != 'restart' and pre == expected:
        return {'result': False,
                'state': {'old': expected, 'new': expected},
                'comment': ('Container \'{0}\' already {1}'
                            .format(name, expected))}
    _client_wrapper(action, name, *args, **kwargs)
    _clear_context()
    try:
        post = state(name)
    except CommandExecutionError:
        # Container doesn't exist anymore
        post = None
    ret = {'result': post == expected,
           'state': {'old': pre, 'new': post}}
    return ret
824323
function (event) {

	// check if connection object exists
	if (typeof event.conn === 'undefined') {
		LOG.error('no connection records, cannot respond to request', l_name);
		return false;
	}

	// if no mechanism to store (such as from a bot), just ignore
	// TODO: cleaner approach?
	if (event.conn.type !== 'socket' ||
    	event.conn.connector.queuedEvents === undefined) {
		return true;
	}

	var socket = event.conn.connector;

	// check if id exist
	if (socket.queuedEvents.hasOwnProperty(event.id) === false) {
		LOG.error('event not found. id = ' + event.id, l_name);
		LOG.stack();
		return false;
	}

	// remove current event from the socket's event queues
	delete socket.queuedEvents[event.id];

	return true;
}
76966
def _handle_sdp_target_state_updated(sdp_state: SDPState):
    
    LOG.info('Handling SDP target state updated event...')
    LOG.info('SDP target state: %s', sdp_state.target_state)

    # Map between the SDP target state and the service target state?
    if sdp_state.target_state == 'off':
        _update_services_target_state('off')

    # TODO: Work out if the state of SDP has reached the target state.

    # If yes, update the current state.
    sdp_state.update_current_state(sdp_state.target_state)
1339804
def bind(self, event_name, callback):
        

        if event_name not in self.event_callbacks.keys():
            self.event_callbacks[event_name] = []

        self.event_callbacks[event_name].append(callback)
1371819
def _process_event(event: Event, sdp_state: SDPState,
                   service_states: List[ServiceState]):
    """"""
    LOG.debug('Event detected! (id : "%s", type: "%s", data: "%s")',
              event.object_id, event.type, event.data)

    if event.object_id == 'SDP' and event.type == 'current_state_updated':
        LOG.info('SDP current state updated, no action required!')

    if event.object_id == 'SDP' and event.type == 'target_state_updated':
        LOG.info("SDP target state changed to '%s'",
                 sdp_state.target_state)

        # If the sdp is already in the target state do nothing
        if sdp_state.target_state == sdp_state.current_state:
            LOG.warning('SDP already in %s state',
                        sdp_state.current_state)
            return

        # Check that a transition to the target state is allowed in the
        # current state.
        if not sdp_state.is_target_state_allowed(sdp_state.target_state):
            LOG.error('Transition to %s is not allowed when in state %s',
                      sdp_state.target_state, sdp_state.current_state)
            sdp_state.target_state = sdp_state.current_state
            return

        _update_services_target_state(sdp_state.target_state)

        # If asking SDP to turn off, also turn off services.
        if sdp_state.target_state == 'off':
            LOG.info('Turning off services!')
            for service_state in service_states:
                service_state.update_target_state('off')
                service_state.update_current_state('off')

        LOG.info('Processing target state change request ...')
        time.sleep(0.1)
        LOG.info('Done processing target state change request!')

        # Assuming that the SDP has responding to the target
        # target state command by now, set the current state
        # to the target state.
        sdp_state.update_current_state(sdp_state.target_state)

        if sdp_state.current_state == 'alarm':
            LOG.debug('raising SDP state alarm')
            SIP_STATE_ALARM.set(1)
        else:
            SIP_STATE_ALARM.set(0)
        try:
            # FIXME(BMo) the pushgateway host should not be hardcoded!
            push_to_gateway('platform_pushgateway:9091', job='SIP',
                            registry=COLLECTOR_REGISTRY)
        except urllib.error.URLError:
            LOG.warning("Unable to connect to the Alarms service!")