-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
JobDefinition.swift
30 lines (27 loc) · 1.11 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
//===----------------------------------------------------------------------===//
//
// 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 HBJobDefinition<Parameters: Codable & Sendable>: Sendable {
public let id: HBJobIdentifier<Parameters>
let maxRetryCount: Int
let _execute: @Sendable (Parameters, HBJobContext) async throws -> Void
public init(id: HBJobIdentifier<Parameters>, maxRetryCount: Int = 0, execute: @escaping @Sendable (Parameters, HBJobContext) async throws -> Void) {
self.id = id
self.maxRetryCount = maxRetryCount
self._execute = execute
}
func execute(_ parameters: Parameters, context: HBJobContext) async throws {
try await self._execute(parameters, context)
}
}