-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
36 lines (29 loc) · 1.18 KB
/
worker.py
File metadata and controls
36 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
from threading import Thread
from service.service import RestService
import queue
import logging
logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] (%(threadName)-10s) %(message)s', )
class Worker(Thread):
meterId = "99806"
applicationName = "electro-backend"
endpoint = "http://jacobwortmann.dk:9080/%s/api/meter/%s/readings/" % (applicationName, meterId)
user = "jacob"
password = "secret"
restService = None
"""docstring for Worker"""
def __init__(self, name):
super(Worker, self).__init__(name=name)
self.restService = RestService(self.endpoint, self.user, self.password)
def run(self):
while True:
item = queue.get()
if item is not None:
try:
wasSuccessful = self.restService.post(item)
if not wasSuccessful:
logging.error("Unable to post to endpoint, putting reading back to queue")
queue.put(item)
except Exception as e:
logging.error("Unable to post to endpoint, putting reading back to queue")
queue.put(item)