I am trying to setup a scheduled action that adds news items to my news page for a rss feed.
Here is the class that should work
<ScheduleExecution(1, TimeUnit.Seconds, Repeat:=Repeat.Indefinitely)> _
Public Class News_Timer
Dim mlist As ItemList(Of News_List)
Public Overrides Sub Execute()
mlist = Find.Items.Where.Type.Eq(GetType(News_List)).Select()
For Each item As News_List In mlist
Public Sub Get_Updates(ByVal Url As String, ByVal Parent As News_List)
Dim google As Google_RssRss = Google_RssRss.Load(New System.Uri(Url))
Dim RegexObj As Regex = New Regex("(?<Title>.+)\s-\s(?<Source>.+)")
Dim m As GroupCollection
For Each Item As Google_RssItem In google.Channel.Items
Dim list As IList(Of ContentItem) = Find.Items.Where.Type.Eq(GetType(News_Item)).And.Detail("GUID").Eq(Item.Guid.Text).OrderBy.Published.Desc.MaxResults(1).Select()
If Not list.Count > 0 Then
Dim News As News_Item = N2.Context.Definitions.CreateInstance(Of News_Item)(Parent)
News.GUID = Item.Guid.Text
News.Published_Date = Item.PubDate
News.Link = Item.Link
News.Introduction = Regex.Match(Item.Description, "(?S:.)*<br><font[^>]*>(?:<b>\.\.\.</b>?(.*)<b>\.\.\.</b>").ToString
News.Introduction = Regex.Replace(News.Introduction, "<[^>]+>", "")
'News.Introduction = News.Text
m = RegexObj.Match(Item.Title).Groups
News.Source = m("Source").ToString
News.Title = m("Title").ToString
News.Expires = DateTime.Now.AddDays(Parent.DaysListed)
How ever the Execute sub is never executed.
I think this may have to do with me being on Medium Trust but it still does not work when i turn that off.
Am i setting this up right?
thanks for all your help,
I noticed this because I had the same issue whilst trying to get ScheduledActions to execute under medium trust. Although I am by no means an expert, I did get them working eventually. To do this I had to do two things:
1. Add an instance of the Heart and Scheduler classes to the engine container, this will start the timer that triggers the scheduled actions, and call them when required (sorry for the c# syntax, but my VB is really rusty).
IHeart heart = AddComponentInstance(new Heart(engineConfiguration));
2. Set the interval value in the web.config to something lower, the default is 60 seconds, so no matter how low you set the interval, it will only ever be called after 60 seconds (this might be why you couldn't get it to work under full trust).
AddComponentInstance(new Scheduler(pluginFinder, heart, webContext, errorHandler));
Like I said I'm no expert, so if somebody has a better explaination then please add it here :). As an aside I would be interested in any suggestions as to where is the best place to add the code to add the scheduler. I currently have placed mine in the constructor
of MediumTrustEngine, purely because it was the most convenient place, but I would much rather inject it by some means that does not require any modification of the N2 source.
<scheduler interval="5" />
Nov 29, 2008 at 8:42 PM
Hi Nigel. I applied your code to the medium trust engine constructor. Next version you shouldn't need to add this fix.