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

Add SchedulerAgent, which periodically runs other agents. #459

Merged
merged 34 commits into from
Sep 8, 2014
Merged

Add SchedulerAgent, which periodically runs other agents. #459

merged 34 commits into from
Sep 8, 2014

Conversation

knu
Copy link
Member

@knu knu commented Aug 22, 2014

This is the core part of the solution to #444. As the first step, I've implemented SchedulerAgent that supports cron-style schedule. User can create SchedulerAgents as many as they want and bind target Agents to it. A master scheduler job in HuginnScheduler periodically checks for SchedulerAgents to create/update/delete the corresponding jobs as necessary.

We can add some additional agents later if needs be:

  • CalendarAgent: Runs target Agents if it is currently free or busy now in specified calendar(s).
  • RunnerAgent: Runs target Agents when it receives an event.

How do you feel about this direction?

@cantino
Copy link
Member

cantino commented Aug 22, 2014

This is very interesting.

Do you see different types of Agents needing to trigger other Agents as well? Generally, Agents are triggered by incoming events, but I can imagine that having a side-channel method of running Agents could be useful in the future. If we're going to make it generic-- chains and targets-- then we should be sure that there are enough use cases beyond the SchedulerAgent. Otherwise, a new Schedule object could have many Agents, but not be an Agent itself. What other uses do we foresee?

@knu
Copy link
Member Author

knu commented Aug 22, 2014

@cantino Yes, I have at least two in my mind as I named above. Their supposed use cases include the following:

  • A RunnerAgent that receives events from a PeakDetectorAgent and runs a WebsiteAgent: to crawl a news site to check for headlines immediately after some peak is detected.
  • A SchedulerAgent that runs a CalendarAgent that runs an agent to check the status of bus service: to get alerted of bus approaching only on a non-holiday weekdays, where the SchedulerAgent runs the CalendarAgent every 30 seconds in the morning on weekdays that checks the national holiday calendar (which should of course be cached for some time) to run the target agent only if it is not a holiday.

@knu
Copy link
Member Author

knu commented Aug 22, 2014

The only action that these "runner" agents take at the moment is "run", but there could also be "disable" and "enable". Agents that can run other agents may have options['action'] defaulted to "run" if we allow those additional actions.

@cantino
Copy link
Member

cantino commented Aug 22, 2014

That makes sense. I'll play with this and do a deeper review of the code soon!

# SchedulerAgent. By default, the use of the "second" field is
# restricted so that any value other than a single zero (which means
# "on the minute") is disallowed.
ENABLE_SECOND_PRECISION_SCHEDULE=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to prevent DOS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can still create as many agents as you want, though, I suppose only allowing an agent to run on the minute would demotivate potential abusers. Should I note that here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess? I suppose we could allow every 15 or 30 seconds. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine as long as you can document that nicely in the description. I cheated by omitting the seconds part completely. 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, multiples of fifteen are now allowed even when the option is disabled (default).

@knu
Copy link
Member Author

knu commented Aug 29, 2014

@cantino The s/target/control_target/g part is done. What do you think about the table name? #459 (comment)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) when pulling 05dd52d on knu:scheduler_agent into 4c938f1 on cantino:master.

@cantino cantino mentioned this pull request Sep 1, 2014
48 tasks

class Job
# Store an ID of SchedulerAgent in this job.
def scheduler_agent_id= id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

() please around the arguments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

()!

@cantino
Copy link
Member

cantino commented Sep 4, 2014

Looks great to me! Let me deploy this to my setup and let it run for a few days, then I think we'd be good to merge. Is there anything else you wanted to add to this?

@cantino
Copy link
Member

cantino commented Sep 4, 2014

If controlling Agents have a "Control targets" list, why do other Agents need to have a "Controllers" list. It seems like it'd make sense to have one or the other.

@knu
Copy link
Member Author

knu commented Sep 4, 2014

@cantino I'll make the field read-only then. When cloning an agent that has controllers, it may be important for user to see them in the form before saving it.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.72%) when pulling 23b0741 on knu:scheduler_agent into 5a82064 on cantino:master.

@knu
Copy link
Member Author

knu commented Sep 4, 2014

@cantino I think it's done by now!

@cantino
Copy link
Member

cantino commented Sep 4, 2014

Awesome! I'll play with it for a day or two and we can get it out :)

@cantino
Copy link
Member

cantino commented Sep 6, 2014

Seems to be working well!

@knu
Copy link
Member Author

knu commented Sep 8, 2014

OK, so I'm going to merge this later and take the next step forward!

@cantino
Copy link
Member

cantino commented Sep 8, 2014

Sounds good!

@knu knu merged commit 23b0741 into huginn:master Sep 8, 2014
@knu
Copy link
Member Author

knu commented Sep 8, 2014

Done! Should cover #67.

@knu
Copy link
Member Author

knu commented Sep 8, 2014

This thread was closed, but I've added Agent ideas found here to the list in #353.

@knu knu deleted the scheduler_agent branch September 10, 2014 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants