It is often a pattern that I wish to poll a file for changes (when it was last written). When the file does change from its previous value, I wish to execute some function. Something of the form.
(poll-for-changes file-str on-change-fx current-value)
where
file-str
is just a string that specifies the files locationon-change-fx
is the function that should be called when the file at file-str
changes. Let us say that the on-change-fx
should take the File object pointing to file-str
as a argument.current-value
the current value of the file in milliseconds. You might set to 0 to guarantee that this function will run at least once, or to the actual value to only run this function when you actually detect a change.I would just like this function implemented in the clearest, most concise, Clojurist way possible. Thank you.
Team-linked applications using the Business API are able to poll for a variety of changes to the team - including changes to team content, membership, sharing, and more.
The following example provides a basic overview of how a polling trigger acquires new data. The flow runtime invokes an initial call on the trigger to the API in the connector. The connector will then call the backend service. The backend service then returns all of the current data back to the connector.
To implement this functionality, called file change notification, a program must be able to detect what is happening to the relevant directory on the file system. One way to do so is to poll the file system looking for changes, but this approach is inefficient.
As you build your Dropbox application, it’s important to remember that users may edit, move, and delete content at any time on Dropbox. As a result, your app may wish to poll for or be notified of these changes as they occur.
If you're looking to poll a directory or files and act on it, I think watchtower
is pretty good to look at.
Java 7 has a WatchService, which uses file system events to react to changes. In this case, you don't poll at all, but block on a future file event. I don't think there are any projects in Clojure that are out there leveraging that, although I spent some time toying with it to write a small library. The source for it is here
I don't claim my library is even complete, but it does use the Java 7 service, so you could use that for inspiration on your own project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With