-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from LCOGT/feature/add_operation_caching
Added caching of operations by inputs and operation name, and added o…
- Loading branch information
Showing
14 changed files
with
335 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from datalab.datalab_session.data_operations.data_operation import BaseDataOperation | ||
from time import sleep | ||
from math import ceil | ||
|
||
class LongOperation(BaseDataOperation): | ||
@staticmethod | ||
def name(): | ||
return 'Long' | ||
|
||
@staticmethod | ||
def description(): | ||
return """The Long operation just sleeps and then returns your input images as output without doing anything""" | ||
|
||
@staticmethod | ||
def wizard_description(): | ||
return { | ||
'name': LongOperation.name(), | ||
'description': LongOperation.description(), | ||
'category': 'test', | ||
'inputs': { | ||
'input_files': { | ||
'name': 'Input Files', | ||
'description': 'The input files to operate on', | ||
'type': 'file', | ||
'minimum': 1, | ||
'maxmimum': 999 | ||
}, | ||
'duration': { | ||
'name': 'Duration', | ||
'description': 'The duration of the operation', | ||
'type': 'number', | ||
'minimum': 0, | ||
'maximum': 99999.0, | ||
'default': 60.0 | ||
}, | ||
} | ||
} | ||
|
||
def operate(self): | ||
num_files = len(self.input_data.get('input_files', [])) | ||
per_image_timeout = ceil(float(self.input_data.get('duration', 60.0)) / num_files) | ||
for i, file in enumerate(self.input_data.get('input_files', [])): | ||
print(f"Processing long operation on file {file.get('basename', 'No basename found')}") | ||
sleep(per_image_timeout) | ||
self.set_percent_completion((i+1) / num_files) | ||
# Done "processing" the files so set the output which sets the final status | ||
output = { | ||
'output_files': self.input_data.get('input_files', []) | ||
} | ||
self.set_output(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,5 @@ def wizard_description(): | |
} | ||
} | ||
|
||
def operate(self, input_data): | ||
def operate(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pkgutil import walk_packages | ||
import inspect | ||
from django.utils.module_loading import import_string | ||
from datalab.datalab_session import data_operations | ||
|
||
|
||
def available_operations(): | ||
operations = {} | ||
base_operation = import_string('datalab.datalab_session.data_operations.data_operation.BaseDataOperation') | ||
for (loader, module_name, _) in walk_packages(data_operations.__path__): | ||
module = loader.find_module(module_name).load_module() | ||
members = inspect.getmembers(module, inspect.isclass) | ||
for member in members: | ||
if member[0] != 'BaseDataOperation' and issubclass(member[1], base_operation): | ||
operations[member[1].name()] = member[1] | ||
|
||
return operations | ||
|
||
|
||
def available_operations_tuples(): | ||
names = available_operations().keys() | ||
return [(name, name) for name in names] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
datalab/datalab_session/migrations/0002_dataoperation_cache_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.10 on 2024-02-08 23:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('datalab_session', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='dataoperation', | ||
name='cache_key', | ||
field=models.CharField(blank=True, default='', help_text='Cache key for this operation', max_length=64), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.