Utilizing a Workspace to Store Temporary Files

Looking for an example project to get you started?
1 post Page 1 of 1

Support_Rick

Support Specialist
Posts: 590
Joined: Tue Jul 17, 2012 2:12 pm
Location: Phoenix, AZ

Post by Support_Rick » Fri Apr 25, 2014 4:45 pm
Oftentimes you need a workspace to store temporary files for a job. For instance, you may need extract some information from a database and build CSV files for sending to a customer. After the CSV files are sent, you may want to easily remove these temporary CSV files from your system.

There are numerous reasons for using a temporary workspace, but it can be difficult to try to uniquely name and manage your own work folders on the system for this purpose. And most importantly, will you remember to clean up those work folders after the jobs are finished to minimize disk space usage?

GoAnywhere Director solves these challenges by allowing you to quickly create and delete temporary workspace folders using the following two tasks:

Create Workspace and Delete Workspace

The CreateWorkspace task will create a folder for storing files while executing a GoAnywhere job. Each workspace folder will be named with the job number and will be located under the GoAnywhere directory of /linoma/goanywhere/userdata/workspace/ by default.

The DeleteWorkspace task will remove the job’s workspace folder and all its contents.

Let’s say that you need to retrieve CSV files from a FTP Server. Once you get the files, you will need to insert the CSV contents into a database table and then delete the CSV files when done. In this instance, you will create the Workspace to store the temporary CSV files and then delete the Workspace at the end of the Project after the CSV files have been processed.

Let’s build a project that does just that!

First, let’s create the Workspace… (see figure 1)
Figure1.JPG
Figure1.JPG (41.52 KiB) Viewed 23652 times

Add the FTP|Get to retrieve the files needed … (See figure 2)
Figure2.JPG
Figure2.JPG (19.4 KiB) Viewed 23652 times
Since we want to put the file into the Workspace, the simple way to do this is to use the System Variable “${system.job.workspace}” which identifies the Workspace created in the first task above. Place this variable into the “Destination Directory” as seen in figure 3 below.

**NOTE**
Keep in mind that you must execute the “Create Workspace” task prior to using the ${system.job.workspace} variable in a task.
Figure3.JPG
Figure3.JPG (32.68 KiB) Viewed 23652 times
Finally, add your file processing for the files retrieved then follow this with the “Delete Workspace” task. Your completed project may look something similar to figure 4 below…
Figure4.JPG
Figure4.JPG (27.48 KiB) Viewed 23652 times
In the next scenario, we are going to pull information from a Database Table, create a CSV file and email it as an attachment.

Similar to the prior example, the project will create the Workspace first. We then pull the data from the Database Table and create a RowSet output Variable, as demonstrated in Figure 5.
Figure5.JPG
Figure5.JPG (32.19 KiB) Viewed 23652 times
Our next step is to create the CSV file from the SQL output. This is done by executing the Write CSV Task as in Figure 6.
Figure6.JPG
Figure6.JPG (29.96 KiB) Viewed 23652 times
The input Rowset Variable matches the output variable from the prior SQL Task.

Notice how the Output File name only has the csv file name specified without a path. Anytime you specify a file name without a path on a task, it will use the job Workspace folder to store or find that file.

Now, let’s add the Send Email task and send the file as an attachment (see figure 7).
Figure7.JPG
Figure7.JPG (38.5 KiB) Viewed 23652 times
The email attachment element must contain the name of the file to attach to the email. (See Figure 8)
Figure8.JPG
Figure8.JPG (24.85 KiB) Viewed 23652 times
Again, notice that the path is not included with the file name, which tells GoAnywhere to use the file from the job’s workspace.

Now, add the Delete Workspace Task and you are ready to run the project! (See figure 9)
Figure9.JPG
Figure9.JPG (27.48 KiB) Viewed 23652 times
Executing the project and reviewing the joblog shows you how the project created the Temporary Workspace folder, stores the CSV file into the workspace, and then deletes the workspace when done. (See Figure 10)
Figure10.JPG
Figure 10

We think you will find that workspaces have a lot of benefit by allowing you to have uniquely named temporary folders that don’t conflict with other jobs.

Please note that if your project aborts at any point during processing, the workspace is not automatically deleted. This allows you to go back and review your temporary files, if needed. However if you are storing sensitive files in the workspace, then you will want to make sure to delete the workspace folder.

Feel free to contact Linoma Software with any questions or to inquire about our On-Site Professional Services or Training Programs.
Rick Elliott
Lead Solutions Consultant
(402) 944.4242
(800) 949-4696
1 post Page 1 of 1