-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #419 from MetOffice/feature-self-updating-database
Feature self updating database
- Loading branch information
Showing
11 changed files
with
106 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import forest.main | ||
import forest.cli.main | ||
import forest.data as data | ||
|
||
|
||
class DatasetSyncCallback: | ||
"""Process to synchronize datasets""" | ||
def __init__(self, datasets): | ||
self.datasets = datasets | ||
|
||
def __call__(self): | ||
for dataset in self.datasets: | ||
if hasattr(dataset, "sync"): | ||
dataset.sync() | ||
|
||
|
||
def on_server_loaded(server_context): | ||
data.on_server_loaded() | ||
|
||
# Add periodic callback to keep database(s) up to date | ||
_, argv = forest.cli.main.parse_args() | ||
config = forest.main.configure(argv) | ||
interval_ms = 15 * 60 * 1000 # 15 minutes in miliseconds | ||
callback = DatasetSyncCallback(list(config.datasets)) | ||
server_context.add_periodic_callback(callback, interval_ms) | ||
|
||
|
||
def on_session_destroyed(session_context): | ||
''' | ||
Function called when a session is closed | ||
(e.g. tab closed or time out) | ||
''' | ||
if data.AUTO_SHUTDOWN: | ||
import sys | ||
sys.exit('\033[1;31mThe session has ended - tab closed or timeout. \n\n --- Terminating the Forest progam and relinquishing control of port. ---\033[1;00m') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.