How to use the autobahn.util.utcnow function in autobahn

To help you get started, we’ve selected a few autobahn 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 crossbario / crossbar / v1 / crossbar / database.py View on Github external
"service-enable-extdirectremoter": False,
          }

      if not scratchMode:
         CONFIG.update({"database-created": created,
                        "admin-password": "secret"})

      ## default global configuration
      ##
      for k in CONFIG:
         cur.execute("INSERT INTO config (key, value) VALUES (?, ?)", [k, json_dumps(CONFIG[k])])
      db.commit()

      ## default client permission: allow everything for anynonymous
      cur.execute("INSERT INTO clientperm (id, created, topic_uri, match_by_prefix, allow_publish, allow_subscribe) VALUES (?, ?, ?, ?, ?, ?)",
                  [newid(), utcnow(), "http://", 1, 1, 1])
      db.commit()

      if self.checkForOracleXE():
         log.msg("Inserting initial configuration for 'Tavendo WebMQ with Oracle XE'")
         oraConnectId = newid()
         now = utcnow()
         cur.execute("INSERT INTO oraconnect (id, created, label, host, port, sid, user, password, demo_user, demo_password, connection_timeout) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                     [oraConnectId, now, "WebMQ", "127.0.0.1", 1521, "XE", "WEBMQ", "webmq", "WEBMQDEMO", "webmqdemo", 5])
         cur.execute("INSERT INTO orapushrule (id, created, oraconnect_id, topic_uri, match_by_prefix) VALUES (?, ?, ?, ?, ?)",
                     [newid(), now, oraConnectId, "http://", 1])
         cur.execute("INSERT INTO oraremote (id, created, oraconnect_id, schema_list, rpc_base_uri, connection_pool_min_size, connection_pool_max_size, connection_timeout, request_timeout) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
                     [newid(), now, oraConnectId, "", "http://", 3, 10, 5, 2])
         db.commit()

      log.msg("database initialized.")
github crossbario / crossbar / v1 / crossbar / bridge / oraschemademo.py View on Github external
## CONFIG table
      ##
      cur.execute("""
                  CREATE TABLE config
                  (
                     key                 VARCHAR2(30)                     PRIMARY KEY,
                     value               VARCHAR2(4000)                   NOT NULL
                  )
                  """)
      log.msg("database table '%s' created" % "config")

      ## store database schema version
      ##
      config = [('schema-category', 'demo'),
                ('schema-version', SCHEMAVERSION),
                ('schema-created', utcnow())]
      for key, value in config:
         cur.execute("INSERT INTO config (key, value) VALUES (:1, :2)", [key, json_dumps(value)])
      conn.commit()

      log.msg("crossbar.io Demo schema created (version %d)!" % SCHEMAVERSION)

   else:

      log.msg("crossbar.io Demo schema dropped!")

   return dbschema.getSchemaVersion(conn, oraschema.LATESTVERSIONS)
github crossbario / crossbar / v1 / crossbar / linux / netstat.py View on Github external
def processRecord(self):
      self.current["timestamp"] = utcnow()
      if self.service:
         self.service.dispatchEvent(self.current)
      else:
         log.msg(self.current)
github crossbario / crossbar / v1 / crossbar / freebsd / netstat.py View on Github external
def processRecord(self, inPackets, inBytes, outPackets, outBytes):
      evt = {"timestamp": utcnow(),
             "packets-in": inPackets,
             "bytes-in": inBytes,
             "packets-out": outPackets,
             "bytes-out": outBytes}
      self.current = evt
      if self.service:
         self.service.dispatchEvent(evt)
      else:
         log.msg(evt)
github crossbario / crossbar / v1 / crossbar / fakeos / vmstat.py View on Github external
def processRecord(self, memUsed, memFree, cpuUser, cpuSys, cpuIdle):
      evt = {"timestamp": utcnow(),
             "mem-used": memUsed,
             "mem-free": memFree,
             "cpu-user": cpuUser,
             "cpu-system": cpuSys,
             "cpu-idle": cpuIdle}
      self.current = evt
      self.dispatchEvent(evt)
github crossbario / crossbar / v1 / crossbar / freebsd / vmstat.py View on Github external
def processRecord(self, memUsed, memFree, cpuUser, cpuSys, cpuIdle):
      evt = {"timestamp": utcnow(),
             "mem-used": memUsed,
             "mem-free": memFree,
             "cpu-user": cpuUser,
             "cpu-system": cpuSys,
             "cpu-idle": cpuIdle}
      self.current = evt
      if self.service:
         self.service.dispatchEvent(evt)
      else:
         log.msg(evt)
github crossbario / crossbar / v1 / crossbar / adminwebmodule / appcreds.py View on Github external
AppCreds.APPCRED_SECRET_PATTERN)}

      errcnt, errs = self.proto.checkDictArg("appcred spec", spec, attrs)

      txn.execute("SELECT created FROM appcredential WHERE key = ?", [spec["key"]])
      if txn.fetchone() is not None:
         errs["key"].append((self.proto.shrink(URI_ERROR + "duplicate-value"), "Application key '%s' already exists" % spec["key"]))
         errcnt += 1

      if errcnt:
         raise Exception(URI_ERROR + "illegal-argument", "one or more illegal arguments (%d errors)" % errcnt, errs)

      id = newid()
      appcred_uri = URI_APPCRED + id
      label = spec["label"].strip()
      now = utcnow()
      txn.execute("INSERT INTO appcredential (id, label, key, created, secret) VALUES (?, ?, ?, ?, ?)",
                  [id,
                   label,
                   spec["key"],
                   now,
                   spec["secret"]])

      services = self.proto.factory.services
      if services.has_key("restpusher"):
         services["restpusher"].recache(txn)
      if services.has_key("clientfilter"):
         services["clientfilter"].recache(txn)

      appcred = {"uri": appcred_uri,
                 "created": now,
                 "label": label,
github crossbario / crossbar / v1 / crossbar / fakeos / netstat.py View on Github external
def processRecord(self, inPackets, inBytes, outPackets, outBytes):

      evt = {"timestamp": utcnow(),
             "packets-in": inPackets,
             "bytes-in": inBytes,
             "packets-out": outPackets,
             "bytes-out": outBytes}
      self.current = evt
      self.dispatchEvent(evt)
github crossbario / crossbar / v1 / crossbar / adminwebmodule / extdirectremotes.py View on Github external
spec["rpc-base-uri"] = res[1]
         spec["router-url"] = res[2]
         spec["api-url"] = res[3]
         spec["api-object"] = res[4]
         spec["forward-cookies"] = res[5] != 0
         spec["redirect-limit"] = res[6]
         spec["connection-timeout"] = res[7]
         spec["request-timeout"] = res[8]
         spec["max-persistent-connections"] = res[9]
         spec["persistent-connection-timeout"] = res[10]

         errcnt += self.checkExtDirectRemotePermSpec(spec, specDelta, errs)

         self.proto.raiseDictArgException(errs)

         now = utcnow()
         delta = {}
         sql = "modified = ?"
         sql_vars = [now]

         if specDelta.has_key("require-appcred-uri"):
            if appcred_id != res[0]:
               delta["require-appcred-uri"] = appcred_uri
               sql += ", require_appcred_id = ?"
               sql_vars.append(appcred_id)

         if specDelta.has_key("rpc-base-uri"):
            newval = rpcBaseUri
            if newval != "" and newval != res[1]:
               delta["rpc-base-uri"] = newval
               sql += ", rpc_base_uri = ?"
               sql_vars.append(newval)
github crossbario / crossbar / crossbar / node / controller.py View on Github external
if worker_id not in self._workers or not isinstance(self._workers[worker_id], NativeWorkerProcess):
            emsg = "Could not stop native worker: no native worker with ID '{}' currently running".format(worker_id)
            raise ApplicationError('crossbar.error.worker_not_running', emsg)

        worker = self._workers[worker_id]

        if worker.status != 'started':
            emsg = "Could not stop native worker: worker with ID '{}' is not in status 'started', but status: '{}')".format(worker_id, worker.status)
            raise ApplicationError('crossbar.error.worker_not_running', emsg)

        stop_info = {
            'id': worker.id,
            'type': worker.TYPE,
            'kill': kill,
            'who': details.caller if details else None,
            'when': utcnow(),
        }

        # publish management API event
        #
        yield self.publish(
            '{}.on_stop_requested'.format(self._uri_prefix),
            stop_info,
            options=PublishOptions(exclude=details.caller if details else None, acknowledge=True)
        )

        # send SIGKILL or SIGTERM to worker
        #
        if kill:
            self.log.info("Killing {worker_type} worker with ID '{worker_id}'",
                          worker_type=worker.TYPE, worker_id=worker_id)
            self._workers[worker_id].proto.transport.signalProcess("KILL")