Jump to content
  • Generating Schedules for Spotfire Automation Services Job


    Introduction

    In Spotfire 10 and higher, it is possible to schedule an Automation Services job, saved in the library from the Spotfire administration interface. This allows for scheduling of tasks to be run at particular times on specified days. However, another common need is to be able to run an automation services job regularly based upon a time interval, for example, every 5 minutes. Currently, this is not possible from the administration interface but due to Spotfire being a highly extendable and customizable platform, it offers the capability to create custom schedules which can be uploaded directly to the server. 

    This wiki article explains how custom schedules can be created using IronPython script and easily upload them to the Spotfire server.

    Configuring the Schedules

    Using the Spotfire Analysis that is downloadable from the bottom of this Wiki article, one can easily configure the parameter for schedules.

    • From Tools > Automation Service Job Builder copy the library path of the Automation job that you would like to create schedules for.
    • Enter the copied path in the Automation Job Location field.
    • Select the Start time in hh:mm:ss format.
    • From the dropdown, select the timezone.
    • Enter the interval in minutes to set the repeat frequency  of schedules.
    • Select Days using drag select or CTRL key hold and select.
    • Finally, select the folder location (without ?\? towards the end) in which you want to save the schedules.json file.

    After clicking the "Generate JSON" button, a file named "schedules.json" will be generated and saved in the specified location. (Refer to sample screenshot attached)

    Previewing the JSON

    A preview of the JSON will be generated based on the parameters selected for the schedules. (Refer to sample screenshot attached)

    The IronPython Code

    import datetime, json, os
    
    # setting up variables
    start = Document.Properties["propStartTime"]
    end = "23:59:59"
    minutes_interval = Document.Properties["propInterval"]
    timeZone = Document.Properties["propTimeZone"]
    
    # Creating array for selected Days
    dayOfWeek = []
    selectedDays = Document.Properties['propDays']
    for days in selectedDays:
    	dayOfWeek.append(days)
    
    # Library location of Automation job
    jobFile = Document.Properties["propAutoJobLoc"]
    ruleType = 'asjob'
    
    # converting string time to datetime format
    start_time = datetime.datetime.strptime(start,'%H:%M:%S')
    end_time = datetime.datetime.strptime(end,'%H:%M:%S')
    delta = datetime.timedelta(minutes=minutes_interval)
    
    # preparing JSON data
    data = {}
    data['libraryItemPath'] = jobFile
    data['ruleType'] = ruleType
    data['schedules'] = []
    sch={}
    sTime = start_time
    while sTime <= end_time :
    	sch = {'startTime' : datetime.datetime.strftime(sTime,'%H:%M:%S'),'daysOfTheWeek': dayOfWeek,'timeZone': timeZone} 
    	data['schedules'].append(sch)
    	sTime += delta
    
    json_data = '[' + json.dumps(data, indent=2) + ']'
    varJson = json.loads(json_data)
    
    # saving json file to document property for preview
    Document.Properties["jsonString"] = json_data
    
    filePath = Document.Properties['propFilepath']
    
    # Create directory if it does not exist
    try:
    	if not os.path.exists(filePath):
    		os.makedirs(filePath)
    
    except Exception as e:
    	Document.Properties['propMessage'] = str(e)
    
    else:
    	# write schedules to json file
    	filePath = filePath + '\schedules.json'
    	with open(filePath, 'w') as outfile:
    		json.dump(varJson, outfile, indent=2)
    	Document.Properties['propMessage'] = 'File saved in : ' + filePath
     

    Uploading JSON to Spotfire Server

    Once the JSON file is generated successfully, follow the instructions below to import schedules.json file to Spotfire Server.

    • Start command prompt as "Administrator" on spotfire server.
    • CD into spotfire-bin folder. Default location:
     C:\tibco\tss\11.1.0\tomcat\spotfire-bin
     
    • Run "create-scheduled-jobs" command. Replace tool password value with your Spotfire server config tool password. Example:
     config create-scheduled-jobs --local-file-path=C:\Work\schedules.json --enabled=true --tool-password=value
     
    • Open Spotfire Admin Console with spotfire admin user and navigate to Automation Services.
    • Under the "Schedule Jobs" section, you will see a new schedule has been added with name "Imported rule 1".
    • Click on "Imported rule 1" and you will notice that all the schedules are populated.

    Reference

    https://docs.tibco.com/pub/spotfire_server/latest/doc/html/TIB_sfire_server_tsas_admin_help/server/topics/create-scheduled-jobs.html

    Attachments

    You can download attachments from resources.

    jsonpreview.thumb.png.2a548e9a6f219671e65f52af8d61eb8f.png


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...