| Conditions | 5 |
| Total Lines | 72 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | #!/usr/bin/env python3 |
||
| 47 | class ImportCryowebTask(ImportGenericTaskMixin, ExclusiveTask): |
||
| 48 | """ |
||
| 49 | An exclusive task wich upload a *data-only* cryoweb dump in cryoweb |
||
| 50 | database and then fill up :ref:`UID <The Unified Internal Database>` |
||
| 51 | tables. After data import (wich could be successful or not) cryoweb |
||
| 52 | helper database is cleanded and restored in the original status:: |
||
| 53 | |||
| 54 | from cryoweb.tasks import ImportCryowebTask |
||
| 55 | |||
| 56 | # call task asynchronously |
||
| 57 | task = ImportCryowebTask() |
||
| 58 | res = task.delay(submission_id) |
||
| 59 | |||
| 60 | Args: |
||
| 61 | submission_id (int): the submission primary key |
||
| 62 | |||
| 63 | Returns: |
||
| 64 | str: a message string (ex. success) |
||
| 65 | """ |
||
| 66 | |||
| 67 | name = "Import Cryoweb" |
||
| 68 | description = """Import Cryoweb data from Cryoweb dump""" |
||
| 69 | action = "cryoweb import" |
||
| 70 | |||
| 71 | # ExclusiveTask attributes |
||
| 72 | lock_id = 'ImportFromCryoWeb' |
||
| 73 | blocking = True |
||
| 74 | |||
| 75 | # decorate function in order to cleanup cryoweb database after data import |
||
| 76 | @clean_cryoweb_database |
||
| 77 | def import_data_from_file(self, submission_obj): |
||
| 78 | """Call the custom import method""" |
||
| 79 | |||
| 80 | # upload data into cryoweb database |
||
| 81 | status = upload_cryoweb(submission_obj.id) |
||
| 82 | |||
| 83 | # if something went wrong, uploaded_cryoweb has token the exception |
||
| 84 | # ad update submission.message field |
||
| 85 | if status is False: |
||
| 86 | return status |
||
| 87 | |||
| 88 | # load cryoweb data into UID |
||
| 89 | # check status |
||
| 90 | status = cryoweb_import(submission_obj) |
||
| 91 | |||
| 92 | return status |
||
| 93 | |||
| 94 | |||
| 95 | # register explicitly tasks |
||
| 96 | # https://github.com/celery/celery/issues/3744#issuecomment-271366923 |
||
| 97 | celery_app.tasks.register(ImportCryowebTask) |
||
| 98 |