Refresh Sitecore index to include CD's - sitecore

I've written some code to refresh an index when an item is programmatically added to Sitecore. Now as the live system is made up of 1 CM and 2 CD Servers I need my code to also trigger the indexing to be refreshed on the CD Servers (unfortunately my dev machine is just a single box so I can't test this fully). I've looked online but can't find anything about this when triggering a re-index programmatically.
So the question is do I need to write code for this or does Sitecore do this by default and if I do need to write code, does anyone have ideas how I go about this. My current code is below.
ISearchIndex index = ContentSearchManager.GetIndex("GeorgeDrexler_web_index");
Sitecore.Data.Database database = Sitecore.Configuration.Factory.GetDatabase("web");
Item item = database.GetItem("/sitecore/content/GeorgeDrexler/Global/Applications");
index.Refresh(new SitecoreIndexableItem(item));
My config for the index has the remotebuild strategy enabled
<strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/remoteRebuild" />

As #Hishaam Namooya pointed out in his comment, publishing from master to web should trigger the web index updates out of the box, unless you've disabled something in the configurations.
Note that items won't publish unless they are in a final workflow state, so if you want a completely automated process that creates the item, updates the local index, and then immediately updates the web index, you will also need to update the workflow state to your final approved state and then trigger a publish of the item.

Related

Sitecore Commerce Connect > Refreshing a Cache via code

I am trying to update the commerce catalog from external source. After the incremental update I need to have fresh data in Sitecore tree(data provider should return correct data instead of old(cached) ones). However, if I go to Sitecore right after the data import I can see only the old data till I click on "Refresh Catalog Cache" button in Sitecore Commerce menu.
I found the same info in the documentation for Sitecore Commerce Connect, however I can't find any example how to clean cache via code.
I found several types in "Sitecore.Commerce.Connect.CommerceServer.Caching" namespace. For example, CacheRefresh static class. It has RefreshCatalogCaches method which needs ICommerceServerContextManager contextManager as input parameter. If I create contextManager just using constructor new CommerceServerContextManager() and passing it to the method - it doesn't work(at least I still need to clean cache manually).
I would appreciate any advise/suggestion.
Thank you in advance.
You should do in your code same that happens on "Refresh Catalog Cache" button click:
CacheRefreshEvent eventX = new CacheRefreshEvent("catalogcache", "master", = ID.Null);
EventManager.QueueEvent<CacheRefreshEvent>(eventX, true, true);
For more details, look on Sitecore.Commerce.Connect.CommerceServer.Caching.RefreshCache, Sitecore.Commerce.Connect.CommerceServer implementation via reflector.

Sitecore Scheduled Job: Unable to run

I am very new with Sitecore, I am trying to create one task, but after creating task I configured command and task at content editor. Still I don't see run now option for my task at content editor. Need help.I want to know where the logs of scheduled jobs are written?
There are 2 places where you can define custom task.
In database
In config file
If you decide to go with 1st option
a task item must be created under /sitecore/system/tasks/schedules
item in the “core” database (default behavior).
no matter what schedule you set on that item, it may never be executed, if you do not have right DatabaseAgent looking after that task item.
DatabaseAgent periodically checks task items and if tasks must be
executed (based on the value set in the Scheduling field), it
executes actual code
By default the DatabaseAgent is called each 10
minutes
If you decide to go with 2nd option, check this article first.
In short, you need to define your task class and start method in the config files (check out the /sitecore/admin/showconfig.aspx page, to make sure config changes are applied successfully)
<scheduling>
<!--
Time between checking for scheduled tasks waiting to execute
-->
<frequency>00:00:05</frequency>
<agent type="NameSpace.TaskClass" method="MethodName" interval="00:10:00"/>
</agent>
</scheduling>
As specified in the other answers, you can use config file or database to execute your task. However, it seems that you want to run it manually.
I have a custom module on the Sitecore Marketplace which allows you to select the task you want run. Here is the link
In brief, you need to go to the Sitecore control panel, then click on administration and lastly click on the Run Agent.
It will open a window where you can select the task. I am assuming that the task you have implemented does not take the Item details on which you are when triggering the job.

How do I rebuild a custom Lucene index on a Sitecore content delivery server?

The custom Lucene index on my Sitecore 6.2 Content Delivery server seems to be not right. So I think I need to rebuild all 3 of my custom indexes. How do I do that? Do I just have to use the shared source Index Viewer module? Right now I have that installed on my CD server, however for some reason it is not working. When I select my custom index in Index Viewer - nothing happens. So I can't rebuild the index that way. Can I just delete the index files from the hard drive? If so, how quickly will Lucene rebuild them?
As noted above, earlier versions of Sitecore 6.x required custom indexes to be rebuild using either IndexViewer or with some custom code. I believe in a revision of 6.5 the Control Panel > Database > Rebuild Search Indexes began including custom indexes so IndexViewer is no longer necessary (but should still work).
To your specific question though, on my CD servers I have a rebuild script that can be called directly to rebuild search indexes. I forget where I found this script (believe it was something published by Alex Shyba at Sitecore). You can find the details of this script at https://gist.github.com/Refactored/6776801
However, I believe you have a different issue that needs to be addressed. If your CD servers aren't detecting changes and therefore not updating you have a configuration issue. I would start with this article when troubleshooting index issues: http://sitecoreblog.alexshyba.com/2011/04/search-index-troubleshooting.html
I ended up contacting Sitecore support and they pointed me to the shared source module called Sitecore Support Toolbox - http://marketplace.sitecore.net/en/Modules/Sitecore_Support_Toolbox.aspx. Once I installed that I was able to easily rebuild my indexes.
Since Sitecore 6.6 update 3 or 4 (don't remember which one was it) you can rebuild your custom indexes from the Sitecore Control Panel.
In all previous versions you need to rebuild it from code or using custom modules for Sitecore. Deleting index files won't work.
The simplest code for rebuilding custom Sitecore Lucene Index is:
Sitecore.Search.SearchManager.GetIndex("your_index_name").Rebuild()
The blog post "Troubleshooting Sitecore Lucene search and indexing" can help you if rebuilding the index won't solve your problem.
I have come across the same requirement in one of my projects. Here was my solution:
Create a configuration content item with a template that has only one field, say "Rebuild Index", default value is "1", example of the item path could be: "/sitecore/content/mysite/config/index rebuild flag"
Create an IndexRebuilder class that has a Run method. Within the Run method, check the "index rebuild flag" item (from the Context database) and rebuild the index on the server if the "Rebuild Index" field value equals to "1". After rebuilt successfully, update the item field value to "0".
Set up, a scheduled agent that points to the IndexRebuilder class. For examples,
<agent type="MyAssembly.IndexRebuilder, MyAssembly" method="Run" interval="00:00:00"/>
Notice that the interval is "00:00:00" by default, to turn off the agent on content management server. Your build and deployment process should turn this value to say "00:05:00", which allow the agent to run on every 5 minutes.
From there, to rebuild index on content delivery server, just publish the "index rebuild flag" item from master database to the content delivery database (web) and the index on your content delivery server should start rebuilding in 5 minutes.
Clicking Index Viewer with nothing happening, is usually an indication of certain files of the Index Viewer package having not been deployed to your CD server. Easiest fix for this - if you do have /sitecore running on the CD server - is to just re-install the package directly on the CD server. After this, IndexViewer will work.
If you don't have a /sitecore on your CD server (Sitecore recommends removing this, or at least blocking access to it) - it becomes more problematic. I would recommend setting a page/webservice or similar, executing the code Maras suggests above - that way you can always trigger an index rebuild when you need it.

Using New Relic with Sitecore

I am testing New Relic with Sitecore CMS. All of the New Relic web transactions are being sent to the items layout file, so I am unable to drill into item level details in New Relic.
I am trying to use the New Relic API to call SetTransactionName and set it to the items URL, but I can't seem to make it work. I have created an httprequestbegin pipeline processor, and I have put it right at the end, right after:
<processor type="Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel"/>
I have the New Relic API assembly installed, and is also in my bin folder. Here is the line of code that I am trying to run.
NewRelic.Api.Agent.NewRelic.SetTransactionName("Custom", Sitecore.Context.RawUrl);
Any ideas what I am possibly doing wrong? All web transactions still show up as the items layout file.
I'm setting the transaction name in the httpRequestProcessed pipeline and that works. Started out using the httpRequestBegin but I found that is was not working every time. Also remember that your request must take longer than 500 ms to execute before NewRelic picks it up.
Additional integration points I did with Sitecore:
Log4Net Appender that reports to NewRelic using NoticeError
HttpModule picking up Application_Error and reporting to NewRelic using NoticeError
Use Item path to name transactions and use AddCustomParameter to add Language, Database, User etc.
There is a module on the marketplace that sorts all this out:
http://marketplace.sitecore.net/en/Modules/New_Relic.aspx
We had similar issues when we started using New Relic with our Sitecore application about 18 or so months back. Unfortunately nobody was using New Relic with Sitecore at the time. What we settled on was to add the following code to a base Page class that every page in our site inherits:
// --- Set custom transaction name for New Relic.
NewRelic.Api.Agent.NewRelic.SetTransactionName("Pages", Sitecore.Context.Item.Template.FullName));
// --- Set custom parameter to store raw url to assist with diagnostics.
NewRelic.Api.Agent.NewRelic.AddCustomParameter("RawUrl", Request.RawUrl);
For our application template names are enough to distinguish trends and we added the custom parameter to stuff the entire RawUrl (we noticed oddities at the time where New Relic wasn't capturing the complete url for us, that might not be the case any longer).

Simple question about Sitecore's publish:end:remote event

Anyone have luck with the publish:end:remote Sitecore event or can shed some light on how it's supposed to work? I simply cannot get it to fire.
From what I understand, it's an event that will trigger after a successful publish to a remote instance of Sitecore. The trouble is, there appears to be no documentation on which server(s) this event is fired on (master or slave) or which server should contain the config setting.
I have the "History Engine" enabled on both of my servers for all databases like so:
<Engines.HistoryEngine.Storage>
<obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
<param connectionStringName="$(id)">
</param>
</obj>
</Engines.HistoryEngine.Storage>
As a test, I added a custom class to the publish:end:remote event on both servers. The class simply logs "Hello World" via Log.Info(), but nothing shows up.
I am using Sitecore 6.4.1 (rev. 101221).
UPDATE 1
I have read the latest Scaling guide and instituted all of the required configuration changes. Both our single Staging/CM server and (2) Prod/CD servers have EnableEventQueues set to true and the ScalabilitySettings.config is in place on all instances. That said, I believe the issue is that Sitecore is storing these queued events in the core database. Our CD servers are isolated from the staging core database and they are only linked to Staging via the "web" database. Should I be storing these queued events in the production 'web' database like so...
/eventing/providers/add[#name="sitecore"]
... and set the following attribute: systemDatabaseName="coreweb"
UPDATE 2
I have set the eventing provider to use the (shared) production 'web' database and I now see event queues pouring into the EventQueue table. There are around 60 records for the "PublishEndRemoteEvent" event in that table at any given time. All of these events have the "InstanceName" set to my Staging instance name. "RaiseLocally" is set to FALSE and "RaiseGlobally" set to TRUE. Oddly, the "Created" date for new events are somehow 7 hours in the future. Our Staging server is located only 3 hours ahead of where I work. I'm thinking this time difference might be the culprit.
Be sure you have the "EnableEventQueues" setting set to true in both web.config files. You'll find it in the /sitecore/settings section of the web.config.
See my post in this thread on the SDN forum for more details:
http://sdn.sitecore.net/forum//ShowPost.aspx?PostID=34284
You may also want to check out the Scaling Guide document on SDN (it was recently updated):
http://sdn.sitecore.net/upload/sitecore6/64/scaling_guide_sc63-64-usletter.pdf
Time you looking at is stored in UTC. Because of this you shouldn't have problems even if your servers are situated on different continents.