I have a custom job. It works fine on staging server, after moving to production it is not working. It shows in Central Administration "Job Definitions" I can open it and click "Run now" but it has no effect = still is visible in "Job Definitions" and not visible in "Job History" or "Running jobs"
I have:
- restarted OWSTIMER
- iisresets
- browsed ULS for info (no info)
- checked event viewer (no info)
The difference between staging and production is that staging contains only one webapplication and production more.
Could it be that SPJobLockType.ContentDatabase is wrong here? Or is it something else?
Jobs code:
public class PropagacjaDanychLekuJob : SPJobDefinition
{
public const string JobName = "PropagacjaDanychLekuJob";
[Persisted()]
private int _lekId;
[Persisted()]
private string _numerKatalogowy;
[Persisted()]
private string _wielkoscOpakowania;
[Persisted()]
private string _stezenie;
[Persisted()]
private double _cenaKatalogowa;
[Persisted()]
private DateTime _zmianaOdDaty;
public PropagacjaDanychLekuJob(string name, SPWebApplication webApplication, SPServer server, SPJobLockType lockType) : base(name, webApplication, server, lockType)
{
}
public PropagacjaDanychLekuJob(SPWebApplication webApp) : base(JobName, webApp, null, SPJobLockType.Job)
{
}
public PropagacjaDanychLekuJob(SPWebApplication webApp, int lekId, string numerKatalogowy, string wielkoscOpakowania, string stezenie, double cenaKatalogowa, DateTime zmianaOdDaty)
: base(JobName, webApp, null, SPJobLockType.ContentDatabase)
{
Title = "Aktualizacja po zmiane leku o Id " + lekId;
_lekId = lekId;
_numerKatalogowy = numerKatalogowy;
_wielkoscOpakowania = wielkoscOpakowania;
_stezenie = stezenie;
_cenaKatalogowa = cenaKatalogowa;
_zmianaOdDaty = zmianaOdDaty;
}
public PropagacjaDanychLekuJob() : base()
{
}
#region Overrides of SPJobDefinition
public override void Execute(Guid targetInstanceId)
{
SPWebApplication webApp = this.Parent as SPWebApplication;
//SPListItem lek = webApp.Sites[0].RootWeb.Lists["Leki"].GetItemById(_lekId);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(webApp.Sites[0].ID))
{
using (SPWeb web = site.OpenWeb())
{
//my operations
}
}
});
}
#endregion
}
}
Execution in my event receiver:
PropagacjaDanychLekuJob job = new PropagacjaDanychLekuJob(properties.Web.Site.WebApplication,
properties.ListItemId,
numerKatalogowy,
wielkoscOpakowania,
stezenie,
cenaKatalogowa,
DateTime.Parse(propagacjaOd));
//job.Execute(Guid.Empty);
SPOneTimeSchedule spOneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);
job.Schedule = spOneTimeSchedule;
job.Update();