Skip to content

Commit

Permalink
Merge pull request #24 from overtone/arne/prep-release
Browse files Browse the repository at this point in the history
Prep release
  • Loading branch information
plexus authored Nov 26, 2023
2 parents e30dfa5 + c850401 commit cc6975b
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 55 deletions.
1 change: 1 addition & 0 deletions .VERSION_PREFIX
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.cake
pom.xml
*.jar
*.war
lib
Expand All @@ -13,3 +12,4 @@ pom.xml.asc
/.nrepl-port
.hgignore
.hg/
.cpcache
21 changes: 14 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# at-at Changelog
# Unreleased

## 1.1.0
_14th Jan 2013_

* Added new fn `interspaced` which will call fun repeatedly with a
specified interspacing.
* Added missing trailing quotes when printing schedule.
- Add exception handling through `uncaught-exception-handler`
- Make our thread pool threads recognizable by adding `at-at` to the thread name
- Add pprint handlers for records
- Add type hints to avoid reflection, and to be Babashka/GraalVM compatible
- Make `shutdown-pool!` public

## 1.2.0
_28th May 2013_

* BREAKING CHANGE - Remove support for specifying stop-delayed? and
stop-periodic? scheduler strategies.
* Jobs now correctly report as no longer being scheduled when pool is shutdown.

## 1.1.0
_14th Jan 2013_

* Added new fn `interspaced` which will call fun repeatedly with a
specified interspacing.
* Added missing trailing quotes when printing schedule.

File renamed without changes.
68 changes: 47 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,84 @@

### at-at

<!-- badges -->
[![cljdoc badge](https://cljdoc.org/badge/overtone/at-at)](https://cljdoc.org/d/overtone/at-at) [![Clojars Project](https://img.shields.io/clojars/v/overtone/at-at.svg)](https://clojars.org/overtone/at-at)
<!-- /badges -->

Simple ahead-of-time function scheduler. Allows you to schedule the execution of an anonymous function for a point in the future.

> This is a graalvm compatible fork of the original [`overtone/at-at`](https://github.com/overtone/at-at) repo.
<!-- installation -->
## Installation

To use the latest release, add the following to your `deps.edn` ([Clojure CLI](https://clojure.org/guides/deps_and_cli))

```
overtone/at-at {:mvn/version "0.0.0"}
```

or add the following to your `project.clj` ([Leiningen](https://leiningen.org/))

```
[overtone/at-at "0.0.0"]
```
<!-- /installation -->

### Basic Usage

First pull in the lib:

```clj
(use 'overtone.at-at)
(require '[overtone.at-at :as at])
```

`at-at` uses `ScheduledThreadPoolExecutor`s behind the scenes which use a thread pool to run the scheduled tasks. You therefore need create a pool before you can get going:

```clj
(def my-pool (mk-pool))
(def my-pool (at/mk-pool))
```

It is possible to pass in extra options `:cpu-count`, `:stop-delayed?` and `:stop-periodic?` to further configure your pool. See `mk-pool`'s docstring for further info.

Next, schedule the function of your dreams. Here we schedule the function to execute in 1000 ms from now (i.e. 1 second):

```clj
(at (+ 1000 (now)) #(println "hello from the past!") my-pool)
(at/at (+ 1000 (at/now)) #(println "hello from the past!") my-pool)
```

You may also specify a description for the scheduled task with the optional `:desc` key.

Another way of achieving the same result is to use `after` which takes a delaty time in ms from now:

```clj
(after 1000 #(println "hello from the past!") my-pool)
(at/after 1000 #(println "hello from the past!") my-pool)
```

You can also schedule functions to occur periodically. Here we schedule the function to execute every second:

```clj
(every 1000 #(println "I am cool!") my-pool)
(at/every 1000 #(println "I am cool!") my-pool)
```

This returns a scheduled-fn which may easily be stopped `stop`:

```clj
(stop *1)
(at/stop *1)
```

Or more forcefully killed with `kill`.

It's also possible to start a periodic repeating fn with an initial delay:

```clj
(every 1000 #(println "I am cool!") my-pool :initial-delay 2000)
(at/every 1000 #(println "I am cool!") my-pool :initial-delay 2000)
```

Finally, you can also schedule tasks for a fixed delay (vs a rate):

```clj
(interspaced 1000 #(println "I am cool!") my-pool)
(at/interspaced 1000 #(println "I am cool!") my-pool)
```

This means that it will wait 1000 ms after the task is completed before
Expand All @@ -97,42 +117,48 @@ starting the next one.
When necessary it's possible to stop and reset a given pool:

```clj
(stop-and-reset-pool! my-pool)
(at/stop-and-reset-pool! my-pool)
```

You may forcefully reset the pool using the `:kill` strategy:

```clj
(stop-and-reset-pool! my-pool :strategy :kill)
(at/stop-and-reset-pool! my-pool :strategy :kill)
```

### Viewing running scheduled tasks.

`at-at` keeps an eye on all the tasks you've scheduled. You can get a set of the current jobs (both scheduled and recurring) using `scheduled-jobs` and you can pretty-print a list of these job using `show-schedule`. The ids shown in the output of `show-schedule` are also accepted in `kill` and `stop`, provided you also specify the associated pool. See the `kill` and `stop` docstrings for more information.

```clj
(def tp (mk-pool))
(after 10000 #(println "hello") tp :desc "Hello printer")
(every 5000 #(println "I am still alive!") tp :desc "Alive task")
(show-schedule tp)
;; [6][RECUR] created: Thu 12:03:35s, period: 5000ms, desc: "Alive task
;; [5][SCHED] created: Thu 12:03:32s, starts at: Thu 12:03:42s, desc: "Hello printer
(def tp (at/mk-pool))
(at/after 10000 #(println "hello") tp :desc "Hello printer")
(at/every 5000 #(println "I am still alive!") tp :desc "Alive task")
(at/show-schedule tp)
;; [6][RECUR] created: Thu 12:03:35s, period: 5000ms, desc: "Alive task"
;; [5][SCHED] created: Thu 12:03:32s, starts at: Thu 12:03:42s, desc: "Hello printer"
```

### Install

Fetch at-at from github: https://github.com/overtone/at-at or pull from clojars: `[overtone/at-at "X.Y.Z"]`

### History

at-at was extracted from the awesome music making wonder that is Overtone (http://github.com/overtone/overtone)


### Authors

* Sam Aaron
* Jeff Rose
* Michael Neale
* Alexander Oloo
* Arne Brasseur
* Daniel MacDougall
* Josh Comer

(Ascii art borrowed from http://www.sanitarium.net/jokes/getjoke.cgi?132)

<!-- license -->
## License

Copyright &copy; 2011-2023 Sam Aaron, Jeff Rose, and contributors

Available under the terms of the Eclipse Public License 1.0, see LICENSE.txt
<!-- /license -->
4 changes: 4 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:deps
{lambdaisland/open-source {:git/url "https://github.com/lambdaisland/open-source"
:sha "b46bd6273c5c554f8374406a7482f6e0a6f1dd25"
#_#_:local/root "../open-source"}}}
17 changes: 17 additions & 0 deletions bin/proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bb

(ns proj (:require [lioss.main :as lioss]))

(lioss/main
{:license :epl
:group-id "overtone"
:gh-project "overtone/at-at"
:org-name "Overtone"
:org-url "https://overtone.github.io/"
:inception-year 2011
:description "Ahead-of-time function scheduler."})


;; Local Variables:
;; mode:clojure
;; End:
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
89 changes: 89 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>overtone</groupId>
<artifactId>at-at</artifactId>
<version>0.0.51</version>
<name>at-at</name>
<description>Ahead-of-time function scheduler.</description>
<url>https://github.com/lambdaisland/at-at</url>
<inceptionYear>2011</inceptionYear>
<organization>
<name>Lambda Island</name>
<url>https://lambdaisland.com</url>
</organization>
<properties>
<project class="build sourceEncoding">UTF-8</project>
</properties>
<licenses>
<license>
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>
<scm>
<url>https://github.com/lambdaisland/at-at</url>
<connection>scm:git:git://github.com/lambdaisland/at-at.git</connection>
<developerConnection>scm:git:ssh://git@github.com/lambdaisland/at-at.git</developerConnection>
<tag>797011be61c92d3e6578e6fcff49fd39eef11b64</tag>
</scm>
<dependencies></dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<git-revision>797011be61c92d3e6578e6fcff49fd39eef11b64</git-revision>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>clojars</id>
<url>https://repo.clojars.org/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>clojars</id>
<name>Clojars repository</name>
<url>https://clojars.org/repo</url>
</repository>
</distributionManagement>
</project>
3 changes: 0 additions & 3 deletions project.clj

This file was deleted.

24 changes: 24 additions & 0 deletions repl_sessions/walkthrough.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns at-at.walkthrough
(:require
[overtone.at-at :as at]))

(def my-pool (at-at/mk-pool))

(at/at (+ 1000 (at/now)) #(println "hello from the past!") my-pool)
(at/after 1000 #(println "hello from the past!") my-pool)

(at/every 1000 #(println "I am cool!") my-pool)
(at/every 1000 #(println "I am cool!") my-pool :initial-delay 2000)
(at/show-schedule my-pool)
(at/stop (first (at/scheduled-jobs my-pool)))

(at/interspaced 1000 #(println "I am cool!") my-pool)
(at/stop-and-reset-pool! my-pool)
(at/stop-and-reset-pool! my-pool :strategy :kill)

(def tp (at/mk-pool))
(at/after 10000 #(println "hello") tp :desc "Hello printer")
(at/every 5000 #(println "I am still alive!") tp :desc "Alive task")
(at/show-schedule tp)

(run! at/stop (at/scheduled-jobs tp))
Loading

0 comments on commit cc6975b

Please sign in to comment.