Skip to content

Commit

Permalink
Update check_timeshift.py and README
Browse files Browse the repository at this point in the history
  • Loading branch information
VDigitall committed Jul 7, 2017
1 parent cb9d801 commit 9ceae9e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 30 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,36 @@ Follow the instructions:
[edge_data_bridge_defaults]
user_agent = my_platform_name
resources_api_server = http://public.api-sandbox.openprocurement.org
resources_api_server = http://public.api.example.org
```
2. Bootstrap the buildout with Python 2.7:
1. Bootstrap the buildout with Python 2.7:

```
$ python bootstrap.py
```
3. Build the buildout:
1. Build the buildout:
```
$ bin/buildout -N
```
1. For check delay between EDGE Server and Public Server are two ways:
* Look at Netdata dashboard if configured.
* Run python script:
```shell
pip install -r requirements.txt
python check_timeshift.py https://public-api-server-url http://your-edge-ip-or-domain api_version resource
```
**api_version** - it is version of api which you wont to check
**resource** - it is document type like: auctions, contracts, plans or tenders
System requirements (Fedora 24):
dnf install zeromq3-devel git gcc python-devel file python2-systemd python-virtualenv sqlite-devel libffi-devel openssl-devel libsodium libsodium-devel redhat-rpm-config logrotate libselinux-python bash-completion policycoreutils-python policycoreutils-python-utils nginx
Local development environment also requires additional dependencies:
dnf install couchdb ctorrent
dnf install couchdb
To start environment services:
Expand Down
26 changes: 0 additions & 26 deletions check_dates.py

This file was deleted.

62 changes: 62 additions & 0 deletions check_timeshift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
"""
EDGE Timeshift checker
"""
import argparse
from datetime import datetime, timedelta
from requests import Session
from termcolor import colored


def check_timeshift(public_url, edge_url, api_version, resource):
delta = timedelta(days=1)
testing_from = (datetime.now() + delta).strftime('%Y-%m-%d')
source_url = '{}/api/{}/{}?descending=1&offset={}&limit=1000'.format(
public_url, api_version, resource, testing_from)
test_url = '{}/api/{}/{}/'.format(edge_url, api_version, resource)
r = Session()
lr = Session()
try:
response = r.get(source_url).json()
except Exception as e:
print 'InvalidResponse: {}'.format(e.message)
raise SystemExit

while response['data']:
for item in response['data']:
l_resp = lr.get(test_url + item['id']).json()
if (l_resp.get('data', {}).get('dateModified') !=
item['dateModified']):
print colored('API - {}, EDGE - {}, ID: {}'.format(
item['dateModified'],
l_resp.get('data', {}).get('dateModified'),
item['id']), 'red')
else:
print colored('Pass: {} - {}'.format(
item['id'], item['dateModified']), 'green')
next_page = response['next_page']['path']
response = r.get(public_url + next_page).json()


def main():
"""
Main function
"""
parser = argparse.ArgumentParser(
description="----- EDGE Timeshift checker -----")
parser.add_argument('public_server', type=str,
help="https://api.public.org")
parser.add_argument('edge_server', type=str,
help='http://my_edge_domain_or_ip')
parser.add_argument('api_version', type=str, help='2.3')
parser.add_argument(
'resource', type=str,
help='Document type for ckecking like: tenders, plans etc.')
args = parser.parse_args()
check_timeshift(args.public_server, args.edge_server, args.api_version,
args.resource)


#######################################################################
if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
termcolor

0 comments on commit 9ceae9e

Please sign in to comment.