Repository: facebookresearch/Mephisto

Issue:
[Feature Request] Set task expires time 
How can I set the task expiration time to one week? Currently, tasks will be expired in one month. It's too long.


Discussion:
Hi @WilliamsToTo. Right now this value is hard-coded:
https://github.com/facebookresearch/Mephisto/blob/e26722f230198a6b2d8251cc3ca08b6148160aef/mephisto/abstractions/providers/mturk/mturk_utils.py#L554

I'd be happy to accept a PR that turns it into an argument for `create_hit_with_hit_type`, then retrieves it from the `task_args` in the same way we pull duration:
https://github.com/facebookresearch/Mephisto/blob/e26722f230198a6b2d8251cc3ca08b6148160aef/mephisto/abstractions/providers/mturk/mturk_unit.py#L277

This can be added as an argument to `TaskRunArgs` in the same way the duration one is set here:
https://github.com/facebookresearch/Mephisto/blob/e26722f230198a6b2d8251cc3ca08b6148160aef/mephisto/data_model/task_run.py#L77
I can help with that! Will be happy to work on it.

Resolving patch:
diff --git a/mephisto/abstractions/providers/mturk/mturk_unit.py b/mephisto/abstractions/providers/mturk/mturk_unit.py
--- a/mephisto/abstractions/providers/mturk/mturk_unit.py
+++ b/mephisto/abstractions/providers/mturk/mturk_unit.py
@@ -272,9 +272,14 @@ def get_status(self) -> str:
         return self.db_status
 
     def launch(self, task_url: str) -> None:
-        """Create this HIT on MTurk (making it availalbe) and register the ids in the local db"""
+        """Create this HIT on MTurk (making it available) and register the ids in the local db"""
         task_run = self.get_assignment().get_task_run()
         duration = task_run.get_task_args().assignment_duration_in_seconds
+        task_lifetime_in_seconds = (
+            task_run.get_task_args().task_lifetime_in_seconds
+            if task_run.get_task_args().task_lifetime_in_seconds
+            else 60 * 60 * 24 * 31
+        )
         run_id = task_run.db_id
         run_details = self.datastore.get_run(run_id)
         hit_type_id = run_details["hit_type_id"]
@@ -282,7 +287,11 @@ def launch(self, task_url: str) -> None:
         client = self._get_client(requester._requester_name)
         frame_height = run_details["frame_height"]
         hit_link, hit_id, response = create_hit_with_hit_type(
-            client, frame_height, task_url, hit_type_id
+            client,
+            frame_height,
+            task_url,
+            hit_type_id,
+            lifetime_in_seconds=task_lifetime_in_seconds,
         )
         # TODO(OWN) get this link to the mephisto frontend
         print(hit_link)
diff --git a/mephisto/abstractions/providers/mturk/mturk_utils.py b/mephisto/abstractions/providers/mturk/mturk_utils.py
--- a/mephisto/abstractions/providers/mturk/mturk_utils.py
+++ b/mephisto/abstractions/providers/mturk/mturk_utils.py
@@ -505,7 +505,7 @@ def create_compensation_hit_with_hit_type(
 
     is_sandbox = client_is_sandbox(client)
 
-    # Create the HIT
+    # Creates a compensation HIT to be completed in the next month
     response = client.create_hit_with_hit_type(
         HITTypeId=hit_type_id,
         MaxAssignments=num_assignments,
@@ -533,6 +533,7 @@ def create_hit_with_hit_type(
     page_url: str,
     hit_type_id: str,
     num_assignments: int = 1,
+    lifetime_in_seconds: int = 60 * 60 * 24 * 31,
 ) -> Tuple[str, str, Dict[str, Any]]:
     """Creates the actual HIT given the type and page to direct clients to"""
     page_url = page_url.replace("&", "&amp;")
@@ -554,7 +555,7 @@ def create_hit_with_hit_type(
     response = client.create_hit_with_hit_type(
         HITTypeId=hit_type_id,
         MaxAssignments=num_assignments,
-        LifetimeInSeconds=60 * 60 * 24 * 31,
+        LifetimeInSeconds=lifetime_in_seconds,
         Question=question_data_structure,
     )
 
diff --git a/mephisto/data_model/task_run.py b/mephisto/data_model/task_run.py
--- a/mephisto/data_model/task_run.py
+++ b/mephisto/data_model/task_run.py
@@ -74,6 +74,10 @@ class TaskRunArgs:
             "required": True,
         },
     )
+    task_lifetime_in_seconds: int = field(
+        default=60 * 60 * 24 * 31,
+        metadata={"help": "The time that the task will last for before expiring"},
+    )
     assignment_duration_in_seconds: int = field(
         default=30 * 60,
         metadata={"help": "Time that workers have to work on your task once accepted."},


Test patch: