Kyaraben server & worker

The server and worker applications are configured via environment variables.

To print their default values:

$ kyaraben-server --write-config-defaults
export KYARABEN_SERVER_LISTEN_ADDRESS=127.0.0.1
export KYARABEN_SERVER_LISTEN_PORT=8084
export KYARABEN_LOG_JSONFORMAT=False           # Write log lines as JSON objects
export KYARABEN_AMQP_HOSTNAME=127.0.0.1
export KYARABEN_AMQP_ADMIN_USERNAME=guest
export KYARABEN_AMQP_ADMIN_PASSWORD=guest
export KYARABEN_ORCHESTRATION_NOVNC_HOST=''    # IP address/hostname of the player containers
export KYARABEN_ORCHESTRATION_STACKPREFIX=''
export KYARABEN_OPENSTACK_OS_AUTH_URL=''
export KYARABEN_OPENSTACK_INSECURE=False       # Do not verify SSL certificate
export KYARABEN_OPENSTACK_OS_CACERT=''
export KYARABEN_OPENSTACK_OS_TENANT_NAME=''
export KYARABEN_OPENSTACK_OS_USERNAME=''
export KYARABEN_OPENSTACK_OS_PASSWORD=''
export KYARABEN_OPENSTACK_FLOATING_NET=net04_ext
export KYARABEN_DOCKER_HOST=''
export KYARABEN_DOCKER_TLS_VERIFY=True
export KYARABEN_DB_DSN=''
export KYARABEN_QUOTA_VM_ASYNC_MAX=1
export KYARABEN_QUOTA_VM_LIVE_MAX=3
export KYARABEN_OPENSTACK_TEMPLATE=android.yaml
export KYARABEN_WORKER_HEAT_POLL_INTERVAL=5
export KYARABEN_RETRY_DELAY_MIN=1              # initial delay between retries
export KYARABEN_RETRY_DELAY_MAX=30             # max delay between retries
export KYARABEN_RETRY_FAIL_TIMEOUT=86400       # after 24h, failed messages will be discarted
export KYARABEN_MEDIA_TEMPDIR=/tmp
export KYARABEN_PRJDATA_APK_PATH='/data/project/apk/{apk_id}.apk'
export KYARABEN_PRJDATA_CAMERA_PATH='/data/project/camera/{camera_id}'

You can redirect this output to a file and source it from the shell.

The server

Once the variables are set, the server can be run with kyaraben-server:

(kyaraben) $ kyaraben-server
2016-07-27 18:03:58,931 - ats.kyaraben.server - DEBUG  Set up DBMS connection pool...
2016-07-27 18:03:58,933 - ats.kyaraben.server - DEBUG  Set up AMQP..
2016-07-27 18:03:58,950 - ats.kyaraben.server - DEBUG  setup done.
2016-07-27 18:03:58,950 - ats.kyaraben.server - INFO   Server started at ('127.0.0.1', 8084)

All log messages are printed to standard output. You can change the log format to JSON by setting KYARABEN_LOG_JSONFORMAT = True.

Other options:

$ kyaraben-server -h
usage: kyaraben-server [-h] [--write-config-defaults] [--debug] [--no-debug]
                       [--db-update]

optional arguments:
  -h, --help            show this help message and exit
  --write-config-defaults
                        print default configuration values
  --debug               enable debug toolbar
  --no-debug            disable debug toolbar
  --db-update           Update the database schema

The debug toolbar is useful to inspect and troubleshoot requests, it is available under the path /_debugtoolbar.

The --db-update option is required the first time the server is run, and after version upgrades. If omitted, it will refuse to start the server in case of pending schema updates.

The worker

The server process creates tasks that are meant for worker processes. Any number of worker processes can be run, though each only executes one task at a time.

The workers use the same configuration variables as the server process.

To run a worker process:

$ kyaraben-worker
2016-11-23 16:54:28,054 - ats.kyaraben.worker.main - INFO     event='waiting for messages'

For debugging purposes, a few options are provided:

$ kyaraben-worker -h
usage: kyaraben-worker [-h] [--reject [REJECT [REJECT ...]]] [--tasks TASKS]

optional arguments:
  -h, --help            show this help message and exit
  --reject [REJECT [REJECT ...]]
                        Reject message
  --tasks TASKS         Perform a given number of tasks, then quit (0 = loop
                        forever)

Though it should not happen in production, tasks may fail when services are temporarily unavailable. An optional, dedicated process receives the failed tasks and reschedules them (by delaying from KYARABEN_RETRY_DELAY_MIN up to KYARABEN_RETRY_DELAY_MAX seconds each time, until KYARABEN_RETRY_FAIL_TIMEOUT has passed and the task is discarded).

$ kyaraben-retry
2016-11-23 17:03:13,873 - ats.kyaraben.retry.main - INFO     event='waiting for messages'