Skip to content

mping/intemporal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a28e4f2 · Feb 15, 2025

History

93 Commits
Nov 15, 2024
Nov 15, 2024
Feb 15, 2025
Oct 23, 2024
Feb 1, 2025
Nov 15, 2024
Feb 15, 2025
Mar 22, 2024
Nov 12, 2024
Feb 15, 2025
Feb 15, 2025
Dec 22, 2022
Feb 15, 2025
Feb 15, 2025
Nov 15, 2024
Apr 14, 2022
Nov 15, 2024
Dec 4, 2024
Nov 15, 2024
Nov 15, 2024
Nov 15, 2024
Feb 15, 2025
Feb 15, 2025
Nov 15, 2024

Repository files navigation

intemporal

Continuous Integration

(in)temporal - NOT temporal

A Clojure library in the spirit of temporal.io or uber cadence. Lets you define a function with side effects, and persist/resume the state of the function.

⚠️ use at your own peril, NOT production ready

Two concepts apply:

  • Activities: Either a protocol+impl, or a function. Handles side-effects
  • Workflows: Functions that orchestrate activities, and are resillient. If a process crashes, the workflow should be able to safely resume with at-least-once semantics

Usage

Examples:

Note that when the runtime is javascript, all activities will return a promise. Thus, the use of promesa.core/let and/or intemporal.macros/env-let is advised

(ns intemporal.demo-workflow
  (:require [intemporal.store :as store]
            [intemporal.workflow :as w]
            [intemporal.macros :refer [stub-function stub-protocol defn-workflow]]))

;;;;
;; demo

(defn nested-fn [a]
  [a :nested])

(defn activity-fn [a]
  (let [f (stub-function nested-fn)]
    (conj a :activity (f :sub))))

(defprotocol MyActivities
  (foo [this a]))

(defrecord MyActivitiesImpl []
  MyActivities
  (foo [this a] (println "record was called:" ) [a :child]))

(defn-workflow my-workflow [i]
  (let [sf (stub-function activity-fn)
        pr (stub-protocol MyActivities {})]
    (conj [:root]
          (sf [1])
          (foo pr :X))))

(def mstore (store/make-memstore))
(def worker (w/start-worker! mstore {`MyActivities (->MyActivitiesImpl)}))

;; note that in cljs, this returns a promise
(def res (w/with-env {:store mstore}
           (my-workflow 1)))

(defn pprint-table [table]
  (clojure.pprint/print-table table))

(defn print-tables []
  (let [tasks (store/list-tasks mstore)
        events (->> (store/list-events mstore)
                    (sort-by :id))]
    (pprint-table tasks)
    (pprint-table events)))

(print-tables)

TODO

  • Activites + Workflows
  • Pass stub options
    • Discard ActivityOptions
    • Protocol options
    • Regular fn options
  • Convert to .cljc
  • workers + queues
  • saga
  • retries
  • signals

About

temporal.io-like but on valium and cbd

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages