Skip to content

Add worker cost fields

https://redmine.teklia.com/issues/8453

Three new fields are introduced:

  • Worker.cost_cpu_hour: Cost for running any version of this worker for an hour with use_gpu = False set on the WorkerRun. Irrelevant if the WorkerVersion requires GPUs.
  • Worker.cost_gpu_hour: Cost for running any version of this worker for an hour with use_gpu = True set on the WorkerRun. Irrelevant if the WorkerVersion does not support GPUs.
  • Worker.cost_1k_elements: Cost for running any version of this worker over 1000 elements.

All of those fields use a DecimalField with 8 max digits and 3 decimal places. They are non-nullable but still optional, defaulting to 0. FloatField should not be used to avoid rounding errors with monetary calculations.

Using decimals require some care. The Python decimal module requires some configuration to get DecimalField to work the way we need it to through its concept of contexts, and we will probably tweak that over time. For now, you can call decimal.setcontext(decimal.BasicContext) in arkindex.project.settings. The BasicContext blocks most of the weirdness like divisions by zero that return Infinity.

All fields should have a help_text set, so that we can document them both in the Django admin and in the API.

All fields also have a MinValueValidator to prevent setting a cost to any negative value.

All fields are editable in the Django admin, in a fieldset named Costs. They are also available in the WorkerSerializer, but read-only. This should include them in ListWorkers and RetrieveWorker.