Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ flask match run
### DATEX II push to Mobilithek

```bash
flask push datex-static # Full static DATEX II snapshot
flask push datex-realtime-full # Full realtime status snapshot
flask push datex-realtime-diff # Incremental realtime status diff
flask location push-mobilithek-static # Full static DATEX II snapshot
flask location push-mobilithek-realtime-full # Full realtime status snapshot
flask location push-mobilithek-realtime-diff # Incremental realtime status diff
```

See [DATEX II push to Mobilithek](#datex-ii-push-to-mobilithek-1) for details.
Expand All @@ -137,9 +137,9 @@ Both DATEX II `3.5` and `3.7` are supported, selected via `MOBILITHEK_VERSION`.
The pushes can be triggered manually through the CLI:

```bash
flask push datex-static # Full static DATEX II snapshot
flask push datex-realtime-full # Full realtime status snapshot (SNAPSHOT_PUSH)
flask push datex-realtime-diff # Incremental realtime status diff (DELTA_PUSH, skipped when empty)
flask location push-mobilithek-static # Full static DATEX II snapshot
flask location push-mobilithek-realtime-full # Full realtime status snapshot (SNAPSHOT_PUSH)
flask location push-mobilithek-realtime-diff # Incremental realtime status diff (DELTA_PUSH, skipped when empty)
```

### Scheduled push
Expand All @@ -157,10 +157,10 @@ MOBILITHEK_CERTIFICATE_FILENAME: 'mobilithek-binary-butterfly.crt.pem' # client
MOBILITHEK_KEY_FILENAME: 'mobilithek-binary-butterfly.key.pem' # client key in KEY_DIR

# Push schedule (only active when MOBILITHEK_ENABLED is true):
DATEX_STATIC_PUSH_HOUR: 3 # static snapshot once a day at this hour ...
DATEX_STATIC_PUSH_MINUTE: 0 # ... and minute
DATEX_REALTIME_FULL_PUSH_FREQUENCY: 21600 # full realtime snapshot, in seconds (default every 6 hours)
DATEX_REALTIME_DIFF_PUSH_FREQUENCY: 60 # incremental realtime diff, in seconds (default every minute)
MOBILITHEK_STATIC_PUSH_HOUR: 3 # static snapshot once a day at this hour ...
MOBILITHEK_STATIC_PUSH_MINUTE: 0 # ... and minute
MOBILITHEK_REALTIME_FULL_PUSH_FREQUENCY: 21600 # full realtime snapshot, in seconds (default every 6 hours)
MOBILITHEK_REALTIME_DIFF_PUSH_FREQUENCY: 60 # incremental realtime diff, in seconds (default every minute)
```

Messages are sent via mutual-TLS `POST` to the Mobilithek publication endpoint, using the client certificate and key
Expand Down
8 changes: 4 additions & 4 deletions config_dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ MOBILITHEK_KEY_FILENAME: 'mobilithek-binary-butterfly.key.pem'

# DATEX II push schedule (only active when MOBILITHEK_ENABLED is true).
# Static data is pushed once a day at the configured time of day:
DATEX_STATIC_PUSH_HOUR: 3
DATEX_STATIC_PUSH_MINUTE: 0
MOBILITHEK_STATIC_PUSH_HOUR: 3
MOBILITHEK_STATIC_PUSH_MINUTE: 0
# Full realtime status snapshot, in seconds (default every 6 hours):
DATEX_REALTIME_FULL_PUSH_FREQUENCY: 21600
MOBILITHEK_REALTIME_FULL_PUSH_FREQUENCY: 21600
# Incremental realtime status diff, in seconds (default every minute):
DATEX_REALTIME_DIFF_PUSH_FREQUENCY: 60
MOBILITHEK_REALTIME_DIFF_PUSH_FREQUENCY: 60

SERVER_AUTH_USERS:
# Test user for local development
Expand Down
2 changes: 0 additions & 2 deletions webapp/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from .import_cli import import_cli
from .location_cli import location_cli
from .match_cli import match_cli
from .push_cli import push_cli
from .source_cli import source_cli


Expand All @@ -30,4 +29,3 @@ def register_cli_to_app(app: Flask):
app.cli.add_command(import_cli)
app.cli.add_command(source_cli)
app.cli.add_command(location_cli)
app.cli.add_command(push_cli)
41 changes: 24 additions & 17 deletions webapp/cli/location_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

from datetime import datetime

import click
from flask.cli import AppGroup

from webapp.common.error_handling import catch_exception
from webapp.dependencies import dependencies
from webapp.services.push_services.datex_push_service import ChargeLocationService

location_cli = AppGroup('location')

Expand All @@ -33,21 +33,28 @@ def assign_regionalschluessel(source_id: str | None, re_assign: bool):
dependencies.get_location_service().assign_official_region_codes(source_id=source_id, re_assign=re_assign)


@location_cli.command('push-datex-static', help='pushes datex2 static data')
def push_datex_static() -> None:
charge_location_service = dependencies.get_charge_location_service()
@location_cli.command('push-mobilithek-static', help='Push the full static DATEX II snapshot to Mobilithek.')
@catch_exception
def push_mobilithek_static() -> None:
charge_location_service: ChargeLocationService = dependencies.get_charge_location_service()
charge_location_service.push_datex_static()


@location_cli.command('push-datex-realtime', help='pushes datex2 realtime data')
@click.option('-s', '--since', 'updated_since', type=click.DateTime())
@click.option('--incremental-update', 'incremental_update', default=False, is_flag=True)
def push_datex_realtime(updated_since: datetime | None = None, incremental_update: bool | None = None) -> None:
if incremental_update is not None and updated_since is not None:
raise click.BadParameter('Cannot specify incremental update and updated since')

charge_location_service = dependencies.get_charge_location_service()
charge_location_service.push_datex_realtime(
updated_since=updated_since,
incremental_update=incremental_update or False,
)
@location_cli.command(
'push-mobilithek-realtime-full',
help='Push the full realtime DATEX II status snapshot to Mobilithek.',
)
@catch_exception
def push_mobilithek_realtime_full() -> None:
charge_location_service: ChargeLocationService = dependencies.get_charge_location_service()
charge_location_service.push_datex_realtime(incremental_update=False)


@location_cli.command(
'push-mobilithek-realtime-diff',
help='Push an incremental realtime DATEX II status diff to Mobilithek (nothing is sent if the diff is empty).',
)
@catch_exception
def push_mobilithek_realtime_diff() -> None:
charge_location_service: ChargeLocationService = dependencies.get_charge_location_service()
charge_location_service.push_datex_realtime(incremental_update=True)
49 changes: 0 additions & 49 deletions webapp/cli/push_cli.py

This file was deleted.

8 changes: 4 additions & 4 deletions webapp/services/import_services/generic_import_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ def _schedule_push(self):
# Static data: push the full snapshot once a day.
celery.add_periodic_task(
crontab(
minute=str(self.config_helper.get('DATEX_STATIC_PUSH_MINUTE', 0)),
hour=str(self.config_helper.get('DATEX_STATIC_PUSH_HOUR', 3)),
minute=str(self.config_helper.get('MOBILITHEK_STATIC_PUSH_MINUTE', 0)),
hour=str(self.config_helper.get('MOBILITHEK_STATIC_PUSH_HOUR', 3)),
),
push_datex_static_task,
)

# Realtime data: push the full status snapshot every 6 hours ...
celery.add_periodic_task(
self.config_helper.get('DATEX_REALTIME_FULL_PUSH_FREQUENCY', 6 * 60 * 60),
self.config_helper.get('MOBILITHEK_REALTIME_FULL_PUSH_FREQUENCY', 6 * 60 * 60),
push_datex_realtime_full_task,
)

# ... and an incremental diff every minute (skipped when nothing changed).
celery.add_periodic_task(
self.config_helper.get('DATEX_REALTIME_DIFF_PUSH_FREQUENCY', 60),
self.config_helper.get('MOBILITHEK_REALTIME_DIFF_PUSH_FREQUENCY', 60),
push_datex_realtime_diff_task,
)

Expand Down
Loading