Integrate Scheduling into workflow

Topics: Core
Jun 21, 2013 at 10:24 AM
Hi There

I see in the 1.x version the scheduling module is no longer available.
It can be downloaded from the gallery but this is very limited as it can only be accessed in the rules module and what you ca do in that module is very limited.

Is there talk about integrating a scheduler into the workflow module as I have a situation where I would like to make a web request at specific times during the day.

The timer would work for this but you cannot start the workflow process with a timer.

Any thoughts

Stanton
Coordinator
Jun 21, 2013 at 5:04 PM
Sure, forgot about this one. I have implemented the Signal even for this exact purpose. And then extended it so that it can be used by HTTP Callbacks.

What you could do is to take the code from Brendan who wrote the previous scheduler module, but just the part creating schedules, and it would just trigger a named Signal when the timer is hit.
Jul 23, 2013 at 11:13 AM
Edited Jul 23, 2013 at 2:16 PM
Hi There

I have created the schedules and they are running correctly.
I am trying to trigger a signal.

Currently I am using the ISignals interface. Is this correct how would I create a Signal so that it is picked up in work flow.
namespace Hellocomputer.Toyota.DataImport.Services
{
    using Orchard;
    using System;
    using Orchard.Caching;
    using Orchard.Tasks;
    using Hellocomputer.Toyota.DataImport.Models;
    using Orchard.Data;
    using Orchard.Services;
    using NCrontab;
    using Orchard.Logging;

    public class SchedulerTask : Component, IBackgroundTask
    {
        private readonly IRepository<ScheduleRecord> _repository;
        private readonly IClock _clock;

        private readonly ISignals _signals;

        private readonly IOrchardServices _services;

        public SchedulerTask(IRepository<ScheduleRecord> repository, 
            IClock clock,
            ISignals signals
           )
        {
            _repository = repository;            
            _clock = clock;
            _signals = signals;
        }

        public void Sweep()
        {
            var now = DateTime.Now;            
            var records = _repository.Fetch(x => x.Enabled && x.StartDateUtc <= now && x.NextOccurrenceUtc <= now);

            foreach (var record in records)
            {
                try
                {      
                    var cronTab = CrontabSchedule.Parse(record.CronExpression);
                    var nextOccurrence = record.EndDateUtc.HasValue ? cronTab.GetNextOccurrence(now, record.EndDateUtc.Value) : cronTab.GetNextOccurrence(now);

                    if (nextOccurrence != DateTime.MinValue)
                    {
                        record.NextOccurrenceUtc = nextOccurrence;
                        _repository.Update(record);
                    }

                    if (record.EndDateUtc.HasValue && record.EndDateUtc.Value <= now)
                    {
                        record.Enabled = false;
                        _repository.Update(record);
                    }

                    _signals.Trigger(record.Signal);
               
                }
                catch (Exception ex)
                {
                   Logger.Error(ex, "Exception occurred during triggering of schedule '{0}'", record.Name);
                }
            }            
        }
    }
}
Coordinator
Jul 23, 2013 at 2:41 PM
I think there is another one. ISignals is the Cache one, which has nothing to do with the workflow, even if the name is similar.