Delayed Reaction Agent (Scheduling Events in the Future) #174

Closed
qedi-r opened this Issue Mar 3, 2014 · 8 comments

Comments

Projects
None yet
5 participants

qedi-r commented Mar 3, 2014

I'm currently implementing a Weatherunderground Astronomy agent, so that I can trigger things based on sundown/sunrise, so I was wondering what is the best way to schedule events for some time in the future.

If say I knew that sundown was going to be at 6:04 pm, how could I schedule my agent from creating an event then?

Contributor

snicker commented Mar 3, 2014

I was going through a similar thought exercise today and thought that a DelayedReactionAgent would be cool. It would take a delay parameter in minutes or a time parameter for specifics and then pass through any queued events. Similar to how the DigestEmailAgent works, except it would need a hook to specify the agent schedule. Haven't dug into the code enough to see how that works

Owner

cantino commented Mar 4, 2014

Hey @qedi-r and @snicker: interesting use case! rufus-scheduler, which is what we use for bin/schedule.rb, is very powerful and we can probably figure out a way to wire through more expressive schedules. Would the you want a free-form schedule field that only fires once?

qedi-r commented Mar 4, 2014

Right now I am thinking an agent like this should be scheduled automatically, which is just a fancy way of saying a schedule of 2m, with a guard at the top of the agent's check that returns if we have figured out when the next sunrise and sunset are, and schedule those events properly.

I was investigating using the delayed_job gem we are using for async agents, but that doesn't quite feel right -- having access to rufus from an agent would make more sense to me.

Owner

cantino commented Mar 5, 2014

I did something like this using the JavaScriptAgent, but it's ugly. I like the idea of a DelayedReactionAgent that standardizes this, or (perhaps) of adding it as an option to any agent if it seems worth it.

The relevant JavaScriptAgent that I use filters the results from a PublicTransportAgent so that they only arrive during my morning commute. The JavaScriptAgent has a Credential called muni_alert_code that contains

Agent.receive = function() {
  var events = this.incomingEvents();
  var currentDate = new Date();
  var weekDay = currentDate.getDay();
  var offset = -8; // PST
  var now = new Date( new Date().getTime() + offset * 3600 * 1000).toUTCString().replace( / GMT$/, "" );
  if (weekDay > 0 && weekDay < 6 && now.match(/ 08:4/)) {
    for(var i = 0; i < events.length; i++) {
      this.createEvent({ message: "MUNI in " + parseInt((parseInt(events[i].payload.prediction.epochTime) - new Date().getTime()) / 1000 / 60) + " minutes" });
    }
  }
}

and then the Agent itself is just

{
  "code": "credential:muni_alert_code",
  "expected_receive_period_in_days": "2",
  "expected_update_period_in_days": "2"
}

qedi-r referenced this issue Mar 19, 2014

Closed

Pending events #195

Member

alias1 commented Jun 1, 2014

Ref: #197

alias1 referenced this issue Jun 1, 2014

Open

Official Agent Suggestions Thread #353

11 of 48 tasks complete

alias1 changed the title from Scheduling Events in the Future to Delayed Reaction Agent (Scheduling Events in the Future) Jun 1, 2014

Contributor

virtadpt commented Feb 12, 2015

I've just found that I have a use case for this as well: Say an every happens, and I want to trigger another agent two minutes after it happens. And maybe another agent five minutes after that if they're chained (or in parallel and just happen to act like they are). Maybe it consumes the event it's or in received, maybe it emits its item payload as an event. It would certainly save a lot of shell script hackery with --delay= if nothing else.

Owner

cantino commented Feb 12, 2015

This seems like a pretty simple agent to add.

Owner

cantino commented Feb 14, 2016

We have a DelayAgent now.

cantino closed this Feb 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment