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

Commit

Permalink
Merge pull request #1255 from mozilla-services/feat/issue-1243
Browse files Browse the repository at this point in the history
feat: switch Rust startup to Rust only
  • Loading branch information
bbangert authored May 24, 2018
2 parents 7c22ccd + 0ef11b6 commit 02cd0ea
Show file tree
Hide file tree
Showing 22 changed files with 939 additions and 1,148 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
604 changes: 382 additions & 222 deletions autopush_rs/Cargo.lock → Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["autopush_rs"]
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 --path autopush_rs && \
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 --path autopush_rs && \
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 02cd0ea

Please sign in to comment.