Can I schedule an agent in VOLTTRON to start at certain time? - volttron

Is it possible to start and then stop an agent by schedule, say run at 12 PM and then stop at 1 PM everyday. Thanks.

You have several options.
You can do as Craig suggests and start and stop it with a cron job. I don't like this idea as it goes against the purpose of an agent which should be always on.
Your agent can watch for device publishes to start appearing with timestamps that fall within the desired block of time (this is a common method).
Your agent can schedule devices for the desired block of time (if you are going to be sending control signals) and then subscribe to the schedule announce topic and watch for your schedule start.
You can schedule a periodic function call to be triggered at the start of the block.
Like 4 you can use schedule instead of periodic. You have to schedule the next event as schedule will only call the callback once, but it is useful for events that change dynamically during run time. The actuator agent uses this for publishing schedule states.
In 2-5 the agent will remain dormant for most of the time and only be become active during the allotted time.

One way is to set up a cron job that executes volttron-ctl start agent_uuid to start it...then another one that stops it.
The other way would involve just leaving the agent running and adding a periodic that can run every 24 hours, which would execute 24 hours from when you started the agent.

Related

GCP Cloud Scheduler run HTTP App Engine Jon one at a time

Our AppEngine, written in Python, reads conditionally from BigQuery Table and writes to another BigQuery Source Table.
The above App Engine is triggered by a Cloud Scheduler Job every 15 minutes.
A few times there are multiple Cloud Scheduler Jobs running that cause duplicates in the Source Table.
How do we overcome the above, please?
We're expecting the Cloud Job Scheduler to run the Job one at a time
It seems what you want is that a job is not run (or is paused) if another is still running. If this summary is correct, then something you could consider is...
When you start the job, check the DB for a flag. If the flag isn't there, then you set the flag and the job starts running. When the job is done running, it deletes the flag.
In say 15 minutes, when another job tries to start, it checks for the flag. If it's there, it means the job can't run. You can pause it (sleep) for X seconds/minutes (you have to figure out how to back-off). If the flag isn't there, it runs

Google Appengine: How to schedule a task to run once at a time of the day

I am faced with a situation where I want a user to perform an action and have the option to revert the action before the next 24 hours, else the action would be executed. The only solution I have been able to come up with is to use a Cron Job and schedule it for a particular time of the day and in the Job I would check for all actions that their scheduled time has passed then execute them. But the action does not happen very often and thus having a Cron job running does not appear to be a good solution to me as I am not even sure of the cost implication.
What I want to do is that whenever a user clicks on the action a Job should be scheduled and once that action is executed the schedule should be cancelled. Is it possible to do this with Cron Job? If no what alternative does GAE provide?
When a request is scheduled by a cron job it's handled as one normal request, from the quota/billing perspective. I suppose your applications gets much more requests per day, so plus one request shouldn't be a matter, unless your application is quite heavyweight.
I'd prefer cron over deferred tasks, because the latter is more convoluted. A cron job most likely would query the datastore then do something or not. It's easier to keep track or manage the state of the datastore than keep track of deferred tasks.
You have two options:
(1) Run a cron-job once per hour (for example). Execute all actions that have more than 24 hours since time of their creation.
(2) When an action is stored, create a task using a DeferredTask API. Give this task a name (e.g. an ID of an action), in case you need to cancel it. Add this task to a queue with a delay of 24 hours. Java example:
Queue queue = QueueFactory.getDefaultQueue();
// Wait 24 hours to run
queue.add(TaskOptions.Builder.withPayload(new MyTask())
.name(taskName).etaMillis(System.currentTimeMillis() + (24 * 60 * 60 * 1000));

salesforce trigger or schedule invoke after a period of time

I looked into salesforce trigger and scheduler is there any way i can create a scheduler to repeat itself for an hour or the time i configured in the screen.
Schedule should stop automatically after the given time.
inputs will be
Start time
Frequency
End time(This where the schedule should stop executing)
if you can provide a sample code will be great

App Engine Cron.yaml run multiple instances of a script

How can one run multiple instances of a Script Using Google App Engine's Cron system?
By default, it will run, then wait the specified interval before running again, which means that only one instance runs. What i am looking for is how one can get a script that takes 2+ minutes to run start a new instance every 30-60 seconds regardless of if it is running already or not, which does assume the script does not interfere with itself if multiple instances are running. this would effectively allow the script to deal with several times more information in the same period of time.
Edit, Completely reworded the question.
You only get resolution to the minute. To get finer-grained, you'll need instances that know whether they should handle the request from chron immediately, of if they'll have to sleep 30 seconds first. A 30 second sleep uses up half of the 60 second request deadline. Depending on the workload you expect to handle, this might require that you use Modules.
By the way, I'm not aware of any guarantee that a job scheduled for 01:00 will fire at exactly 01:00:00 (and not at, say, 01:00:03).
Since the cron service doesn't allow intervals below 1 min you'd need to achieve staggering script launching in a different manner.
One possibility would be to have a cron entry handler running every 2 mins which internally sleeps for 30 seconds (or as low as your "few seconds of each-other" requirements are) between triggering the respective script instance launches.
Note: the sleeps would probably burn into your Instance Hours usage. You might be able to incorporate the staggered triggering logic into some other long-living task you may have instead of simply sleeping.
To decouple the actual script execution from the cron handler (or the other long-living task) execution you could use dedicated task queues for each script instance, with queue handlers sharing the actual script code if needed. The actual triggering would be done by enqueueing tasks in the respective script instance queue. As a bonus you may further control each script instance executions by customizing the respective queue configuration.
Note: if your script execution time exceeds the 2 minutes cron period you may need to take extra precautions in the queue configurations as there can be extra delays (due to queueing) which could push lauching of the respective script instance closer to the next instance launch.
Working off Dave W. Smith's answer, The Line would be
every 1 minute from 00:00 to 23:59
Which means that it would create a new instance every minute, even if the script takes longer than a minute to run. It does seem that specifying seconds is not possible.

[google-app-engine]Cron Error - Launching tasks every few seconds instead of the specified frequency

I run an application that usually triggers a heavy update every 2 hours, by queuing heavy tasks, using the cron mecanism. This has been working well for months.
However, the december 16th of 2012, this url has been called (by user-agent AppEngine-Google) every few seconds between 15:17 and 15:51, launching hundreds of heavy tasks. This resulted in an explosion of my quotas and forced me to switch to the paid version of the application, in order for my website to stay alive.
Anybody having the same issue? Any idea of what happened and how I could avoid this problem in the future?
I had the same issue.
I don't have an answer, but I think this is a task queue problem.
I have 4 cron jobs and some task queue tasks piled up. Everything was normal until 14:05Z (16th 6:05 PST?).
At 14:06Z and 14:07Z, two of my cron jobs were called (at their scheduled times) and finished with 200. After that, AppEngine-Google started to call the same jobs few times per every minutes. The disorder vanished after 14:50Z and no issues right now.
During the period, one of my task queue tasks was called at 14:11Z and finished with 503 (this was an expected failure). The task was scheduled to retry some hours later, but was called hundreds of times in an hour. The task's retry count was not incremented.
My guess is that something went wrong in task queues ("__cron" and, for me, "default") and the tasks were not removed until 14:50Z.
My app's App ID is vidssage.

Resources