Skip to content

Commit

Permalink
Merge pull request #810 from facebookresearch/add-custom-task-expirat…
Browse files Browse the repository at this point in the history
…ion-time

Adds ability to set custom task lifetime
  • Loading branch information
Etesam913 committed Jul 5, 2022
2 parents 207cfd7 + 6cc7eaf commit c776529
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions mephisto/abstractions/providers/mturk/mturk_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,26 @@ 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"]
requester = self.get_requester()
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)
Expand Down
5 changes: 3 additions & 2 deletions mephisto/abstractions/providers/mturk/mturk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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("&", "&")
Expand All @@ -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,
)

Expand Down
4 changes: 4 additions & 0 deletions mephisto/data_model/task_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand Down

0 comments on commit c776529

Please sign in to comment.