Skip to content

Commit

Permalink
Merge pull request #176 from RUGSoftEng/backend/periodic_fetching
Browse files Browse the repository at this point in the history
Fixing periodic fetching, refactoring backend code
  • Loading branch information
TheVeggydude authored Apr 27, 2018
2 parents 23551de + 1669bf6 commit fdcbb80
Show file tree
Hide file tree
Showing 40 changed files with 986 additions and 505 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ ENV/
.vscode
#Directories
/pydash/logs
/pydash/.pytest_cache
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.6"
3 changes: 2 additions & 1 deletion build_and_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ RunFlask()
{
PydashPrint "Finally: Starting flask webservice. Close with Ctrl+C"
cd pydash
pipenv run "flask run --no-reload"
pipenv run flask run --no-reload
cd ..
}

BuildFrontend
Expand Down
13 changes: 4 additions & 9 deletions pydash/Pipfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]

Flask = "*"
Flask-WTF = "*"
flask-login = "*"
Expand All @@ -18,16 +15,14 @@ requests = "*"
Flask-Cors = "*"
pqdict = "*"


[dev-packages]


pytest = "*"
pytest-cov = "*"
pytest-xdist = "*"
pytest-env = "*"

[requires]

python_version = "3.6"


[pipenv]

keep_outdated = true
135 changes: 133 additions & 2 deletions pydash/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pydash/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
import pydash_database
import pydash_app.user.repository
import pydash_app.dashboard.repository
@pytest.fixture(autouse=True)
def clean_in_memory_database(*_):
pydash_app.user.repository.clear_all()
pydash_app.dashboard.repository.clear_all()

Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
"""
Performs the remote requests to the flask-monitoring-dashboard.
The method names in this module 1:1 reflect the names of the flask-monitoring-dashboard API
(but without the word 'JSON' in them, because conversion from JSON to Python dictionaries/lists
is one of the thing this module handles for you.)
"""

import requests
import jwt
import json

import pydash_app.impl.logger as pylog
import pydash_logger

DETAILS_ENDPOINT = 0
RULES_ENDPOINT = 1
DATA_ENDPOINT = 2

logger = pylog.Logger(__name__)
logger = pydash_logger.Logger(__name__)

def get_details(dashboard_url):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@
The scheduler will be started by calling the `start()` function. It will stop scheduling and tear down the spawned processes when calling the `stop()` function.
This function will also (in most cases) be automatically called when the main process finishes execution.
Example code with default scheduler:
>>> import pydash_app.impl.periodic_tasks as pt
>>> import periodic_tasks as pt
>>> import datetime
>>> pt.start_default_scheduler()
>>> pt.add_periodic_task('foo', datetime.timedelta(seconds=3), pt.foo)
>>> pt.add_periodic_task('bar', datetime.timedelta(seconds=5), pt.bar)
>>> pt.add_background_task('baz', pt.baz)
>>> pt.add_periodic_task('bar', datetime.timedelta(seconds=1), pt.bar) # overrides previous `bar` task with new settings
>>> pt.remove_task('foo')
>>> pt.default_task_scheduler.stop()
Example code with custom scheduler:
>>> import pydash_app.impl.periodic_tasks as pt
>>> import periodic_tasks as pt
>>> ts = pt.TaskScheduler()
>>> import datetime
>>> import datetime, time
>>> ts.start()
>>> ts.add_periodic_task('foo', datetime.timedelta(seconds=1), pt.foo)
>>> ts.add_periodic_task('bar', datetime.timedelta(seconds=5), pt.bar)
>>> ts.add_periodic_task('foo', datetime.timedelta(milliseconds=1), pt.foo)
>>> ts.add_periodic_task('bar', datetime.timedelta(milliseconds=5), pt.bar)
>>> time.sleep(2)
>>> ts.stop()
"""

from .task_scheduler import TaskScheduler
Expand Down
Loading

0 comments on commit fdcbb80

Please sign in to comment.