<?xml version="1.0" encoding="ISO-8859-1"?>
<ss:description type="trigger" id="com.autodesk.XML.MinuteTrigger"
		xmlns:ss="urn:Autodesk:Server"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="urn:Autodesk:Server Schema.xsd">
	<ss:title>
		Minutes
	</ss:title>
	<ss:options>
		<ss:label/>
		<ss:option name="minutes">
			<ss:label>Minutes</ss:label>
			<ss:tooltip>
				Enter how often the trigger will run, in minutes.
			</ss:tooltip>
			<!-- Allow specifying up to once a day in minutes. -->
			<ss:integer min="1" max="1440" default="5" />
		</ss:option>
	</ss:options>
	<ss:code>
from com.autodesk.actions import Workflow
import time

# This first function is a little more accurate than the second. It works
# by checking each minute if the current minute in the hour is an increment
# of the given minutes value. If the workflow takes longer to run than the
# given increment then increments are skipped. So for example, if minutes
# is 5, then at the hour, five past, 10 past, etc. the workflow will run.
# But if the workflow started at 5 past is still running at 10 past the
# workflow won't run again until 15 past, assuming that the one started
# at 5 past has finished it's work.
# TODO: Rather than using sleep it would be better to use a signal.
def first(workflow, minutes):
	while not workflow.stopRequested():
		if time.localtime()[4] % minutes == 0:
			workflow.trigger()
		time.sleep(60)

# This second function runs the workflow and then sleeps for the given
# number of minutes. It's less accurate than the first method as the
# duration between successive runs of the workflow will be the given number
# of minutes plus the time it takes to run the workflow.
# TODO: Again it would be better to use a signal.
def second(workflow, minutes):
	naptime = 60*minutes
	while not workflow.stopRequested():
		workflow.trigger()
		time.sleep(naptime)

def main(workflow, minutes):
	if workflow == None or minutes == None:
		return

	if 60 % minutes == 0:
		first(workflow, minutes)
	else:
		second(workflow, minutes)

	</ss:code>
</ss:description>
