I have followed this post to build a scheduled task at the end of each month
Scheduled tasks using Orchard CMS
private void ScheduleNextTask(DateTime date)
{
if (date > DateTime.UtcNow)
{
var tasks = _taskManager.GetTasks(TaskType);
if (tasks == null || tasks.Count() == 0)
_taskManager.CreateTask(TaskType, date, null);
}
}
This works fine in orchard 1.4, but when I upgraded to 1.5.1, It thorws an error everytime I enable/disable module, change themes, or edit source code while debugging. This is the error
Cannot access a disposed object.Object name: 'TransactionScope'
If I comment all the lines access to _taskManager in method ScheduleNextTask, no more error. I don't know why but I need the task running, so anyone can give me an advice?
Related
Im trying to retrieve the schedule of the vNext BuildDefinitions through my C# Application.
I can retrieve the BuildDefinition objects that i need.
List<BuildDefinitionReference> builddefs = buildClient.GetDefinitionsAsync().Result;
and
var buildDef = buildClient.GetFullDefinitionsAsync(project: project,
name: buildDefName).Result.ToArray();
But when looking at the BuildDefinition.Trigger information, this does not seem to contain what i need.
Simular to the XAML builds, i want to be able to read the BuildDefinition.Schedules, to see when each build is scheduled.
Who knows where this information is currently kept ?
Update:
Fixed the issue by converting the BuildTrigger to a ScheduleTrigger
if (buildDefinition.Triggers != null)
{
foreach (BuildTrigger trigger in buildDefinition.Triggers)
{
if (trigger is ScheduleTrigger)
{
ScheduleTrigger scheduleTrigger = trigger as ScheduleTrigger;
foreach (var schedule in scheduleTrigger.Schedules)
{
//Do magic
}
}
}
}
Update the Microsoft.TeamFoundationServer.ExtendedClient package to the latest version and the GetFullDefinitionsAsync method should return the schedules information, that are stored in Triggers property instead of Schedules property.
You could use Rest API to Get a build definition, a sample:
GET https://tfsserver:8080/tfs/DefaultCollection/Fabrikam-Fiber-Git/_apis/build/definitions/29?api-version=2.0
Then you will get a response as below which include trigger information:
"triggers": [
{
"schedules": [
{
"branchFilters": [
"+$/MyFirstProject/Test"
],
"timeZoneId": "UTC",
"startHours": 3,
"startMinutes": 0,
"daysToBuild": "all",
"scheduleJobId": "18316444-edbb-479d-950d-7714ba39d3d6",
"scheduleOnlyWithChanges": true
}
],
"triggerType": "schedule"
}
And the each member for your reference:
Members
branchFilters: string[].
daysToBuild: ScheduleDays. Days for a build (flags enum for days of the week)
scheduleJobId: string. The Job ID of the Scheduled job that will queue the scheduled build. Since a single trigger can have multiple
schedules and we want a single job to process a single schedule (since
each schedule has a list of branches to build), the schedule itself
needs to define the Job Id. This value will be filled in when a
definition is added or updated. The UI does not provide it or use it.
startHours: number. Local timezone hour to start
startMinutes: number. Local timezone minute to start
timeZoneId: string. Time zone of the build schedule (string representation of the time zone id)
Details please refer Schedule Rest API.
developing application using Grails 2.5.1 i used Quartz plugin , and created a job successfully , but when i inject a service in this job i get org.quartz.JobExecutionException: java.lang.NullPointerException
here is the Job's code:
class EveryMonthJob {
def usersUtilsService
static triggers = {
cron name: 'EveryOneMonthJob', cronExpression: "* 31 2 L * ?"
}
def execute() {
usersUtilsService.testMe() // getting the exception here
}
}
There are any number of reasons that might not work. If you are creating an instance of the job yourself (as opposed to Spring creating the instance and subjecting it to dependency injection), that would explain why the reference is null. Another explanation could be that you have the property name wrong.
See the project at https://github.com/jeffbrown/sherifquestion. That is a Grails 2.5.1 app that does just what you are describing and it works fine. See https://github.com/jeffbrown/sherifquestion/blob/e0179f836314dccb5f83861ae8466bfd99717995/grails-app/jobs/demo/EveryMonthJob.groovy which looks like this:
class EveryMonthJob {
// generally I would statically type this property but
// am leaving it dynamically typed top be consistent with
// a question being asked...
def usersUtilsService
static triggers = {
simple repeatInterval: 5000l // execute job once in 5 seconds
}
def execute() {
usersUtilsService.testMe() // this works fine
}
}
I am trying to get userid who approved an "input" step in workflow jenkins groovy script. Below is the sample script
node('node1'){
stage "test"
input message: 'test'
}
In the workflow UI if a person hits "thumbs up" I want to print his userid in the log. I dont see any option to do it.
def cause = currentBuild.rawBuild.getCause(Cause.UserIdCause)
cause.userId
will print the person who started the build. I have googled this for days but i am not finding anything. Any help here will be greatly appreciated :)
This Jira issue describes how this is likely to work going forward, however it is still open.
In the meantime, the approach of getting the latest ApproverAction via the build actions API was suggested on #Jenkins IRC recently and should work, note it's not sandbox safe.
Something along the lines of the below for getting the most recent approver:
#NonCPS
def getLatestApprover() {
def latest = null
// this returns a CopyOnWriteArrayList, safe for iteration
def acts = currentBuild.rawBuild.getAllActions()
for (act in acts) {
if (act instanceof org.jenkinsci.plugins.workflow.support.steps.input.ApproverAction) {
latest = act.userId
}
}
return latest
}
The JIRA incident referenced u-phoria has been resolved and the fix released.
By setting the submitterParameter to a value, the variable specified by submitterParameter will be populated with the Jenkins user ID that responded to the input field.
I have created a Custom Timer job which is added when a feature gets activated. The feature does get activated without any exception. But the timer job is not being listed in Timer Job definitions on Central Admin.
The same is working on Staging Server but I am facing this in Production Server.
I am working on Sharepoint2007.
Below is what I have done in Feature Activated.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWeb parentWeb = properties.Feature.Parent as SPWeb;
UpdateEmpReferralListTimer taskJob;
SPMinuteSchedule schedule;
foreach (SPJobDefinition job in parentWeb.Site.WebApplication.JobDefinitions)
{
if (job.Name == "xyz")
job.Delete();
}
parentWeb = properties.Feature.Parent as SPWeb;
taskJob = new UpdateEmpReferralListTimer("xyz", parentWeb.Site.WebApplication);
schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
taskJob.Schedule = schedule;
taskJob.Update();
});
}
catch (Exception Ex)
{
string str = Ex.Message.ToString();
}
}
Scope of Feature is "Web"
To my knowledge trying to perform tasks that require administrator privilegies (like creating timer job) should not work from site level feature activation callback if SharePoint accounts set up properly. Account that web sites run under normally does not have adminstrative privilegies.
It likely works on your staging server due to all accounts having the same privileges. Check out SharePoint logs on your production server to see what exception is (after removing code that eats exception without rethrowing/reporting it - catch (Exception Ex) {...}).
how do you know that your feature is getting activated without error. your code has try/catch block and you are doing nothing in catch block. if your code throwing any error, your catch block will suppress it.
add this line in your catch block and check sharepoint log.
Microsoft.SharePoint.Administration.SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Development Debugging", TraceSeverity.Unexpected, EventSeverity.Information), TraceSeverity.Unexpected, str, null);
you can find log files in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS folder
I have the web application in visual studio web express and having db in sql server express.
I want to perform insert 100 records on 5:00 PM daily.web application is developed in asp.net MVC and vb.net. and deployed on server machine with IIS 7.5. what logic i should follow?
For me i'm using this approach and it's good till now :)
I've enum with Tasks to do and the time for the task to restart and this time in seconds like this:
public enum ScheduledTasks
{
CleanGameRequests = 120,
AnotherTask = 30,
}
Then i start all my tasks in the Application_Start to ensure that the task will execute while my application is run
protected void Application_Start()
{
...............
// Add the tasks on Application starts
AddTask(ScheduledTasks.CleanGameRequests);
AddTask(ScheduledTasks.AnotherTask);
}
OK now here is the trick :)
in the AddTask method i just add new empty item to cache and set the AbsoluteExpiration for it according to the task time and the call the suitable method for this task.
Actually my i couldn't explain the idea very clear but here is the code:
private static CacheItemRemovedCallback _onCacheRemove;
private void AddTask(ScheduledTasks task)
{
// Add my `CacheItemRemoved` method to be called on cache removed
_onCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
// Add new key to the cache with the name of this task
// and Expiration time acccordin to the task
HttpRuntime.Cache.Insert(task.ToString(), (int)task, null,
DateTime.Now.AddSeconds((int)task), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, _onCacheRemove);
}
Then all I've to do is to select suitable method for each task in the CacheItemRemoved method :
public void CacheItemRemoved(string key, object time, CacheItemRemovedReason r)
{
//Get Task enum object
var task = (ScheduledTasks)Enum.Parse(typeof(ScheduledTasks), key);
// Select the suitable method to depending on the Task Enum object
switch (task)
{
case ScheduledTasks.CleanGameRequests:
GameRequest.CleanUp();
break;
case ScheduledTasks.AnotherTask:
Service.AnotherTask();
break;
}
// Don't forget to re-add the task to the cache to do it again and again
AddTask(task);
}
Last thing remain for your case is to check the time if it's 5:00 PM and i advice you to put this check in your Service class.
Hope this helped you :)
Since you are using Sql server express edition you can't create scheduled jobs in sql side. But you can try other options like.
Quartz.Net
Service Broker approach
Windows services (If your hosting provider allows)