| @@ 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 |
|
| @@ 147-191 (lines=45) @@ | ||
| 144 | return 'success' |
|
| 145 | ||
| 146 | ||
| 147 | class BatchUpdateAnimals(MyTask, BatchUpdateMixin): |
|
| 148 | name = "Batch update animals" |
|
| 149 | description = """Batch update of field in animals""" |
|
| 150 | ||
| 151 | item_cls = Animal |
|
| 152 | submission_cls = Submission |
|
| 153 | ||
| 154 | # Ovverride default on failure method |
|
| 155 | # This is not a failed validation for a wrong value, this is an |
|
| 156 | # error in task that mean an error in coding |
|
| 157 | def on_failure(self, exc, task_id, args, kwargs, einfo): |
|
| 158 | logger.error('{0!r} failed: {1!r}'.format(task_id, exc)) |
|
| 159 | ||
| 160 | # get submission object |
|
| 161 | submission_obj = Submission.objects.get(pk=args[0]) |
|
| 162 | ||
| 163 | # mark submission with ERROR |
|
| 164 | submission_obj.status = ERROR |
|
| 165 | submission_obj.message = ("Error in batch update for animals: %s" |
|
| 166 | % (str(exc))) |
|
| 167 | submission_obj.save() |
|
| 168 | ||
| 169 | send_message(submission_obj) |
|
| 170 | ||
| 171 | # send a mail to the user with the stacktrace (einfo) |
|
| 172 | submission_obj.owner.email_user( |
|
| 173 | "Error in batch update for animals: %s" % (args[0]), |
|
| 174 | ("Something goes wrong in batch update for animals. Please " |
|
| 175 | "report this to InjectTool team\n\n %s" % str(einfo)), |
|
| 176 | ) |
|
| 177 | ||
| 178 | # TODO: submit mail to admin |
|
| 179 | ||
| 180 | def run(self, submission_id, animal_ids, attribute): |
|
| 181 | """Function for batch update attribute in animals |
|
| 182 | Args: |
|
| 183 | submission_id (int): id of submission |
|
| 184 | animal_ids (dict): dict with id and values to update |
|
| 185 | attribute (str): attribute to update |
|
| 186 | """ |
|
| 187 | ||
| 188 | logger.info("Start batch update for animals") |
|
| 189 | super(BatchUpdateAnimals, self).batch_update(submission_id, animal_ids, |
|
| 190 | attribute) |
|
| 191 | return 'success' |
|
| 192 | ||
| 193 | ||
| 194 | # register explicitly tasks |
|