functions-api.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*! firebase-admin v12.1.1 */
  2. /*!
  3. * @license
  4. * Copyright 2021 Google Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * Interface representing task options with delayed delivery.
  20. */
  21. export interface DelayDelivery {
  22. /**
  23. * The duration of delay of the time when the task is scheduled to be attempted or retried.
  24. * This delay is added to the current time.
  25. */
  26. scheduleDelaySeconds?: number;
  27. /** @alpha */
  28. scheduleTime?: never;
  29. }
  30. /**
  31. * Interface representing task options with absolute delivery.
  32. */
  33. export interface AbsoluteDelivery {
  34. /**
  35. * The time when the task is scheduled to be attempted or retried.
  36. */
  37. scheduleTime?: Date;
  38. /** @alpha */
  39. scheduleDelaySeconds?: never;
  40. }
  41. /**
  42. * Type representing delivery schedule options.
  43. * `DeliverySchedule` is a union type of {@link DelayDelivery} and {@link AbsoluteDelivery} types.
  44. */
  45. export type DeliverySchedule = DelayDelivery | AbsoluteDelivery;
  46. /**
  47. * Type representing task options.
  48. */
  49. export type TaskOptions = DeliverySchedule & TaskOptionsExperimental & {
  50. /**
  51. * The deadline for requests sent to the worker. If the worker does not respond by this deadline
  52. * then the request is cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure.
  53. * Cloud Tasks will retry the task according to the `RetryConfig`.
  54. * The default is 10 minutes. The deadline must be in the range of 15 seconds and 30 minutes.
  55. */
  56. dispatchDeadlineSeconds?: number;
  57. /**
  58. * The ID to use for the enqueued event.
  59. * If not provided, one will be automatically generated.
  60. * If provided, an explicitly specified task ID enables task de-duplication. If a task's ID is
  61. * identical to that of an existing task or a task that was deleted or executed recently then
  62. * the call will throw an error with code "functions/task-already-exists". Another task with
  63. * the same ID can't be created for ~1hour after the original task was deleted or executed.
  64. *
  65. * Because there is an extra lookup cost to identify duplicate task IDs, setting ID
  66. * significantly increases latency. Using hashed strings for the task ID or for the prefix of
  67. * the task ID is recommended. Choosing task IDs that are sequential or have sequential
  68. * prefixes, for example using a timestamp, causes an increase in latency and error rates in
  69. * all task commands. The infrastructure relies on an approximately uniform distribution of
  70. * task IDs to store and serve tasks efficiently.
  71. *
  72. * "Push IDs" from the Firebase Realtime Database make poor IDs because they are based on
  73. * timestamps and will cause contention (slowdowns) in your task queue. Reversed push IDs
  74. * however form a perfect distribution and are an ideal key. To reverse a string in
  75. * javascript use `someString.split("").reverse().join("")`
  76. */
  77. id?: string;
  78. /**
  79. * HTTP request headers to include in the request to the task queue function.
  80. * These headers represent a subset of the headers that will accompany the task's HTTP
  81. * request. Some HTTP request headers will be ignored or replaced, e.g. Authorization, Host, Content-Length,
  82. * User-Agent etc. cannot be overridden.
  83. *
  84. * By default, Content-Type is set to 'application/json'.
  85. *
  86. * The size of the headers must be less than 80KB.
  87. */
  88. headers?: Record<string, string>;
  89. };
  90. /**
  91. * Type representing experimental (beta) task options.
  92. */
  93. export interface TaskOptionsExperimental {
  94. /**
  95. * The full URL path that the request will be sent to. Must be a valid URL.
  96. * @beta
  97. */
  98. uri?: string;
  99. }