CrushMFT Documentation

Examples#

Worked jobs for the things jobs are most often asked to do. Each is given as its tasks in order, with the fields that matter. Fields that are not named keep what a new task has.

The first one was built and run on a test server; its log is shown. The others are recipes: build them, point the Find at a test folder, and step through them once with breakpoints.

1. Copy the day's reports#

Every evening, copy the spreadsheets of one folder to another.

Task Fields
Find "Find reports" Find URL file:///srv/files/Reports/ · Find Filter *.xlsx
Copy "Copy to Incoming" Destination file:///srv/files/Incoming/copies/{name}

Start → Find → Copy → End. Schedule: Daily, Run at 6:30 PM.

The run, as its log has it:

tasks.FindTask.Find:Found 7 in folder file:///srv/files/Reports/ of which 2 matched the filename patterns …
tasks.FindTask.Find:Waiting to check if items are changing:3
tasks.CopyTask.Copy:attempting copy (1) from:file://srv/files/Reports/q3-figures.xlsx
tasks.CopyTask.Copy:attempting copy (1) to:file:///srv/files/Incoming/copies/q3-figures.xlsx
tasks.CopyTask.Copy:Copy finished:file://srv/files/Reports/q3-figures.xlsx

Two things this small job teaches:

  • The destination ends in a name. {name} gives each copy the name of its file. A destination that ends at the folder is an error: "Destination path must have a file name or variable at the end".
  • The folder must exist. The first run failed with java.io.FileNotFoundException … (No such file or directory): the folder copies was not there, and a Copy does not make folders. Either make the folder once, or put a MakeDirectory with file:///srv/files/Incoming/copies/ before the Copy.

The Find waits 3 seconds and lists the folder a second time before it hands anything on, to leave out files that are still being written. That is Verify files are not changing, and it is on unless you turn it off.

2. Fetch from a partner every night#

Take the files a partner leaves on their SFTP server, file them by date, and remove them there.

Task Fields
Find "List partner outbox" Find URL sftp://acme@sftp.partner.example/outbox/ with the key or password · Find Filter *.csv
Copy "Fetch" Destination file:///data/partner/{yyyy}/{MM}/{dd}/{name} · Temp name while in transit {name}.part
Delete "Remove at partner" Item {url}
Email "Default Failure" To you · Subject {scheduleName} failed at {task_error_name} · Body {task_error}

Start → MakeDirectory file:///data/partner/{yyyy}/{MM}/{dd}/ → Find → Copy → Delete → End. The Email has no line into it: its name makes it the place every failure leads to.

  • The Copy hands on the originals, at the partner's address. That is why the Delete behind it removes the files at the partner and not the fresh copies. Leave After copying, add to list for future tasks unticked here: with it the copies would be in the list too, and the Delete would remove both. Check once with a breakpoint before the Delete which addresses it is given.
  • A Move does the Copy and the Delete in one task. Two tasks are used here so that the Delete only runs when the whole Copy worked.
  • The temporary name keeps a half-written file from being picked up by whatever watches the folder.
  • Give the job a Max runtime: a partner's server that accepts the login and then says nothing would hold the run for ever.

3. Decrypt what users upload#

Files that arrive PGP-encrypted are decrypted and put where the application reads them.

This job is started by an event of the user or group, action Run Plugin, with the job chosen from the list. It gets the uploaded files as its items, so it has no Find.

Task Fields
PGP "Decrypt" Folder Traversal Filter *.pgp · Method Decrypt · Private Public Key file the private key · Key password · Delete Original? ticked
Copy "To application" Destination file:///data/app/in/{name}

Files that are not .pgp pass the PGP task untouched, and the Copy takes them as they are.

For the event, choose a timing that waits until the upload session is over, so that one run gets all files of a batch.

4. Clean up old files#

Delete what is older than 90 days.

Task Fields
Find "Old files" Find URL file:///data/archive/ · Depth 20 · Last modified Older, Days 90 · Don't Add Folders ticked · Fail if no files are found unticked
Delete "Delete them" Item {url}

Start → Find → Delete → End. Schedule: Daily, at night.

  • Untick Fail if no files are found, or the job is "completed with errors" on every night with nothing to delete.
  • Try it first with an Email in place of the Delete, with Loop through items? unticked and {items_count} in the subject: it tells you how many files the job would remove.

5. Zip the month and mail it#

Task Fields
Find Find URL file:///data/reports/{!!!yyyy}-{!!!MM}/
Zip Zip Output Path file:///data/out/reports-{!!!yyyy}-{!!!MM}.zip
Email Folder Traversal Filter *.zip · To the recipients · Subject Reports for {!!!MMMM} {!!!yyyy} · Attach Files? ticked

Schedule: Monthly, Days of month 1. {!!!MM} is last month.

The Zip adds the zip file to the list, behind the reports. The Email's filter *.zip makes it attach the zip alone. Mail servers refuse large attachments: for more than a few megabytes, copy the zip to a folder the recipients can reach and mail the link.

6. One file to three places#

Every file goes to the archive, to a partner and to an application, and one mail reports at the end.

Task Fields
Find the incoming folder
Branch Dots 3 · Run the dots All at once
three Copy tasks, one per dot the three destinations
Wait / Joiner Join the branches ticked · Merge Union · When a joined branch failed Fail
Email {items_count} files delivered

Each Copy gets its own copy of the list, so a failure of one does not stop the others. The joiner waits for all three; without it the Email would be sent three times.

7. Call an API for every file#

Tell another system about each file that arrived.

Task Fields
HTTP URL https://api.example.com/v1/files · HTTP Method POST · Authentication as the service wants · header Content-Type: application/json · POST Data {"name":"{name}","size":{size}} · Expected Response Codes 200,201

The task makes one call per item. Import from cURL fills the form from the command in the service's documentation: see Snippets and the curl import.

To use what the service answers, tick Save response to file? and read the file in a later task.

8. Sort files by their kind#

Task Fields
Find the incoming folder
Jump "PDF?" {ext} Equals .pdf
Copy on the true line file:///data/pdf/{name}
Copy on the false line file:///data/other/{name}

The Jump sends the items that match down its true line and the rest down its false line. For more than two kinds, use a Branch with a filter per dot: *.pdf, *.csv, *.

9. Try again, three times#

A partner's server is often busy. Try three times, ten minutes apart, before giving up.

Task Fields
Loop Repeat A number of times · Times 3 · Pause between passes 10 Minutes · Also stop after a pass when the condition below is true: {fetched} Equals yes · When a pass fails Go on with the next pass
in its frame: Find → Copy → UserVariable as in example 2; the UserVariable at the end sets fetched to yes
Jump on the Loop's Done line {fetched} Equals yes; its false line leads to an Email "gave up after three tries"

A pass in which the Find or the Copy fails ends there, without reaching the UserVariable, and the loop goes on with the next pass after the pause. A pass that gets to the end sets the variable, and the loop stops.

Many tasks can do the simple case themselves: Copy has Retry failed copies x times and Retry delay, and Find has Keep checking for up to x minutes. Use the loop when several tasks have to be repeated together.

10. A list of what arrived#

Write one line per file into a log of your own.

Task Fields
WriteFile File Path file:///data/logs/arrivals-{yyyy}{MM}.txt · Loop through items? ticked · Append Only ticked · Contents {yyyy}-{MM}-{dd} {HH}:{mm} {name} {size}{r}{n}

Where to go from here#

For See
each task's fields the task pages, from Jobs
values such as {name} and {!!!MM} Variables, Functions
branches, joiners, loops How a job flows
what to do when it fails When a job fails