Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

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

Comments

@qedi-r
Copy link

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?

@snicker
Copy link
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

@cantino
Copy link
Member

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
Copy link
Author

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.

@cantino
Copy link
Member

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"
}

@0xdevalias
Copy link
Member

Ref: #197

@0xdevalias 0xdevalias changed the title Scheduling Events in the Future Delayed Reaction Agent (Scheduling Events in the Future) Jun 1, 2014
@virtadpt
Copy link
Collaborator

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.

@cantino
Copy link
Member

cantino commented Feb 12, 2015

This seems like a pretty simple agent to add.

@cantino
Copy link
Member

cantino commented Feb 14, 2016

We have a DelayAgent now.

@cantino cantino closed this as completed Feb 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants