Contents

  1. Introduction
  2. The test workflow
  3. Declaring evQueue object
  4. Launching a new instance
  5. Javascript events
  6. Monitoring instances

Introduction

This sample project aims at demonstrating interaction between javascript client side code and the evQueue core API.

You will learn how to asynchronously launch a new instance and display a dynamic status page.

Source code can be found in our sample project on GitHub.

This is a guide of the 'index.php' file.

The test workflow

For testing purposes, we have created a simple workflow (named 'sleep') that takes a 'time' parameter and then sleeps for this amount of seconds using the /bin/sleep command.

Workflow creation will not be covered here, please see the user documentation.

Declaring evQueue object

Declaration of the evQueue javascript object is pretty straightforward:

			evq = new evQueue('/evqueue-api.php');
		

Please see javascript object documentation for details.

Launching a new instance

			The following code retrieve the 'time' parameter value from the input and launches a new instance:
			$('#launch').click(function() {
				evq.ClearStatuses();
				
				var time = $('#time').val();
				evq.Launch('sleep',{time:time});
			});
		

We only allow one instance to run at the same time, so the status of old instances is cleared each time we launch a new instance. This is not mandatory and could be done as a separate action.

Javascript events

We have used two javascript events (evq-launch and evq-terminated) to prevent launching multiple workflows at the same time. This is not mandatory and you can remove this code:

			$(document).bind('evq-launch',function() {
				$('#launch').prop('disabled',true);
			});
			
			$(document).bind('evq-terminated',function() {
				$('#launch').prop('disabled',false);
			});
		

Monitoring instances

Here is the code used to display dynamically updated instances status:

			evq.MonitorStatus(function(instances) {
				...
			});
		

As the code is mainly frontend, it will not be detailed here and you can customize it to suit your needs.

Please note the ajax queries are only made if at least one instance is curruntly running.