How to use the synapse.common.now function in synapse

To help you get started, we’ve selected a few synapse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vertexproject / synapse / synapse / axon.py View on Github external
def _addloc(self, bsid, hashval, commit=False):
        '''
        Record blobstor's bsid has a particular hashval.  Should be run in my executor.
        '''
        xact = self.xact.guarantee()

        tick = s_common.now()

        written = xact.put(hashval, bsid, db=self.bloblocs, dupdata=False)

        if written:
            self._metrics.inc(xact, 'files', 1)

            # metrics contains everything we need to clone
            self._metrics.record(xact, {'time': tick, 'bsid': bsid, 'sha256': hashval})

            if commit:
                self.xact.commit()
github vertexproject / synapse / synapse / lib / types.py View on Github external
# self contained relative time string

        # we need to be pretty sure this is meant for us, otherwise it might
        # just be a slightly messy time parse
        unitcheck = [u for u in s_time.timeunits.keys() if u in valu]
        if unitcheck and '-' in valu or '+' in valu:
            splitter = '+'
            if '-' in valu:
                splitter = '-'

            bgn, end = valu.split(splitter, 1)
            delt = s_time.delta(splitter + end)
            if bgn:
                bgn = self._normPyStr(bgn)[0]
            else:
                bgn = s_common.now()

            return self._normPyInt(delt + bgn)

        valu = s_time.parse(valu)
        return self._normPyInt(valu)
github vertexproject / synapse / synapse / lib / net.py View on Github external
def rx(self, link, mesg):
        '''
        Recv a message on this link and dispatch the message.

        Args:
            link (Link): The link.
            mesg ((str,dict)): A message tufo.
        '''
        if self.isfini:
            return

        self.rxtime = s_common.now()

        if self.rxfunc is not None:
            try:
                return self.rxfunc(self, mesg)
            except Exception as e:
                logger.exception('%s.rxfunc() failed on: %r' % (self.__class__.__name__, mesg))
                self.fini()
                return

        try:
            func = self._mesg_funcs.get(mesg[0])
        except Exception as e:
            logger.exception('link %s: rx mesg exception: %s' % (self.__class__.__name__, e))
            self.fini()
            return
github vertexproject / synapse / synapse / eventbus.py View on Github external
def log(self, level, mesg, **info):
        '''
        Implements the log event convention for an EventBus.

        Args:
            level (int):  A python logger level for the event
            mesg (str):   A log message
            **info:       Additional log metadata

        '''
        info['time'] = s_common.now()
        info['host'] = s_thishost.get('hostname')

        info['level'] = level
        info['class'] = self.__class__.__name__

        self.fire('log', mesg=mesg, **info)
github vertexproject / synapse / synapse / lib / slabseqn.py View on Github external
def save(self, items):
        '''
        Save a series of items to a sequence.

        Args:
            items (tuple): The series of items to save into the sequence.

        Returns:
            The index of the first item
        '''
        rows = []
        indx = self.indx

        size = 0
        tick = s_common.now()

        for item in items:

            byts = s_msgpack.en(item)

            size += len(byts)

            lkey = s_common.int64en(indx)
            indx += 1

            rows.append((lkey, byts))

        self.slab.putmulti(rows, append=True, db=self.db)
        took = s_common.now() - tick

        origindx = self.indx
github vertexproject / synapse / synapse / lib / crypto / vault.py View on Github external
def genCertTokn(rpub, **info):
        '''
        Generate a public key certificate token.

        Args:
            rpub (s_ecc.PubKey):
            **info: Additional key/value data to be added to the certificate token.

        Returns:
            bytes: A msgpack encoded dictionary.
        '''
        tick = s_common.now()
        info['ecdsa:pubkey'] = rpub.dump()
        info['created'] = s_common.now()
        info.setdefault('expires', tick + (3 * s_const.year))
        return s_msgpack.en(info)
github vertexproject / synapse / synapse / cores / common.py View on Github external
return tufo

            tick = s_common.now()
            iden = s_common.guid()

            props.update(subs)

            # create a "full" props dict which includes defaults
            fulls = self._normTufoProps(prop, props)
            self._addDefProps(prop, fulls)

            fulls[prop] = valu

            # Set universal node values
            fulls['tufo:form'] = prop
            fulls['node:created'] = s_common.now()
            fulls['node:ndef'] = s_common.guid((prop, valu))
            # fulls['node:ndef'] = self.reqPropNorm('node:ndef', (prop, valu))[0]

            # Examine the fulls dictionary and identify any props which are
            # themselves forms, and extract the form/valu/subs from the fulls
            # dictionary so we can later make those nodes
            toadds = None
            if self.autoadd:
                toadds = self._formToAdd(prop, fulls)

            # Remove any non-model props present in the props and fulls
            # dictionary which may have been added during _normTufoProps
            self._pruneFulls(prop, fulls, props, isadd=True)

            # update our runtime form counters
            self.formed[prop] += 1
github vertexproject / synapse / synapse / lib / crypto / vault.py View on Github external
def genCertTokn(rpub, **info):
        '''
        Generate a public key certificate token.

        Args:
            rpub (s_ecc.PubKey):
            **info: Additional key/value data to be added to the certificate token.

        Returns:
            bytes: A msgpack encoded dictionary.
        '''
        tick = s_common.now()
        info['ecdsa:pubkey'] = rpub.dump()
        info['created'] = s_common.now()
        info.setdefault('expires', tick + (3 * s_const.year))
        return s_msgpack.en(info)
github vertexproject / synapse / synapse / cores / sqlite.py View on Github external
def _setRowsByIdProp(self, iden, prop, valu):
        if isinstance(valu, int):
            count = self.update(self._q_uprows_by_iden_prop_int, iden=iden, prop=prop, valu=valu)
        else:
            count = self.update(self._q_uprows_by_iden_prop_str, iden=iden, prop=prop, valu=valu)

        if count == 0:
            rows = [(iden, prop, valu, s_common.now()), ]
            self._addRows(rows)