Execution scheduler

Dear All,
I'm writing a tango device which needs to execute different operations at later time, resembling the Unix at command, but with routines or methods as argument, not shell commands.

Does a Tango standard approach already exist? In case it does not already exist, which is the best approach? I have already developed a C scheduler for a non Tango project: can it be used safely?
As an alternative I can use a dummy attribute polling, but I fear this can be cumbersome.

Thanks in advance for your answers!
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Dear Carlo,

we briefly discussed a similar feature (e.g. scheduling command execution at future time) in recent SKA TANGO meeting in Trieste. Tango developers told us that such feature is not present in current Tango release (v9) but suggested to have a look at Sardana Macro device. Alternatively, if you want to develop something new, the suggestion was to create a custom device server with additional user threads in which you actually execute the scheduled task.

I'm also currently implementing a scheduler. Here's the (maybe-to-simple) approach I'm following (at least in C++) to schedule commands implemented in other devices (still under implementation):

- Define a device server with an additional omni_thread and a pool of worker threads
- Define a priority_queue of Task objects in the device, e.g. storing cmd name/args, time start/stop, device address
- Whenever a schedule command request is called, a task is pushed in the queue (and queue monitor thread is wake up)
- In the additional thread monitor the priority queue, checking top task activation time against local time. Whenever the activation time is reached, execute the command specified in the task, otherwise wait till activation time
- Command execution is executed in the worker threads, NOT in the same omni_thread. I'm using zmq inproc socket trasport to share data (and commanding task execution) across omni_thread and worker threads
- Provide heartbeat mechanism for queue and worker threads

I'm a novice in TANGO, so I hope that Tango experts could give their view on this point.

Cheers,

Simone
****************************************************************
Simone Riggi
INAF, Osservatorio Astrofisico di Catania
Via S. Sofia 78
95123, Catania - Italy
phone: +39 095 7332 extension 282
e-mail: simone.riggi@gmail.com,
sriggi@oact.inaf.it
skype: simone.riggi
****************************************************************
I'm also currently implementing a scheduler. Here's the (maybe-to-simple) approach I'm following (at least in C++) to schedule commands implemented in other devices (still under implementation):

Dear Simone

I'm aware of SKA conference and of the suggestion we received there. But as you said the Sardana macro server is not suited to SKA situation. So I asked for a pure scheduler.

We are thinking to modify our already working scheduler to yat thread. I think the best approach is to share ideas, code and approaches. I will make available our code as discussion basis.

Thank you for your answer
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Dear Carlo + Simone,
first of all your approach is valid if it solves your problem! However when we have had a similar problem we used the MacroServer from Sardana:
http://www.sardana-controls.org/en/stable/devel/overview/overview_macroserver.html
Our need was to execute a sequence of commands as a script with the need to pause or stop it and get feedback about the progress of execution. We use Python as scripting language. Maybe adding the "sched" module to your script you can solve your problem? Up till now we have not had this need. If we need execute a command periodically we configure it with polling but this is different to your need I think.

In your case I am not sure what you mean by "action" - is it one single command in a server or a sequence of commands? I could imagine doing a single command at a fixed time but how to interrupt it? How to get the results?
What are the requirements of your use case? Knowing this will enable us to see if it can be added as a standard feature to device servers. Are you looking for something like a cron but for commands and/or attributes? The job of scheduling might be better delegated to a scheduler which calls tango devices. If you have something which is generic for doing this it could be interesting for others to share the solution.

Ciao
Andy
Dear all,

In Sardana there is no such scheduler - we have not faced this requireemnt yet.
The sardana macros - python procedures (developed as either classes or functions) are executed by python worker threads inside of the MacroServer. In order to provide the features like the ones Andy was listing: progress updates, results, pause, resume and many others, the running macro is assigned to the Door Tango device. The restriction is that only one macro can run simultaneously on a Door (a stack of macro execution is possible: macro A runs macro B which runs macro C…)
Currently there is no way to start the macro execution other than calling the RunMacro command on the Door Tango device. This one executes the procedure as soon as a worker thread is available. Your macro of course can wait for the correct time to start performing the actions.
It would be great if you consider enhancing Sardana with the scheduler feature. We would be very happy to help in this development (I don't know if as active developers, but at least in the design discussions, code review and integration, clarification of any doubts…).

Cheers,
Zibi

PS. In the continuous scans development we have foreseen API for the acquisition triggers that should happen at a given time in the future (it is not yet implemented). But they will just execute the MeasurementGroup acquisition and not the macro.
Hello All,

I would like to share an approach for scheduling a task in Java.

Java has native support for scheduling tasks. As per my knowledge, this functionality can be achieved in following ways:

1. Using Timer class and TimerTask class
2. Using ExecutorService class and Executor class

Here's the snippet to show how we have used Timer class and TimerTask class in the code generated by POGO:


Timer timer = new Timer();

@Command(name="Test")
public void Test(String activationTime) throws DevFailed {
	if (activationTime != null) {
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				myOperation();
			}
		}, getDate(activationTime));
		}
	else {
		myOperation();
	}
}

private void myOperation() {
	//behavioural logic
}

private Date getDate(String dateStr) throws ParseException {
        DateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        return df.parse(dateStr);
}

I understand the discussion is as to how the scheduling functionality can be implemented in C++. However, just thought to highlight that there is a native support for it in Java.

This solution is outside the Tango domain, but it is simple to implement in the code.

Kind regards,
Jyotin

“We are what we repeatedly do. Excellence, then, is not an act, but a habit” - Aristotle
Po!
This solution is outside the Tango domain, but it is simple to implement in the code.

Kind regards,
Jyotin

“We are what we repeatedly do. Excellence, then, is not an act, but a habit” - Aristotle

Hi Jyotin,

Nice solution!

In fact it easy to implement a standalone server which will take target server as a parameter and schedule one (or more) it's command(s) for execution. Target server can be then in any language. Scheduler in java.

Through attributes of such scheduler one can define execution's delay, for instance.
Po!
I understand the discussion is as to how the scheduling functionality can be implemented in C++. However, just thought to highlight that there is a native support for it in Java.

This solution is outside the Tango domain, but it is simple to implement in the code.
Jyotin

Dear Jyotin,
Thank you for your solution, which seems nice to me.
Unfortunately we need a fast schedulerfor our C++ code and the Sardana solution does not include a sccheduler (as stated by Zibi).
Bye
Carlo
—-
Carlo Baffa INAF - Osservatorio Astrofisico di Arcetri
baffa@arcetri.astro.it Largo Fermi 5
http://www.arcetri.astro.it/~baffa/ I-50125-Firenze ITALY
Edited 3 years ago
Dear Carlo,
do you have a specification of your needs? I would be interested in reading them. It would be useful for us to know what has to be scheduled, how often, and what happens to the output, errors, logs etc. Are we talking about a cron type scheduler? If this is the case I would write a device server which implements similar functionalities as cron. Having it as a device server instead of standalone cron means is part of the control system and it can be configured using the standard tango tools.
Ciao
Andy
carlo
Po!
Unfortunately we need a fast scheduler for our C++ code

What "fast" means in this context?
 
Register or login to create to post a reply.