Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
feat: switch Rust startup to Rust only
Browse files Browse the repository at this point in the history
Co-authored by: Phil Jenvey <[email protected]>

Closes #1243
  • Loading branch information
bbangert committed May 23, 2018
1 parent 7c22ccd commit bb406b5
Show file tree
Hide file tree
Showing 21 changed files with 773 additions and 1,010 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ pypy/
.eggs/
autopush_rs/target
autopush_rs/_native*
target
*.rs.bk
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ install:
# Build here instead of within tox's pip install -e. It hides the output
# which can kill the job on slower travis runs
if [ ${WITH_RUST} == "release" ]; then
export CARGO_ARG="--release"
cargo install --path autopush_rs || travis_terminate 1
#export CARGO_ARG="--debug"
else
cargo install --debug --path autopush_rs || travis_terminate 1
fi
cargo build --manifest-path autopush_rs/Cargo.toml ${CARGO_ARG:-""} || \
travis_terminate 1
#cargo build --manifest-path autopush_rs/Cargo.toml ${CARGO_ARG:-""} || \
# travis_terminate 1
#cargo install ${CARGO_ARG:-""} || travis_terminate 1
#unset WITH_RUST
fi
script:
- tox -v -- ${CODECOV:+--with-coverage --cover-xml --cover-package=autopush}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RUN \
make clean && \
pip install -r requirements.txt && \
pypy setup.py develop && \
cd autopush_rs && \
cargo install && \
cargo clean && \
rustup self uninstall -y

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.python27
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN \
make clean && \
pip install -r requirements.txt && \
python setup.py develop && \
cd autopush_rs && \
cargo install && \
cargo clean && \
rustup self uninstall -y

Expand Down
80 changes: 0 additions & 80 deletions autopush/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""autopush/autoendpoint daemon scripts"""
import os
import time
from argparse import Namespace # noqa

from twisted.application.internet import (
Expand Down Expand Up @@ -40,7 +39,6 @@
monkey_patch_ssl_wrap_socket,
undo_monkey_patch_ssl_wrap_socket,
)
from autopush.webpush_server import WebPushServer
from autopush.websocket import (
ConnectionWSSite,
PushServerFactory,
Expand Down Expand Up @@ -307,81 +305,3 @@ def from_argparse(cls, ns, resource=None):
aws_ddb_endpoint=ns.aws_ddb_endpoint,
resource=resource
)


class RustConnectionApplication(AutopushMultiService):
"""The autopush application"""

config_files = AutopushMultiService.shared_config_files + (
'/etc/autopush_connection.ini',
'configs/autopush_connection.ini',
'~/.autopush_connection.ini',
'.autopush_connection.ini'
)

parse_args = staticmethod(parse_connection) # type: ignore
logger_name = "AutopushRust"
push_server = None

def setup(self, rotate_tables=True, num_threads=10):
super(RustConnectionApplication, self).setup(rotate_tables)

self.db.setup(self.conf.preflight_uaid)

# No add_memusage: requires twisted
self.push_server = WebPushServer(
self.conf,
self.db,
num_threads=num_threads,
)

def run(self): # pragma: nocover
try:
self.startService()
while True:
try:
# handle a graceful shutdown on SIGINT w/ a busy
# loop. we can't Thread.join because SIGINT won't
# interrupt it
time.sleep(6000)
except KeyboardInterrupt:
return 1
finally:
self.stopService()

def startService(self):
self.push_server.start()

def stopService(self):
self.push_server.stop()

@classmethod
def from_argparse(cls, ns, resource=None): # pragma: nocover
# type: (Namespace, DynamoDBResource) -> AutopushMultiService
return super(RustConnectionApplication, cls)._from_argparse(
ns,
port=ns.port,
endpoint_scheme=ns.endpoint_scheme,
endpoint_hostname=ns.endpoint_hostname,
endpoint_port=ns.endpoint_port,
router_scheme="https" if ns.router_ssl_key else "http",
router_hostname=ns.router_hostname,
router_port=ns.router_port,
env=ns.env,
hello_timeout=ns.hello_timeout,
router_ssl=dict(
key=ns.router_ssl_key,
cert=ns.router_ssl_cert,
dh_param=ns.ssl_dh_param
),
# XXX: default is for autopush_rs
auto_ping_interval=ns.auto_ping_interval or 300,
auto_ping_timeout=ns.auto_ping_timeout,
max_connections=ns.max_connections,
close_handshake_timeout=ns.close_handshake_timeout,
aws_ddb_endpoint=ns.aws_ddb_endpoint,
megaphone_api_url=ns.megaphone_api_url,
megaphone_api_token=ns.megaphone_api_token,
megaphone_poll_interval=ns.megaphone_poll_interval,
resource=resource
)
10 changes: 0 additions & 10 deletions autopush/main_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,6 @@ def parse_connection(config_files, args):
help="The client handshake timeout. Set to 0 to"
"disable.", default=0, type=int,
env_var="HELLO_TIMEOUT")
parser.add_argument('--megaphone_api_url',
help="The megaphone API URL to query for updates",
default=None, type=str, env_var="MEGAPHONE_API_URL")
parser.add_argument('--megaphone_api_token',
help="The megaphone API token",
default=None, type=str, env_var="MEGAPHONE_API_TOKEN")
parser.add_argument('--megaphone_poll_interval',
help="The megaphone API polling interval",
default=30, type=int,
env_var="MEGAPHONE_POLL_INTERVAL")

add_shared_args(parser)
return parser.parse_args(args)
Expand Down
Loading

0 comments on commit bb406b5

Please sign in to comment.