(options: {
readonly name: string
readonly success?: Success | undefined
readonly error?: Error | undefined
readonly execute: Effect.Effect<Success["Type"], Error["Type"], R>
readonly interruptRetryPolicy?: Schedule.Schedule<any, Cause.Cause<unknown>> | undefined
readonly annotations?: Context.Context<never> | undefined
})
| 121 | * @since 4.0.0 |
| 122 | */ |
| 123 | export const make = < |
| 124 | R, |
| 125 | Success extends Schema.Constraint = Schema.Void, |
| 126 | Error extends Schema.Constraint = Schema.Never |
| 127 | >(options: { |
| 128 | readonly name: string |
| 129 | readonly success?: Success | undefined |
| 130 | readonly error?: Error | undefined |
| 131 | readonly execute: Effect.Effect<Success["Type"], Error["Type"], R> |
| 132 | readonly interruptRetryPolicy?: Schedule.Schedule<any, Cause.Cause<unknown>> | undefined |
| 133 | readonly annotations?: Context.Context<never> | undefined |
| 134 | }): Activity<Success, Error, Exclude<R, WorkflowInstance | WorkflowEngine | Scope>> => { |
| 135 | const successSchema = options.success ?? (Schema.Void as any as Success) |
| 136 | const errorSchema = options.error ?? (Schema.Never as any as Error) |
| 137 | const successSchemaJson = Schema.toCodecJson(successSchema) |
| 138 | const errorSchemaJson = Schema.toCodecJson(errorSchema) |
| 139 | // oxlint-disable-next-line prefer-const |
| 140 | let execute!: Effect.Effect<Success["Type"], Error["Type"], any> |
| 141 | const executeWithoutInterrupt = retryOnInterrupt( |
| 142 | options.name, |
| 143 | options.interruptRetryPolicy |
| 144 | )(options.execute) |
| 145 | const self: Activity<Success, Error, Exclude<R, WorkflowInstance | WorkflowEngine>> = { |
| 146 | ...Effectable.Prototype<Activity<Success, Error, R>>({ |
| 147 | label: "Activity", |
| 148 | evaluate(_) { |
| 149 | return execute |
| 150 | } |
| 151 | }), |
| 152 | [TypeId]: TypeId, |
| 153 | name: options.name, |
| 154 | successSchema, |
| 155 | errorSchema, |
| 156 | exitSchema: Schema.Exit(successSchemaJson, errorSchemaJson, Schema.Defect()), |
| 157 | exitSchemaPartial: Schema.Exit(successSchemaJson, errorSchemaJson, Schema.Unknown), |
| 158 | annotations: options.annotations ?? Context.empty(), |
| 159 | annotate(tag: Context.Key<any, any>, value: any) { |
| 160 | return make({ |
| 161 | ...options, |
| 162 | annotations: Context.add(self.annotations, tag, value) |
| 163 | }) |
| 164 | }, |
| 165 | annotateMerge(context: Context.Context<any>) { |
| 166 | return make({ |
| 167 | ...options, |
| 168 | annotations: Context.merge(self.annotations, context) |
| 169 | }) |
| 170 | }, |
| 171 | execute: executeWithoutInterrupt, |
| 172 | executeEncoded: Effect.matchEffect(executeWithoutInterrupt, { |
| 173 | onFailure: (error) => Effect.flatMap(Effect.orDie(Schema.encodeEffect(errorSchemaJson)(error)), Effect.fail), |
| 174 | onSuccess: (value) => Effect.orDie(Schema.encodeEffect(successSchemaJson)(value)) |
| 175 | }) |
| 176 | } as any |
| 177 | execute = makeExecute(self) |
| 178 | return self |
| 179 | } |
| 180 |
no test coverage detected