Skip to content

Commit

Permalink
Merge pull request #358 from golemfactory/mplebanski/add_usage_to_wtct
Browse files Browse the repository at this point in the history
Add cpu_usage field to WTCT
  • Loading branch information
mplebanski committed Sep 17, 2019
2 parents 2a4899f + 5137259 commit c42e647
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions golem_messages/message/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class WantToComputeTask(ConcentEnabled, base.Message):
"""
__slots__ = [
'perf_index', # Provider's performance; a benchmark result
'cpu_usage', # Provider's cpu usage; a benchmark result
'max_resource_size', # P's storage size available for computation
'max_memory_size', # P's RAM
'price', # Offered price per hour in GNT WEI (10e-18)
Expand Down Expand Up @@ -279,6 +280,15 @@ def deserialize_slot(self, key, value):
if key == 'task_header' and value is not None:
return TaskHeader(**value)

if key == 'cpu_usage' and value is not None:
validators.validate_integer(key, value)
if value < 0:
raise exceptions.FieldError(
"Should be equal or greater than zero",
field=key,
value=value,
)

value = super().deserialize_slot(key, value)

if key == 'num_subtasks':
Expand Down
8 changes: 8 additions & 0 deletions tests/message/tasks/test_want_to_compute_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ def test_concent_enabled_invokes_another_constructor(self):
wtct = self.FACTORY()
self.assertIsNotNone(wtct.header)
self.assertIsInstance(wtct.header, MessageHeader)

def test_cpu_usage_negative_integer(self):
wtct = message.tasks.WantToComputeTask(cpu_usage=-1)
serialized = shortcuts.dump(wtct, None, None)
with self.assertRaises(
exceptions.FieldError,
):
shortcuts.load(serialized, None, None)

0 comments on commit c42e647

Please sign in to comment.