backend.diagnostics   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 40
dl 0
loc 51
rs 10
c 0
b 0
f 0
1
'''Full Cycle Mining Systems Check'''
2
import datetime
3
from colorama import Fore
4
import backend.fcmutils as utils
5
from backend.fcmapp import ApplicationService
6
from domain.loggingrepository import getminerlog
7
from domain.logging import MinerLog
8
9
print('Starting application...')
10
APP = ApplicationService()
11
print('started', APP.component)
12
13
APP.cache.tryputcache(key='test', value='value')
14
CACHE_VALUE = utils.safestring(APP.cache.trygetvaluefromcache('test'))
15
if CACHE_VALUE == 'value':
16
    print(Fore.GREEN+'cache is working')
17
else:
18
    print(Fore.RED+'cache is broken')
19
20
try:
21
    SUCCESS = APP.alert('Full Cycle diagnostics test')
22
    if SUCCESS:
23
        print(Fore.GREEN+'message bus is working')
24
    else:
25
        print(Fore.RED+'message bus is broken')
26
except BaseException as ex:
27
    print(Fore.RED+'message bus is broken')
28
    print(APP.exceptionmessage(ex))
29
30
try:
31
    LOG = MinerLog()
32
    LOG.createdate = datetime.datetime.utcnow()
33
    LOG.minerid = 'diag'
34
    LOG.minername = 'diagnostics'
35
    LOG.action = 'diagnostics'
36
    SUCCESS = APP.log_mineractivity(LOG)
37
38
    LOGS = getminerlog(APP.getsession())
39
    #print(log.__dict__)
40
    LOG_CNT = 0
41
    for log in LOGS:
42
        LOG_CNT += 1
43
44
    if SUCCESS and LOG_CNT > 0:
45
        print(Fore.GREEN+'database is working, {0} logs'.format(LOG_CNT))
46
    else:
47
        print(Fore.RED+'database is broken')
48
except BaseException as ex:
49
    print(Fore.RED+'database is broken')
50
    print(APP.exceptionmessage(ex))
51