Try our conversational search powered by Generative AI!

Problems retrieving pages in automatic scheduled job

Vote:
 

Hello all,

I have a problem retrieving data from EPiServer when running a scheduled job. In the scheduled job I have added code to run it having enough rights.

EPiServer.Security.PrincipalInfo.CurrentPrincipal = EPiServer.Security.PrincipalInfo.CreatePrincipal("admin");

The code that fails every now and then is below:

-------------------

PageReference startPoint = PageReference.StartPage;

// Build  criterion for given type

var criterion = new PropertyCriteria();

criterion.Name = "PageTypeID";

criterion.Type = PropertyDataType.PageType;

criterion.Condition = CompareCondition.Equal;

criterion.Value = String.Format("{0}", PageTypeResolver.Instance.GetPageTypeID(typeof(T)));

// Create criteria

var criteria = new PropertyCriteriaCollection { criterion };

// Return a list of all found pages

IEnumerable<T> pages = DataFactory.Instance.FindAllPagesWithCriteria(startPoint, criteria, languageBranch, LanguageSelector.Fallback(languageBranch, true)).OfType<T>();

return pages;

-----

When I start the scheduled job manually it returns pages for the entered languageBranch, English in our case. The masterlanguage is English too. When the scheduled job is started automatically it doesn't always return pages for the entered languagebranch, again English in our case. For an undefined number of calls it returns the correct pages, but at a certain point it doesn't anymore, while using the same criteria en languagebranch.

I have read these blog posts:

http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=48887 about an automatically added epslanguage= http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=65069 about using DataContext.Current

I suspect that something similar is happening here. Does anybody have an idea and maybe some suggestions how th fix it.

Thanks in advance

Ed Schimmel

#69777
Apr 05, 2013 13:38
Vote:
 

I see that you are using OfType<T>()...
Are you using PTB in a CMS 6 or earlier project?

I've noticed that there is something weird going on with PTB combined with multiple languages and FindPagesByCriteria which is exactly what you have. You can easily check this by splitting the .OfType<T>() to a separate line and use log4net to log the number of hits before that call and after that call.

The easy workaround is to avoid using PTB in just this instance (remove that .OfType() and use the standard PageData class) until that bug is identified and fixed in PTB.

Worth a shot if you are using PTB at least...

#69975
Apr 10, 2013 12:00
Vote:
 

Instead of passing the language to FindPagesWithCritiea, use this method to setup the culture before calling the FindPagesWithCritriea and use the overload (without language parameter) method.

There is also the difference between running the scheduled job manually or letting the scheduler start it.

#69980
Apr 10, 2013 13:48
Vote:
 

Hi Daniel, Tahir,

Thanks for suggestions. I have solved this problem now. The main reason that was causing this behaviour is the configuration of the application pool. After being idle for 20 min the application pool timed out. A scheduled job will still be started, but can not retrieve any information anymore from episerver. It is a pity that this is not documented very well. It took me a few days to find out.

Still it is not working perfectly, because the statuses of the scheduled jobs aren't updated and I am not sure if this is also the case for the Versions tab. I hope that the pages are saved and published, but I am not sure. Still something to investigate :-(

Regards,

Ed

 

#70134
Apr 12, 2013 11:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.