过时的资源上的午睡加载失败

时间:2018-07-18 12:25:17

标签: ios swift siesta-swift

经过一段时间(例如几小时)后启动我的应用程序(模拟器或手机)时,Siesta不会加载我的资源,并且statusOverlay()会无限显示。

详细地说,我有一个HomeViewController,它发出以下请求onViewAppear

Api.currentUser.loadIfNeeded()
Api.events.loadIfNeeded()
Api.recommendedProducts.loadIfNeeded()

在我的viewDidLoad中,我指定了各个资源观察者,如下所示:

statusOverlay.embed(in: self)
Api.currentUser.addObserver(statusOverlay).addObserver(owner: self){
        [weak self] resource, _ in
        if(resource.isUpToDate){
            self?.setWelcomeMessage(user: resource.typedContent())
        }
}

Api.events.addObserver(statusOverlay).addObserver(owner: self){
        [weak self] resource, _ in
        if(resource.isUpToDate){
            self?.setEvents(events: resource.typedContent())
        }
}

Api.recommendedProducts.addObserver(statusOverlay).addObserver(owner: self){
        [weak self] resource, _ in
        if(resource.isUpToDate){
            self?.setRecommendedProducts(products: resource)
        }
}

资源和Siesta实例在Api类中定义。虽然此代码在正常使用该应用程序时效果很好,但是当该应用程序在后台或关闭一段时间后,它仍然会遇到困难。

完整的Siesta日志记录将导致以下内容(承载令牌有效,但出于可读性而被截断):

Siesta:network        │ Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[]
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[] is not up to date: no error | no data
Siesta:configuration  │ Computing configuration for GET Resource(…/event?dir=desc&order=ends_at)[]
Siesta:configuration  │   ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration  │   ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration  │   ├╴Applying config 6 [/event : Data → Array<Event>]
Siesta:configuration  │   ├╴Applying config 20 [**]
Siesta:configuration  │   └╴Resulting configuration 
Siesta:configuration  │       expirationTime:            30.0 sec
Siesta:configuration  │       retryTime:                 1.0 sec
Siesta:configuration  │       progressReportingInterval: 0.05 sec
Siesta:configuration  │       headers (1)
Siesta:configuration  │         Authorization: Bearer ABCDE
Siesta:configuration  │       requestDecorators: 0
Siesta:configuration  │       pipeline
Siesta:configuration  │         ║ rawData stage (no transformers)
Siesta:configuration  │         ║ decoding stage (no transformers)
Siesta:configuration  │         ║ parsing stage
Siesta:configuration  │         ╟   ⟨text/*⟩ Data → String  [transformErrors: true]
Siesta:configuration  │         ╟   ⟨image/*⟩ Data → UIImage
Siesta:configuration  │         ║ model stage
Siesta:configuration  │         ╟   Data → Array<Event>
Siesta:configuration  │         ║ cleanup stage (no transformers)
Siesta:network        │ Cache request for Resource(…/event?dir=desc&order=ends_at)[]
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[] is not up to date: no error | no data
Siesta:configuration  │ Computing configuration for GET Resource(…/my/recommended/products)[]
Siesta:configuration  │   ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration  │   ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration  │   ├╴Applying config 5 [/my/recommended/products : Data → Array<Product>]
Siesta:configuration  │   ├╴Applying config 20 [**]
Siesta:configuration  │   └╴Resulting configuration 
Siesta:configuration  │       expirationTime:            30.0 sec
Siesta:configuration  │       retryTime:                 1.0 sec
Siesta:configuration  │       progressReportingInterval: 0.05 sec
Siesta:configuration  │       headers (1)
Siesta:configuration  │         Authorization: Bearer ABCDE
Siesta:configuration  │       requestDecorators: 0
Siesta:configuration  │       pipeline
Siesta:configuration  │         ║ rawData stage (no transformers)
Siesta:configuration  │         ║ decoding stage (no transformers)
Siesta:configuration  │         ║ parsing stage
Siesta:configuration  │         ╟   ⟨text/*⟩ Data → String  [transformErrors: true]
Siesta:configuration  │         ╟   ⟨image/*⟩ Data → UIImage
Siesta:configuration  │         ║ model stage
Siesta:configuration  │         ╟   Data → Array<Product>
Siesta:configuration  │         ║ cleanup stage (no transformers)
Siesta:network        │ Cache request for Resource(…/my/recommended/products)[]
Siesta:staleness      │ Resource(…/my/recommended/products)[] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/my/recommended/products)[] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[] is not up to date: no error | no data
Siesta:network        │ Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])]
Siesta:networkDetails │ Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[] already started
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[] is not up to date: no error | no data
Siesta:network        │ Chain[Request:60c0003c2df0(Cache request for Resource(…/event?dir=desc&order=ends_at)[])]
Siesta:networkDetails │ Cache request for Resource(…/event?dir=desc&order=ends_at)[] already started
Siesta:staleness      │ Resource(…/my/recommended/products)[] is not up to date: no error | no data
Siesta:network        │ Chain[Request:6080001de4b0(Cache request for Resource(…/my/recommended/products)[])]
Siesta:networkDetails │ Cache request for Resource(…/my/recommended/products)[] already started
Siesta:configuration  │ Configurations need to be recomputed
Siesta:stateChanges   │ Resource(…/event?dir=desc&order=ends_at)[L] wiped
Siesta:network        │ Cancelled Chain[Request:60c0003c2df0(Cache request for Resource(…/event?dir=desc&order=ends_at)[])]
Siesta:network        │ Cancelled Cache request for Resource(…/event?dir=desc&order=ends_at)[]
Siesta:observers      │ Resource(…/event?dir=desc&order=ends_at)[L] sending newData(wipe) event to 2 observers
Siesta:observers      │   ↳ newData(wipe) → <Siesta.ResourceStatusOverlay: 0x7fbe105369a0; frame = (0 0; 320 568); hidden = YES; layer = <CALayer: 0x6080002347c0>>
Siesta:observers      │   ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:66)
Siesta:configuration  │ Computing configuration for GET Resource(…/event?dir=desc&order=ends_at)[L]
Siesta:configuration  │   ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration  │   ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration  │   ├╴Applying config 6 [/event : Data → Array<Event>]
Siesta:configuration  │   ├╴Applying config 20 [**]
Siesta:configuration  │   └╴Resulting configuration 
Siesta:configuration  │       expirationTime:            30.0 sec
Siesta:configuration  │       retryTime:                 1.0 sec
Siesta:configuration  │       progressReportingInterval: 0.05 sec
Siesta:configuration  │       headers (1)
Siesta:configuration  │         Authorization: Bearer ABCDE
Siesta:configuration  │       requestDecorators: 0
Siesta:configuration  │       pipeline
Siesta:configuration  │         ║ rawData stage (no transformers)
Siesta:configuration  │         ║ decoding stage (no transformers)
Siesta:configuration  │         ║ parsing stage
Siesta:configuration  │         ╟   ⟨text/*⟩ Data → String  [transformErrors: true]
Siesta:configuration  │         ╟   ⟨image/*⟩ Data → UIImage
Siesta:configuration  │         ║ model stage
Siesta:configuration  │         ╟   Data → Array<Event>
Siesta:configuration  │         ║ cleanup stage (no transformers)
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:network        │ Cache request for Resource(…/event?dir=desc&order=ends_at)[L]
Siesta:stateChanges   │ Resource(…/user/5b0553d15e70bf00104224fc)[L] wiped
Siesta:network        │ Cancelled Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])]
Siesta:network        │ Cancelled Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[]
Siesta:observers      │ Resource(…/user/5b0553d15e70bf00104224fc)[L] sending newData(wipe) event to 1 observer
Siesta:observers      │   ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:56)
Siesta:configuration  │ Computing configuration for GET Resource(…/user/5b0553d15e70bf00104224fc)[L]
Siesta:configuration  │   ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration  │   ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration  │   ├╴Applying config 2 [/user/* : Data → User]
Siesta:configuration  │   ├╴Applying config 20 [**]
Siesta:configuration  │   └╴Resulting configuration 
Siesta:configuration  │       expirationTime:            30.0 sec
Siesta:configuration  │       retryTime:                 1.0 sec
Siesta:configuration  │       progressReportingInterval: 0.05 sec
Siesta:configuration  │       headers (1)
Siesta:configuration  │         Authorization: Bearer ABCDE
Siesta:configuration  │       requestDecorators: 0
Siesta:configuration  │       pipeline
Siesta:configuration  │         ║ rawData stage (no transformers)
Siesta:configuration  │         ║ decoding stage (no transformers)
Siesta:configuration  │         ║ parsing stage
Siesta:configuration  │         ╟   ⟨text/*⟩ Data → String  [transformErrors: true]
Siesta:configuration  │         ╟   ⟨image/*⟩ Data → UIImage
Siesta:configuration  │         ║ model stage
Siesta:configuration  │         ╟   Data → User
Siesta:configuration  │         ║ cleanup stage (no transformers)
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:network        │ Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[L]
Siesta:stateChanges   │ Resource(…/my/recommended/products)[L] wiped
Siesta:network        │ Cancelled Chain[Request:6080001de4b0(Cache request for Resource(…/my/recommended/products)[])]
Siesta:network        │ Cancelled Cache request for Resource(…/my/recommended/products)[]
Siesta:observers      │ Resource(…/my/recommended/products)[L] sending newData(wipe) event to 2 observers
Siesta:observers      │   ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:76)
Siesta:configuration  │ Computing configuration for GET Resource(…/my/recommended/products)[L]
Siesta:configuration  │   ├╴Applying config 0 [Siesta standard text parsing]
Siesta:configuration  │   ├╴Applying config 1 [Siesta standard image parsing]
Siesta:configuration  │   ├╴Applying config 5 [/my/recommended/products : Data → Array<Product>]
Siesta:configuration  │   ├╴Applying config 20 [**]
Siesta:configuration  │   └╴Resulting configuration 
Siesta:configuration  │       expirationTime:            30.0 sec
Siesta:configuration  │       retryTime:                 1.0 sec
Siesta:configuration  │       progressReportingInterval: 0.05 sec
Siesta:configuration  │       headers (1)
Siesta:configuration  │         Authorization: Bearer ABCDE
Siesta:configuration  │       requestDecorators: 0
Siesta:configuration  │       pipeline
Siesta:configuration  │         ║ rawData stage (no transformers)
Siesta:configuration  │         ║ decoding stage (no transformers)
Siesta:configuration  │         ║ parsing stage
Siesta:configuration  │         ╟   ⟨text/*⟩ Data → String  [transformErrors: true]
Siesta:configuration  │         ╟   ⟨image/*⟩ Data → UIImage
Siesta:configuration  │         ║ model stage
Siesta:configuration  │         ╟   Data → Array<Product>
Siesta:configuration  │         ║ cleanup stage (no transformers)
Siesta:staleness      │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:observers      │   ↳ newData(wipe) → <Siesta.ResourceStatusOverlay: 0x7fbe105369a0; frame = (0 0; 320 568); layer = <CALayer: 0x6080002347c0>>
Siesta:network        │ Cache request for Resource(…/my/recommended/products)[L]
Siesta:networkDetails │ Received response, but request was already cancelled: Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[] 
Siesta:networkDetails │     New response: RequestError(userMessage: "Cache miss", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.CacheMiss()), timestamp: 553608424.06342196)
Siesta:networkDetails │ Received response, but request was already cancelled: Cache request for Resource(…/event?dir=desc&order=ends_at)[] 
Siesta:networkDetails │     New response: RequestError(userMessage: "Cache miss", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.CacheMiss()), timestamp: 553608424.07201898)
Siesta:networkDetails │ Received response, but request was already cancelled: Cache request for Resource(…/my/recommended/products)[] 
Siesta:networkDetails │     New response: RequestError(userMessage: "Cache miss", httpStatusCode: nil, entity: nil, cause: Optional(Siesta.RequestError.Cause.CacheMiss()), timestamp: 553608424.08093095)
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/my/recommended/products)[L] is not up to date: no error | no data
Siesta:staleness      │ Resource(…/user/5b0553d15e70bf00104224fc)[L] loadIfNeeded(): load is already in progress: Request:6000001d6bc0(Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])])
Siesta:staleness      │ Resource(…/event?dir=desc&order=ends_at)[L] loadIfNeeded(): load is already in progress: Request:60c0003c2ee0(Chain[Request:60c0003c2df0(Cache request for Resource(…/event?dir=desc&order=ends_at)[])])
Siesta:staleness      │ Resource(…/my/recommended/products)[L] loadIfNeeded(): load is already in progress: Request:60c0003c2fd0(Chain[Request:6080001de4b0(Cache request for Resource(…/my/recommended/products)[])])

实际上,没有发出GET请求,并且statusOverlay仍然可见。

完全重启应用程序可以解决问题,但这当然不适合最终用户。

您对我如何解决此问题有任何想法?提前非常感谢!

1 个答案:

答案 0 :(得分:0)

日志的这一部分:

PATH

…建议您呼叫Siesta:stateChanges │ Resource(…/user/5b0553d15e70bf00104224fc)[L] wiped Siesta:network │ Cancelled Chain[Request:6000001d68f0(Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[])] Siesta:network │ Cancelled Cache request for Resource(…/user/5b0553d15e70bf00104224fc)[] Siesta:observers │ Resource(…/user/5b0553d15e70bf00104224fc)[L] sending newData(wipe) event to 1 observer Siesta:observers │ ↳ newData(wipe) → ClosureObserver(HomeViewController.swift:56) Siesta.wipeResources()。这将导致取消任何对资源的未完成请求。也许您在超时后正在擦除资源?还是当应用程序出现在前台?

如果您要在擦除资源后立即触发新的加载 ,则如果Resource.wipe()为零,请让您的观察者调用loadIfNeeded()