-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
JobDefinition.swift
35 lines (32 loc) · 1.3 KB
/
JobDefinition.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//===----------------------------------------------------------------------===//
//
// This source file is part of the Hummingbird server framework project
//
// Copyright (c) 2024 the Hummingbird authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// Job definition type
public struct JobDefinition<Parameters: Codable & Sendable>: Sendable {
public let id: JobIdentifier<Parameters>
let maxRetryCount: Int
let _execute: @Sendable (Parameters, JobContext) async throws -> Void
/// Initialize JobDefinition
/// - Parameters:
/// - id: Job identifier
/// - maxRetryCount: Maxiumum times this job will be retried if it fails
/// - execute: Closure that executes job
public init(id: JobIdentifier<Parameters>, maxRetryCount: Int = 0, execute: @escaping @Sendable (Parameters, JobContext) async throws -> Void) {
self.id = id
self.maxRetryCount = maxRetryCount
self._execute = execute
}
func execute(_ parameters: Parameters, context: JobContext) async throws {
try await self._execute(parameters, context)
}
}