Jump to content
  • Generating Schedules for Spotfire Automation Services Job


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

    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 customisable platform, it offers the capability to create custom schedules which can be uploaded directly to the 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

    generateautomationschedule.dxp

    scheduleparametersetup.png.9ed51f5d676caeb427e91960158ed306.png

    jsonpreview.thumb.png.2332f2cdf503c0b037a6ef29449606e1.png

    + Add Comment

    converted-file.png.cba3241756268e17ed65ea4fb27a1c45.png 434.65 KB
    converted-file.png.34f8108514e6bf889160142cb2ceb945.png 32.65 KB
    converted-file.png.04110b0b9359c02a4567e0a144cd9a73.png 55.15 KB

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...