This project is read-only.

Integrate Scheduling into workflow

Topics: Core
Jun 21, 2013 at 11: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

Jun 21, 2013 at 6: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 12:13 PM
Edited Jul 23, 2013 at 3: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)
                    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;

                    if (record.EndDateUtc.HasValue && record.EndDateUtc.Value <= now)
                        record.Enabled = false;

                catch (Exception ex)
                   Logger.Error(ex, "Exception occurred during triggering of schedule '{0}'", record.Name);
Jul 23, 2013 at 3: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.
Jan 22, 2015 at 1:49 PM
I have forked Brendan's Scheduler module and updated it to use Workflow signals.