Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
9c6caa7b
Commit
9c6caa7b
authored
Aug 25, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished API
parent
f301fe0f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
5 deletions
+36
-5
BlendMinutelySource/BlendMinutelySource/BlendMinutelySource.swift
+29
-2
OneWeatherCore/OneWeatherCore/Model/LocationManager.swift
+6
-2
OneWeatherCore/OneWeatherCore/Sources/MinutelyForecastSource.swift
+1
-1
No files found.
BlendMinutelySource/BlendMinutelySource/BlendMinutelySource.swift
View file @
9c6caa7b
...
@@ -31,16 +31,43 @@ public class BlendMinutelySource: MinutelyForecastSource {
...
@@ -31,16 +31,43 @@ public class BlendMinutelySource: MinutelyForecastSource {
fmt
.
dateFormat
=
"yyyy-MM-dd'T'hh:mm:ss.sss'Z'"
fmt
.
dateFormat
=
"yyyy-MM-dd'T'hh:mm:ss.sss'Z'"
return
fmt
return
fmt
}()
}()
/// This queue is needed to synchronize access to locationsBeingUpdated. Also, to make logging more clear.
private
let
internalQueue
:
OperationQueue
=
{
let
queue
=
OperationQueue
()
queue
.
name
=
"BlendMinutelySource Queue"
queue
.
maxConcurrentOperationCount
=
1
return
queue
}()
private
var
locationsBeingUpdated
=
Set
<
Location
>
()
//Public
//Public
#if DEBUG
#if DEBUG
public
let
health
UpdateInterval
=
TimeInterval
(
2
*
60
)
// 2 minutes
public
let
minutely
UpdateInterval
=
TimeInterval
(
2
*
60
)
// 2 minutes
#else
#else
public
let
health
UpdateInterval
=
TimeInterval
(
15
*
60
)
// 15 minutes
public
let
minutely
UpdateInterval
=
TimeInterval
(
15
*
60
)
// 15 minutes
#endif
#endif
public
init
()
{}
public
init
()
{}
public
func
getMinutelyForecast
(
forLocation
location
:
Location
,
completion
:
@escaping
MinutelyForecastCompletion
)
{
public
func
getMinutelyForecast
(
forLocation
location
:
Location
,
completion
:
@escaping
MinutelyForecastCompletion
)
{
internalQueue
.
addOperation
{
[
weak
self
]
in
let
extendedCompletion
:
MinutelyForecastCompletion
=
{
[
weak
self
]
result
in
self
?
.
internalQueue
.
addOperation
{
completion
(
result
)
self
?
.
locationsBeingUpdated
.
remove
(
location
)
}
}
self
?
.
getMinutelyForecastInternal
(
forLocation
:
location
,
completion
:
extendedCompletion
)
}
}
private
func
getMinutelyForecastInternal
(
forLocation
location
:
Location
,
completion
:
@escaping
MinutelyForecastCompletion
)
{
guard
!
locationsBeingUpdated
.
contains
(
location
)
else
{
completion
(
.
failure
(
BlendMinutelySourceError
.
alreadyBeingUpdated
))
return
}
locationsBeingUpdated
.
insert
(
location
)
guard
location
.
region
!=
nil
,
location
.
cityName
!=
nil
else
{
guard
location
.
region
!=
nil
,
location
.
cityName
!=
nil
else
{
completion
(
.
failure
(
BlendMinutelySourceError
.
invalidParameters
))
completion
(
.
failure
(
BlendMinutelySourceError
.
invalidParameters
))
return
return
...
...
OneWeatherCore/OneWeatherCore/Model/LocationManager.swift
View file @
9c6caa7b
...
@@ -375,7 +375,7 @@ public class LocationManager {
...
@@ -375,7 +375,7 @@ public class LocationManager {
public
func
updateMinutelyForecast
(
for
location
:
Location
)
{
public
func
updateMinutelyForecast
(
for
location
:
Location
)
{
if
let
lastTimeUpdated
=
location
.
minutely
?
.
lastUpdateTime
{
if
let
lastTimeUpdated
=
location
.
minutely
?
.
lastUpdateTime
{
guard
Date
()
.
timeIntervalSince
(
lastTimeUpdated
)
>=
minutelyForecastSource
.
health
UpdateInterval
else
{
guard
Date
()
.
timeIntervalSince
(
lastTimeUpdated
)
>=
minutelyForecastSource
.
minutely
UpdateInterval
else
{
log
.
verbose
(
"Update minutely forecast (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
), skip update."
)
log
.
verbose
(
"Update minutely forecast (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
), skip update."
)
return
return
}
}
...
@@ -386,7 +386,11 @@ public class LocationManager {
...
@@ -386,7 +386,11 @@ public class LocationManager {
switch
result
{
switch
result
{
case
.
success
(
let
minutelyForecast
):
case
.
success
(
let
minutelyForecast
):
self
.
make
self
.
makeChanges
(
to
:
location
,
in
:
"minutely"
)
{
(
location
)
->
Location
in
var
updatedLocation
=
location
updatedLocation
.
minutely
=
minutelyForecast
return
updatedLocation
}
case
.
failure
(
let
error
):
case
.
failure
(
let
error
):
self
.
log
.
error
(
"Update minutely (
\(
location
)
error:
\(
error
)
"
)
self
.
log
.
error
(
"Update minutely (
\(
location
)
error:
\(
error
)
"
)
}
}
...
...
OneWeatherCore/OneWeatherCore/Sources/MinutelyForecastSource.swift
View file @
9c6caa7b
...
@@ -10,7 +10,7 @@ import Foundation
...
@@ -10,7 +10,7 @@ import Foundation
public
typealias
MinutelyForecastCompletion
=
(
_
result
:
Result
<
MinutelyForecast
,
Error
>
)
->
()
public
typealias
MinutelyForecastCompletion
=
(
_
result
:
Result
<
MinutelyForecast
,
Error
>
)
->
()
public
protocol
MinutelyForecastSource
{
public
protocol
MinutelyForecastSource
{
var
health
UpdateInterval
:
TimeInterval
{
get
}
var
minutely
UpdateInterval
:
TimeInterval
{
get
}
func
getMinutelyForecast
(
forLocation
location
:
Location
,
completion
:
@escaping
MinutelyForecastCompletion
)
func
getMinutelyForecast
(
forLocation
location
:
Location
,
completion
:
@escaping
MinutelyForecastCompletion
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment