Skip to content

Commit

Permalink
Update downloaded scripts after update (#282)
Browse files Browse the repository at this point in the history
* Compare last modified time of script to model to refresh scripts on remote workers

* Use get_modified_time instead of modified_time in file storage backend

* Add tests for script updating

* Ignore windows test error
  • Loading branch information
Chris7 committed Jun 10, 2019
1 parent e9e9dfd commit 00530b6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 10 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
boto
celery==4.2.1
celery==4.3.0
clinto>=0.3.0
coveralls
django
django-autoslug
django-celery-results
django-celery-results==1.1.2
django-storages-redux
jsonfield
factory-boy
Expand Down
9 changes: 7 additions & 2 deletions wooey/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ def submit_script(**kwargs):
# make sure we have the script, otherwise download it. This can happen if we have an ephemeral file system or are
# executing jobs on a worker node.
script_path = job.script_version.script_path
if not utils.get_storage(local=True).exists(script_path.path):
utils.get_storage(local=True).save(script_path.path, script_path.file)
script_update_time = job.script_version.modified_date
local_storage = utils.get_storage(local=True)
script_exists = local_storage.exists(script_path.name)
if not script_exists or (local_storage.get_modified_time(script_path.name) < script_update_time):
if script_exists:
local_storage.delete(script_path.name)
local_storage.save(script_path.name, script_path.file)

job.status = WooeyJob.RUNNING
job.save()
Expand Down
17 changes: 11 additions & 6 deletions wooey/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@ def tearDown(self):
class ScriptFactoryMixin(object):
def tearDown(self):
for i in ScriptVersion.objects.all():
path = i.script_path.name
# import pdb; pdb.set_trace();
utils.get_storage().delete(path)
name = i.script_path.name
utils.get_storage().delete(name)
if wooey_settings.WOOEY_EPHEMERAL_FILES:
utils.get_storage(local=False).delete(path)
path += 'c' # handle pyc junk
utils.get_storage().delete(path)
try:
utils.get_storage(local=False).delete(name)
except WindowsError:
print('unable to delete {}'.format(name))
name += 'c' # handle pyc junk
try:
utils.get_storage().delete(name)
except WindowsError:
print('unable to delete {}'.format(name))
super(ScriptFactoryMixin, self).tearDown()

def setUp(self):
Expand Down
32 changes: 32 additions & 0 deletions wooey/tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mock
import os

from django.test import TestCase
Expand Down Expand Up @@ -119,3 +120,34 @@ def test_script_parameter_upgrade(self):
self.assertListEqual(old_parameters[1:], new_parameters[1:])
self.assertTrue(new_parameters[0].short_param, '--one-choice-added')
self.assertTrue(old_parameters[0].short_param, '--one-choice')

def test_redownloads_on_script_update(self):
# Run the translate script, update it, and ensure the new version is downloaded
sequence_slug = test_utils.get_subparser_form_slug(self.translate_script, 'sequence')
job = utils.create_wooey_job(script_version_pk=self.translate_script.pk, data={'job_name': 'job1', sequence_slug: 'ATG'})
job = job.submit_to_celery()

# The file has been downloaded locally, update the script and ensure the new one is used
script_path2 = os.path.join(config.WOOEY_TEST_SCRIPTS, 'translate2.py')
with open(script_path2) as o:
new_script = self.storage.save(self.filename_func('translate2.py'), o)
self.translate_script.script_path = new_script
self.translate_script.save()

job = utils.create_wooey_job(script_version_pk=self.translate_script.pk,
data={'job_name': 'job1', sequence_slug: 'ATC'})
with mock.patch('wooey.backend.utils.default_storage.local_storage.save') as storage_save:
job.submit_to_celery()
storage_save.assert_called()

def test_reuses_script_if_not_updated(self):
sequence_slug = test_utils.get_subparser_form_slug(self.translate_script, 'sequence')
job = utils.create_wooey_job(script_version_pk=self.translate_script.pk,
data={'job_name': 'job1', sequence_slug: 'ATG'})
job.submit_to_celery()

job = utils.create_wooey_job(script_version_pk=self.translate_script.pk,
data={'job_name': 'job2', sequence_slug: 'ATC'})
with mock.patch('wooey.backend.utils.default_storage.local_storage.save') as storage_save:
job.submit_to_celery()
storage_save.assert_not_called()

0 comments on commit 00530b6

Please sign in to comment.