createScheduledTask method

Future<String> createScheduledTask({
  1. required String projectId,
  2. required String roomName,
  3. required String queueName,
  4. required dynamic payload,
  5. required String schedule,
  6. bool active = true,
  7. bool once = false,
  8. String? taskId,
  9. Map<String, String> annotations = const {},
})

POST /accounts/projects/{project_id}/scheduled-tasks Returns { "task_id" }

Implementation

Future<String> createScheduledTask({
  required String projectId,
  required String roomName,
  required String queueName,
  required dynamic payload,
  required String schedule,
  bool active = true,
  bool once = false,
  String? taskId,
  Map<String, String> annotations = const {},
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/scheduled-tasks');
  final body = _CreateScheduledTaskRequest(
    id: taskId,
    roomName: roomName,
    queueName: queueName,
    payload: payload,
    schedule: schedule,
    active: active,
    once: once,
    annotations: annotations,
  ).toJson();
  final resp = await httpClient.post(uri, body: jsonEncode(body));

  if (resp.statusCode >= 400) {
    // mirror your python client’s "ensure_success" style
    throw MeshagentException('Failed to create scheduled task. Status code: ${resp.statusCode}, body: ${resp.body}');
  }

  final data = jsonDecode(resp.body) as Map<String, dynamic>;
  final tid = data['task_id'];

  if (tid is! String) {
    throw MeshagentException('Invalid create scheduled task response: missing "task_id"');
  }

  return tid;
}