diff --git a/docs/web/docs/guides/tutorials/custom_react.md b/docs/web/docs/guides/tutorials/custom_react.md index cb6051f9d..9423eb7dd 100644 --- a/docs/web/docs/guides/tutorials/custom_react.md +++ b/docs/web/docs/guides/tutorials/custom_react.md @@ -36,15 +36,30 @@ mephisto: task_tags: "test,simple,button" ``` -The only change we'll make is to the `task_name` (as you should on any new tasks!), but we will update the other fields as we go. It's important to note the `task_source` and `extra_source_dir` arguments though, as this is where the `StaticReactBlueprint` class will be looking for the compiled React app's Javascript bundle as well as a folder for extra static resources for the page, respectively. +It is important to give a new `task_name` as we are creating a custom task. For local development **only** it also makes sense to set `link_task_source` to true. This allows changes to propagate to your localhost server when you reload the page (otherwise you would have to shutdown and restart the server to see changes). + +The `task_source` and `extra_source_dir` arguments are also of importance, as this is where the `StaticReactBlueprint` class will be looking for the compiled React app's Javascript bundle as well as a folder for extra static resources for the page, respectively. ### 1.2 Launching the task From the current directory, you should be able to execute the run script and get a job working. We're using a different `task_name` to prevent polluting our later task with data that won't share the same format. It is a good practice to do this with initial iterations, and to change the `task_name` any time you change input or output arguments. + +You can update the `task_name` and `link_task_source` values in your config and run the task like below ```bash -python run_task.py mephisto.task.task_name=custom-react-tutorial-iterating +python run_task.py +``` + +or you can set them when you run the task: + +```bash +python run_task.py mephisto.task.task_name=custom-react-tutorial-iterating mephisto.blueprint.link_task_source=true ``` This will launch a simple task where an annotator is supposed to note a sentence as being good or bad. Clicking a button auto-submits the task. In the next sections we'll add other content. +To establish a link where your changes will be propagated to the localhost server(when you reload), create a separate terminal window and run +```bash +cd webapp && npm run dev:watch +``` + Moving forward, we'll update this task so that workers are able to edit the text as well as rate the original sentence. ## 2. Providing new data to the task diff --git a/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py b/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py index 0f250e5d7..4f3373c02 100644 --- a/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py +++ b/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py @@ -22,6 +22,9 @@ from mephisto.abstractions.blueprint import ( SharedTaskState, ) +from mephisto.utils.logger_core import ( + get_logger, +) if TYPE_CHECKING: from mephisto.data_model.task_run import TaskRun @@ -31,6 +34,7 @@ from omegaconf import DictConfig BLUEPRINT_TYPE_STATIC_REACT = "static_react_task" +logger = get_logger(name=__name__) @dataclass @@ -120,3 +124,9 @@ def assert_task_args( assert link_task_source == False or ( link_task_source == True and current_architect in allowed_architects ), f"`link_task_source={link_task_source}` is not compatible with architect type: {args.architect._architect_type}. Please check your task configuration." + + if link_task_source == False and current_architect in allowed_architects: + logger.info( + "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: [blue]true[/blue]\n\nin your task's hydra configuration and run \n\n[purple]cd[/purple] webapp [red]&&[/red] [green]npm[/green] run dev:watch\n\nin a separate terminal window. For more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task\n", + extra={"markup": True}, + ) diff --git a/mephisto/operations/operator.py b/mephisto/operations/operator.py index 5da26be3d..e6fb60cb2 100644 --- a/mephisto/operations/operator.py +++ b/mephisto/operations/operator.py @@ -29,7 +29,6 @@ ) from mephisto.abstractions.database import MephistoDB, EntryDoesNotExistException from mephisto.data_model.qualification import QUAL_NOT_EXIST -from mephisto.tools.data_browser import DataBrowser as MephistoDataBrowser from mephisto.utils.qualifications import make_qualification_dict from mephisto.operations.task_launcher import TaskLauncher from mephisto.operations.client_io_handler import ClientIOHandler @@ -56,7 +55,7 @@ logger = get_logger(name=__name__) if TYPE_CHECKING: - from mephisto.abstractions.blueprint import Blueprint, TaskRunner + from mephisto.abstractions.blueprint import Blueprint from mephisto.abstractions.crowd_provider import CrowdProvider from mephisto.abstractions.architect import Architect @@ -313,7 +312,7 @@ def launch_task_run_or_die( raise e live_run.task_launcher.create_assignments() - live_run.task_launcher.launch_units(task_url) + live_run.task_launcher.launch_units(url=task_url) self._task_runs_tracked[task_run.db_id] = live_run task_run.update_completion_progress(status=False) diff --git a/mephisto/operations/task_launcher.py b/mephisto/operations/task_launcher.py index b5483ba2e..178ca39ff 100644 --- a/mephisto/operations/task_launcher.py +++ b/mephisto/operations/task_launcher.py @@ -26,7 +26,6 @@ if TYPE_CHECKING: from mephisto.data_model.task_run import TaskRun from mephisto.abstractions.database import MephistoDB - import threading from mephisto.utils.logger_core import get_logger import types @@ -199,7 +198,9 @@ def launch_units(self, url: str) -> None: """launch any units registered by this TaskLauncher""" self.launch_url = url self.units_thread = threading.Thread( - target=self._launch_limited_units, args=(url,), name="unit-generator" + target=self._launch_limited_units, + args=(url,), + name="unit-generator", ) self.units_thread.start()