|
4 | 4 | # This source code is licensed under the MIT license found in the |
5 | 5 | # LICENSE file in the root directory of this source tree. |
6 | 6 |
|
7 | | -from mephisto.data_model.worker import Worker |
8 | | -from mephisto.data_model.requester import Requester |
9 | | -from mephisto.abstractions.providers.mturk.provider_type import PROVIDER_TYPE |
10 | | -from mephisto.abstractions.providers.mturk.mturk_utils import ( |
11 | | - pay_bonus, |
12 | | - block_worker, |
13 | | - unblock_worker, |
14 | | - is_worker_blocked, |
15 | | - give_worker_qualification, |
16 | | - remove_worker_qualification, |
17 | | -) |
18 | | -from mephisto.abstractions.providers.mturk.mturk_requester import MTurkRequester |
19 | | - |
| 7 | +from typing import Any |
| 8 | +from typing import cast |
| 9 | +from typing import Mapping |
| 10 | +from typing import Optional |
| 11 | +from typing import Tuple |
| 12 | +from typing import TYPE_CHECKING |
20 | 13 | from uuid import uuid4 |
21 | 14 |
|
22 | | -from typing import List, Optional, Tuple, Dict, Mapping, Any, cast, TYPE_CHECKING |
| 15 | +from mephisto.abstractions.providers.mturk.mturk_utils import block_worker |
| 16 | +from mephisto.abstractions.providers.mturk.mturk_utils import email_worker |
| 17 | +from mephisto.abstractions.providers.mturk.mturk_utils import give_worker_qualification |
| 18 | +from mephisto.abstractions.providers.mturk.mturk_utils import is_worker_blocked |
| 19 | +from mephisto.abstractions.providers.mturk.mturk_utils import pay_bonus |
| 20 | +from mephisto.abstractions.providers.mturk.mturk_utils import remove_worker_qualification |
| 21 | +from mephisto.abstractions.providers.mturk.mturk_utils import unblock_worker |
| 22 | +from mephisto.abstractions.providers.mturk.provider_type import PROVIDER_TYPE |
| 23 | +from mephisto.data_model.requester import Requester |
| 24 | +from mephisto.data_model.worker import Worker |
| 25 | +from mephisto.utils.logger_core import get_logger |
23 | 26 |
|
24 | 27 | if TYPE_CHECKING: |
25 | 28 | from mephisto.abstractions.providers.mturk.mturk_datastore import MTurkDatastore |
26 | 29 | from mephisto.abstractions.database import MephistoDB |
27 | 30 | from mephisto.data_model.task_run import TaskRun |
28 | 31 | from mephisto.data_model.unit import Unit |
29 | | - from mephisto.abstractions.providers.mturk.mturk_unit import MTurkUnit |
30 | 32 | from mephisto.abstractions.providers.mturk.mturk_requester import MTurkRequester |
31 | 33 |
|
32 | | -from mephisto.utils.logger_core import get_logger |
33 | 34 |
|
34 | 35 | logger = get_logger(name=__name__) |
35 | 36 |
|
@@ -179,6 +180,27 @@ def is_eligible(self, task_run: "TaskRun") -> bool: |
179 | 180 | """ |
180 | 181 | return True |
181 | 182 |
|
| 183 | + def send_feedback_message(self, text: str, unit: "Unit") -> bool: |
| 184 | + """Send feedback message to a worker""" |
| 185 | + requester = cast( |
| 186 | + "MTurkRequester", |
| 187 | + self.db.find_requesters(provider_type=self.provider_type)[-1], |
| 188 | + ) |
| 189 | + |
| 190 | + assert isinstance(requester, MTurkRequester), "Must be an MTurk requester" |
| 191 | + |
| 192 | + client = self._get_client(requester._requester_name) |
| 193 | + task_name = unit.get_task_run().get_task().task_name |
| 194 | + |
| 195 | + email_worker( |
| 196 | + client=client, |
| 197 | + worker_id=self.get_mturk_worker_id(), |
| 198 | + subject=f'Feedback for your Mturk task "{task_name}"', |
| 199 | + message_text=text, |
| 200 | + ) |
| 201 | + |
| 202 | + return True |
| 203 | + |
182 | 204 | @staticmethod |
183 | 205 | def new(db: "MephistoDB", worker_id: str) -> "Worker": |
184 | 206 | return MTurkWorker._register_worker(db, worker_id, PROVIDER_TYPE) |
0 commit comments