-
Notifications
You must be signed in to change notification settings - Fork 1
Fix daily check persistence after successful lookup #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc9087d
fix(scheduling): Record daily checks after successful lookup
HituziANDO 7861e4f
Use generic iOS simulator destination in CI
Copilot 482b45a
fix: update CI destination to use iPhone 17 simulator
Copilot 0373669
fix(scheduling): Prevent concurrent daily lookups
HituziANDO 4679622
fix(scheduling): Suppress noop during active lookup
HituziANDO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // | ||
| // DailySchedule.swift | ||
| // SwiftyUpdateKit | ||
| // | ||
| // Copyright © 2026 Hituzi Ando. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| protocol SUKClock { | ||
| func currentDate() -> Int | ||
| } | ||
|
|
||
| struct SystemSUKClock: SUKClock { | ||
| func currentDate() -> Int { | ||
| DateUtils.currentDate() | ||
| } | ||
| } | ||
|
|
||
| protocol SUKSchedulingStateStore { | ||
| func set(_ value: Int, forKey key: String) | ||
| func integer(forKey key: String) -> Int | ||
| } | ||
|
|
||
| struct UserDefaultsSchedulingStateStore: SUKSchedulingStateStore { | ||
| func set(_ value: Int, forKey key: String) { | ||
| SUKUserDefaults.standard.set(value, forKey: key) | ||
| } | ||
|
|
||
| func integer(forKey key: String) -> Int { | ||
| SUKUserDefaults.standard.integer(forKey: key) | ||
| } | ||
| } | ||
|
|
||
| struct InMemorySchedulingStateStore: SUKSchedulingStateStore { | ||
| func set(_ value: Int, forKey key: String) { | ||
| sharedDictionary.setValue(value, forKey: key) | ||
| } | ||
|
|
||
| func integer(forKey key: String) -> Int { | ||
| sharedDictionary.value(forKey: key) as? Int ?? 0 | ||
| } | ||
| } | ||
|
|
||
| protocol SchedulingExecutionGating: AnyObject { | ||
| func beginExecution(forKey key: String) -> Bool | ||
| func finishExecution(forKey key: String) | ||
| } | ||
|
|
||
| final class SchedulingExecutionGate: SchedulingExecutionGating { | ||
| private let lock = NSLock() | ||
| private var runningKeys: Set<String> = [] | ||
|
|
||
| func beginExecution(forKey key: String) -> Bool { | ||
| lock.lock() | ||
| defer { lock.unlock() } | ||
|
|
||
| return runningKeys.insert(key).inserted | ||
| } | ||
|
|
||
| func finishExecution(forKey key: String) { | ||
| lock.lock() | ||
| defer { lock.unlock() } | ||
|
|
||
| runningKeys.remove(key) | ||
| } | ||
| } | ||
|
|
||
| let sharedSchedulingExecutionGate = SchedulingExecutionGate() | ||
|
|
||
| struct DailySchedule { | ||
| private let clock: SUKClock | ||
| private let stateStore: SUKSchedulingStateStore | ||
| private let executionGate: SchedulingExecutionGating | ||
| private let key: String | ||
|
|
||
| init(clock: SUKClock, | ||
| stateStore: SUKSchedulingStateStore, | ||
| executionGate: SchedulingExecutionGating = sharedSchedulingExecutionGate, | ||
| key: String) | ||
| { | ||
| self.clock = clock | ||
| self.stateStore = stateStore | ||
| self.executionGate = executionGate | ||
| self.key = key | ||
| } | ||
|
|
||
| func shouldRun() -> Bool { | ||
| stateStore.integer(forKey: key) < clock.currentDate() | ||
| } | ||
|
|
||
| func hasRecordedDate() -> Bool { | ||
| stateStore.integer(forKey: key) != 0 | ||
| } | ||
|
|
||
| func recordCurrentDate() { | ||
| let currentDate = clock.currentDate() | ||
| guard stateStore.integer(forKey: key) < currentDate else { return } | ||
|
|
||
| stateStore.set(currentDate, forKey: key) | ||
| } | ||
|
|
||
| func beginExecution() -> Bool { | ||
| executionGate.beginExecution(forKey: key) | ||
| } | ||
|
|
||
| func finishExecution() { | ||
| executionGate.finishExecution(forKey: key) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.