salesforce trigger or schedule invoke after a period of time - salesforce

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

Related

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

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.

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.

How to create scheduled job that runs every minute in apex salesforce

I am planning to create a scheduled job using scheduled apex in salesforce. I know that we can write and run the job for every one hour. I would like to know if there is a way we can run the code for every minute instead of every one hour.
I know the following code will work fine for every one hour.
System.schedule('Scheduled Job', '0 15 * * * ?', new scheduledJob());
You can't schedule by the second. The smallest hypothetical schedule you can perform with a single Scheduleable interface is once an hour. if you need a smaller time frame than this, use an external integration, a trigger, or an outbound message (using Workflow Rules)

How Google App Engine Java Task Queues can be used for mass scheduling for users?

I am focusing GAE-J for developing a Java web application.
I have a scenario where user will create his schedule for set of reminders. And I have to send emails on that particular date/time.
I can not create thread on GAE. So I have the solution of Task Queues.
So can I achieve this functionality with Task Queues. User will create tasks. And App Engine will execute it on specific date and time.
Thanks
Although using the task queue directly, as Chris suggests, will work, for longer reminder periods (eg, 30+ days) and in cases where the reminder might be modified, a more indirect approach is probably wise.
What I would recommend is storing reminders in the datastore, and then taking one of a few approaches, depending on your requirements:
Run a regular cron job (say, hourly) that fetches a list of reminders coming up in the next interval, and schedules task queue tasks for each.
Have a single task that you schedule to be run at the time the next reminder (system-wide) is due, which sends out the reminder(s) and then enqueues a new task for the next reminder that's due.
Run a backend, as Chris suggests, which regularly scans the datastore for upcoming reminders.
In all the above cases, you'll probably need some special case code for when a user sets a reminder in less than the minimum polling interval you've set - probably enqueuing a task directly. You'll also want to consider batching up the sending of reminders, to minimize tasks and wallclock time consumed.
You can do this with Task Queues - basically when you receive the request 'remind me at date/time X by sending an email', you create a new task with the following basic structure:
if current time is close to or past the given date/time X:
send the email
else
fail this task
If the reminder time is far in the future, the first few times the task is scheduled, it will fail and be scheduled for later. The downside of this approach is that it doesn't guarantee that the task will run exactly when the reminder is supposed to be sent - it may be a little while before or afterwards. You could slim down this window by taking into account that your task can run for 10 minutes, so if you're within 10 minutes of the reminder time, sleep until the right time and then send the e-mail.
If the reminders have to be sent out as close in time as possible then just use a Backend - keep an instance running forever and dispatch all reminders to it, and it can continuously look at all reminders it has to send out and send them out at exactly the right time.

Introducing randomness of time using cron and task queue

I'm looking for some engineering creativity to solve a problem on Google App Engine.
I have a small number of jobs that run periodically, but I'd like the jobs to be executed at random times. So instead of running a job every Tuesday at 2:00pm, I'd like it to run every Tuesday "between 2:00pm and 5:00pm".
Currently, I'm using the following algorithm...
Cron job runs every Tuesday at 2:00pm
The cron handler finds a list of specific jobs to run and creates a task queue event for each discrete task.
The respective task queue handler decides if it should actually run by picking a random number between one and N. If the random number is X, the job gets executed. Otherwise, it creates a new task queue event to try again. Each task has a maximum number of queue attempts to guarantee that the job actually completes at some point.
I've realized that another solution would be to create a task queue that has a very slow rate, and when the cron job fills the queue, it randomly re-orders the list of tasks before doing so.
Any ideas from App Engine users?
Have a cron job at 2 pm that queues a task with a random countdown between 0 and 3 hours?

Resources