Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions SeleniumGridNodeMachineAutoscaler/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion SeleniumGridNodeMachineAutoscaler/Package.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// swift-tools-version:6.0
import PackageDescription

let package = Package(

Check warning on line 4 in SeleniumGridNodeMachineAutoscaler/Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Top-level declarations should specify Access Control Level keywords explicitly (explicit_top_level_acl)

Check warning on line 4 in SeleniumGridNodeMachineAutoscaler/Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

All declarations should specify Access Control Level keywords explicitly (explicit_acl)
name: "SeleniumGridNodeMachineAutoscaler",
platforms: [
.macOS(.v13)
.macOS(.v15),
],
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "4.115.0"),
// 🔵 Non-blocking, event-driven networking for Swift. Used for custom executors
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
.package(url: "https://github.com/GetAutomaApp/AutomaUtilities", branch: "main"),
],
targets: [
.executableTarget(
Expand All @@ -19,6 +20,7 @@
.product(name: "Vapor", package: "vapor"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "AutomaUtilities", package: "AutomaUtilities"),
],
swiftSettings: swiftSettings
),
Expand All @@ -33,6 +35,6 @@
]
)

var swiftSettings: [SwiftSetting] { [

Check warning on line 38 in SeleniumGridNodeMachineAutoscaler/Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Top-level declarations should specify Access Control Level keywords explicitly (explicit_top_level_acl)

Check warning on line 38 in SeleniumGridNodeMachineAutoscaler/Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

All declarations should specify Access Control Level keywords explicitly (explicit_acl)
.enableUpcomingFeature("ExistentialAny"),
] }

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SeleniumGridNodeAutoCreatorCommand.swift
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

import Vapor

internal struct SeleniumGridNodeAutoCreatorCommand: AsyncCommand {
internal struct Signature: CommandSignature {}

internal var help: String {
"Auto-creates fly.io SeleniumGrid Node App machines"
}

internal func run(using context: CommandContext, signature _: Signature) async throws {
let autoCreator = try SeleniumGridNodeAutoCreator(
client: context.application.client,
logger: context.application.logger,
cyclePauseDurationSeconds: 10
)
try await autoCreator.autoCreateNodeMachines()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,34 @@

import Vapor

enum SeleniumGridNodeAutoDestroyerType: String, Codable {
internal enum SeleniumGridNodeAutoDestroyerType: String, Codable {
case offMachines
case oldMachines
}

struct SeleniumGridNodeAutoDestroyerCommand: AsyncCommand {
struct Signature: CommandSignature {
internal struct SeleniumGridNodeAutoDestroyerCommand: AsyncCommand {
internal struct Signature: CommandSignature {
@Argument(name: "type")
var type: SeleniumGridNodeAutoDestroyerType.RawValue
internal var type: SeleniumGridNodeAutoDestroyerType.RawValue
}

var help: String {
internal var help: String {
"Auto destroys fly.io SeleniumGrid Node App machines"
}

func run(using context: CommandContext, signature: Signature) async throws {
/// Run auto-destroyer command
/// - Throws: An eror if there was a problem destroying machines
public func run(using context: CommandContext, signature: Signature) async throws {
let destroyer = try SeleniumGridNodeAutoDestroyer(
logger: context.application.logger,
client: context.application.client
client: context.application.client,
cyclePauseDurationSeconds: 10
)
switch signature.type {
case "offMachines":
try await destroyer.autoDestroyAllOffNodeMachines(cyclePauseDuration: 10)
try await destroyer.autoDestroyAllOffNodeMachines()
case "oldMachines":
try await destroyer.autoDestroyAllOldNodeMachines(cyclePauseDuration: 10)
try await destroyer.autoDestroyAllOldNodeMachines()
default:
throw Abort(
.internalServerError,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// CycleSleeper.swift
// Copyright (c) 2025 GetAutomaApp
// All source code and related assets are the property of GetAutomaApp.
// All rights reserved.

import Vapor

internal struct CycleSleeper {
internal let config: CycleSleeperConfig
internal let logger: Logger

internal init(_ config: CycleSleeperConfig, logger: Logger) {
self.config = config
self.logger = logger
}

internal struct CycleSleeperConfig {
internal let duration: Int
internal let startMessage: String? = nil
internal let completionMessage: String? = nil
}

/// Sleep for a cycle
/// - Throws: An error if `Task.sleep()` failed for some reason
public func sleep() async throws {
logSleepBetweenCycleStarted()
try await Task.sleep(for: .seconds(config.duration))
logSleepBetweenCycleCompleted()
}

private func logSleepBetweenCycleStarted() {
logger.info(
Logger
.Message(stringLiteral: config
.startMessage ?? "Pausing for \(config.duration) before next cycle starts."),
metadata: [
"to": .string("\(String(describing: Self.self)).\(#function)"),
]
)
}

private func logSleepBetweenCycleCompleted() {
logger.info(
Logger
.Message(stringLiteral: config
.completionMessage ?? "Pausing for \(config.duration) before completed."),
metadata: [
"to": .string("\(String(describing: Self.self)).\(#function)"),
]
)
}
}

This file was deleted.

Loading