Skip to content

Commit

Permalink
refector Timer to TimerTrigger to avoid conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
SalehAlbuga committed Nov 23, 2019
1 parent 5220f9e commit c29a758
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 1,030 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Azure Functions for Swift

A description of this package.
2 changes: 1 addition & 1 deletion Sources/AzureFunctions/AzureFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class Function {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

open func exec(timer: Timer, context: inout Context, callback: @escaping callback) throws {
open func exec(timer: TimerTrigger, context: inout Context, callback: @escaping callback) throws {
throw FunctionError.FunctionTypeNotImplementedException("Please override the right exec function for your trigger")
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/AzureFunctions/Bindings/BindingFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ internal final class BindingFactory {
} else {
throw FunctionError.internalInconsistancyException("Expected http binding type, got \(rpcBinding.type). Please make sure function.json matches the function definition.")
}
case let timer as Timer:
if rpcBinding.type == Timer.triggerTypeKey {
case let timer as TimerTrigger:
if rpcBinding.type == TimerTrigger.triggerTypeKey {
let json = try RpcConverter.fromTypedData(data: binding.data) as! [String:Any]
let t = Timer()
let t = TimerTrigger()
t.userInfo = json
t.name = timer.name
t.schedule = timer.schedule
Expand Down
25 changes: 14 additions & 11 deletions Sources/AzureFunctions/Bindings/Timer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import Foundation

public final class Timer : Binding {


public final class TimerTrigger : Binding {

public var name: String = ""

Expand All @@ -20,15 +18,20 @@ public final class Timer : Binding {

var userInfo: [String:Any] = [:]

init () {
internal init () {

}

public static func initTrigger (name: String, schedule: String) -> Timer {
let timer = Timer()
timer.schedule = schedule
timer.name = name
return timer
public init(name: String, schedule: String) {
self.schedule = schedule
self.name = name
}

public init(name: String, schedule: String, runOnStartup: Bool, useMonitor: Bool) {
self.schedule = schedule
self.name = name
self.runOnStartup = runOnStartup
self.useMonitor = useMonitor
}

struct Keys {
Expand All @@ -39,7 +42,7 @@ public final class Timer : Binding {

}

extension Timer: BindingCapability {
extension TimerTrigger: BindingCapability {


var isInput: Bool {
Expand All @@ -61,7 +64,7 @@ extension Timer: BindingCapability {
func jsonDescription(direction: BindingDirection) throws -> [String: Any] {

var props: [String: Any] = [
Definitions.Bindings.Keys.TypeKey: Timer.triggerTypeKey,
Definitions.Bindings.Keys.TypeKey: TimerTrigger.triggerTypeKey,
Definitions.Bindings.Keys.Name: name,
Definitions.Bindings.Keys.Direction: Definitions.Bindings.DirectionIn,
Keys.Schedule: schedule
Expand Down
2 changes: 1 addition & 1 deletion Sources/AzureFunctions/Broker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class Broker {
case let http as HttpRequest:
try function.exec(request: http, context: &context, callback: callback)
break
case let timer as Timer:
case let timer as TimerTrigger:
try function.exec(timer: timer, context: &context, callback: callback)
break
case let blob as Blob:
Expand Down
114 changes: 21 additions & 93 deletions Sources/AzureFunctions/Templates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@ internal struct Templates {
struct ProjectFiles {

static let functionJson = """
{{ bindings }}
{{ bindings }}
"""

static let hostJsonDebug = """
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
"""

static let hostJson = """
{
"version": "2.0"
}
{
"version": "2.0"
}
"""

static let workerConfigJson = """
{
"description": {
"arguments": [
"run"
],
"defaultExecutablePath": "{{ execPath }}",
"extensions": [
".swift"
],
"language": "swift"
}
{
"description": {
"arguments": [
"run"
],
"defaultExecutablePath": "{{ execPath }}",
"extensions": [
".swift"
],
"language": "swift"
}
}
"""

static let localSettingsJson = """
Expand All @@ -57,77 +57,5 @@ internal struct Templates {
}
"""

static let mainSwift = """
//
// main.swift
// {{ name }}
//
// Auto Generated by SwiftFunctionsSDK
//
// Do Not modify/change code outside the marked area.
// Only register/remove Functions. Do Not add other code
//
import SwiftFunc
let registry = FunctionRegistry()
// ****** register/remove your functions ******
//registry.register(name: "name", function: MyFunction.self)
// ******
AzureFunctionsWorker.shared.main(registry: registry)
"""

static let mainSwiftWithFunctions =
"""
//
// main.swift
// {{ name }}
//
// Auto Generated by SwiftFunctionsSDK
//
// Do Not modify/change code outside the marked area.
// Only register/remove Functions. Do Not add other code
//
import SwiftFunc
let registry = FunctionRegistry()
{{ functions }}
AzureFunctionsWorker.shared.main(registry: registry)
"""

static let packageSwift = """
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: " {{ name }} ",
products: [
.executable(name: "functions", targets: ["{{ name }}"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "../SwiftFunc", from: "0.0.2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "{{ name }}",
dependencies: [])
]
)
"""

}
}
Loading

0 comments on commit c29a758

Please sign in to comment.