Skip to content

Commit

Permalink
Wrap disk poll caller
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartkmarsh committed Sep 1, 2016
1 parent f7a0611 commit 3ae9148
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions dataplicity/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,33 @@ def run_forever(self):
def disk_poll(self):
now = time.time()

try:
if now >= self.next_disk_poll_time:
self.next_disk_poll_time = now + self.disk_poll_rate_seconds
disk_space = disk_usage('/')

with self.remote.batch() as batch:
batch.call_with_id(
'authenticate_result',
'device.check_auth',
device_class='tuxtunnel',
serial=self.serial,
auth_token=self.auth_token
)
batch.call_with_id(
'set_disk_space_result',
'device.set_disk_space',
disk_capacity=disk_space.total,
disk_used=disk_space.used
)
except Exception as e:
log.error("disk poll failed %s", e)
if now >= self.next_disk_poll_time:
self.next_disk_poll_time = now + self.disk_poll_rate_seconds
disk_space = disk_usage('/')

with self.remote.batch() as batch:
batch.call_with_id(
'authenticate_result',
'device.check_auth',
device_class='tuxtunnel',
serial=self.serial,
auth_token=self.auth_token
)
batch.call_with_id(
'set_disk_space_result',
'device.set_disk_space',
disk_capacity=disk_space.total,
disk_used=disk_space.used
)

def poll(self):
"""Called at regulat intervals."""
t = time.time()
log.debug('poll t=%.02fs', t)
self.disk_poll()
try:
self.disk_poll()
except Exception as e:
log.error("disk poll failed %s", e)
self.sync()

def close(self):
Expand Down

0 comments on commit 3ae9148

Please sign in to comment.