| @@ 136-180 (lines=45) @@ | ||
| 133 | return 'success' |
|
| 134 | ||
| 135 | ||
| 136 | class BatchUpdateAnimals(MyTask, BatchUpdateMixin): |
|
| 137 | name = "Batch update animals" |
|
| 138 | description = """Batch update of field in animals""" |
|
| 139 | ||
| 140 | item_cls = Animal |
|
| 141 | submission_cls = Submission |
|
| 142 | ||
| 143 | # Ovverride default on failure method |
|
| 144 | # This is not a failed validation for a wrong value, this is an |
|
| 145 | # error in task that mean an error in coding |
|
| 146 | def on_failure(self, exc, task_id, args, kwargs, einfo): |
|
| 147 | logger.error('{0!r} failed: {1!r}'.format(task_id, exc)) |
|
| 148 | ||
| 149 | # get submission object |
|
| 150 | submission_obj = Submission.objects.get(pk=args[0]) |
|
| 151 | ||
| 152 | # mark submission with ERROR |
|
| 153 | submission_obj.status = ERROR |
|
| 154 | submission_obj.message = ("Error in batch update for animals: %s" |
|
| 155 | % (str(exc))) |
|
| 156 | submission_obj.save() |
|
| 157 | ||
| 158 | send_message(submission_obj) |
|
| 159 | ||
| 160 | # send a mail to the user with the stacktrace (einfo) |
|
| 161 | submission_obj.owner.email_user( |
|
| 162 | "Error in batch update for animals: %s" % (args[0]), |
|
| 163 | ("Something goes wrong in batch update for animals. Please report " |
|
| 164 | "this to InjectTool team\n\n %s" % str(einfo)), |
|
| 165 | ) |
|
| 166 | ||
| 167 | # TODO: submit mail to admin |
|
| 168 | ||
| 169 | def run(self, submission_id, animal_ids, attribute): |
|
| 170 | """Function for batch update attribute in animals |
|
| 171 | Args: |
|
| 172 | submission_id (int): id of submission |
|
| 173 | animal_ids (dict): dict with id and values to update |
|
| 174 | attribute (str): attribute to update |
|
| 175 | """ |
|
| 176 | ||
| 177 | logger.info("Start batch update for animals") |
|
| 178 | super(BatchUpdateAnimals, self).batch_update(submission_id, animal_ids, |
|
| 179 | attribute) |
|
| 180 | return 'success' |
|
| 181 | ||
| 182 | ||
| 183 | # register explicitly tasks |
|
| @@ 122-166 (lines=45) @@ | ||
| 119 | return 'success' |
|
| 120 | ||
| 121 | ||
| 122 | class BatchUpdateSamples(MyTask, BatchUpdateMixin): |
|
| 123 | name = "Batch update samples" |
|
| 124 | description = """Batch update of field in samples""" |
|
| 125 | ||
| 126 | item_cls = Sample |
|
| 127 | submission_cls = Submission |
|
| 128 | ||
| 129 | # Ovverride default on failure method |
|
| 130 | # This is not a failed validation for a wrong value, this is an |
|
| 131 | # error in task that mean an error in coding |
|
| 132 | def on_failure(self, exc, task_id, args, kwargs, einfo): |
|
| 133 | logger.error('{0!r} failed: {1!r}'.format(task_id, exc)) |
|
| 134 | ||
| 135 | # get submission object |
|
| 136 | submission_obj = Submission.objects.get(pk=args[0]) |
|
| 137 | ||
| 138 | # mark submission with ERROR |
|
| 139 | submission_obj.status = ERROR |
|
| 140 | submission_obj.message = ("Error in batch update for samples: %s" |
|
| 141 | % (str(exc))) |
|
| 142 | submission_obj.save() |
|
| 143 | ||
| 144 | send_message(submission_obj) |
|
| 145 | ||
| 146 | # send a mail to the user with the stacktrace (einfo) |
|
| 147 | submission_obj.owner.email_user( |
|
| 148 | "Error in batch update for samples: %s" % (args[0]), |
|
| 149 | ("Something goes wrong in batch update for samples. Please report " |
|
| 150 | "this to InjectTool team\n\n %s" % str(einfo)), |
|
| 151 | ) |
|
| 152 | ||
| 153 | # TODO: submit mail to admin |
|
| 154 | ||
| 155 | def run(self, submission_id, sample_ids, attribute): |
|
| 156 | """Function for batch update attribute in samples |
|
| 157 | Args: |
|
| 158 | submission_id (int): id of submission |
|
| 159 | sample_ids (dict): dict with id and values to update |
|
| 160 | attribute (str): attribute to update |
|
| 161 | """ |
|
| 162 | ||
| 163 | logger.info("Start batch update for samples") |
|
| 164 | super(BatchUpdateSamples, self).batch_update(submission_id, sample_ids, |
|
| 165 | attribute) |
|
| 166 | return 'success' |
|
| 167 | ||
| 168 | ||
| 169 | # register explicitly tasks |
|