This quick start guide assumes that you are using the out of the box DynamoDB implementation and that you are using dynamodb-local to run DynamoDB locally.
pfn
in sokka), which pretty
prints the value of key :s
in the task definition.Add sokka to your project.clj
:
[ai.verbo/sokka "0.1.0-alpha2"]
Add the necessary requires:
(ns user
(:require [verbo.sokka :as sokka]
[verbo.sokka.impl.dynamodb-task :as dyn]
[verbo.sokka.utils :as u]))
(dyn/create-table
{:cognitect-aws/client
{:endpoint-override
{:all
{:region "us-east-1"
:hostname "localhost"
:port 7000
:protocol :http}}}
:tasks-table "sokka-tasks"})
(defn foo
[task]
;; perform the task
(println
(format "%s\n%s\n%s"
(apply str (repeat 60 "="))
(:s (:data task))
(apply str (repeat 60 "="))))
;; return a valid response to ensure
;; the status of the task is updated
;; correctly.
;; to signal success:
;; (sokka/ok)
;; to signal task failure:
;; (sokka/failed {:error-message "error message"})
;; to temporarily pause the task for 10s:
;; (sokka/snoozed {:snooze-time 10000})
(sokka/ok))
(def foo-worker
(sokka/worker
{:taskq taskq
;; the topic to dequeue / reserve tasks from.
:topic "foo"
:pid "a1235" ;; the pid must be unique per worker
:lease-time-ms 2000
;; function to handle the task.
:pfn foo}))
;; to stop the worker, and wait for completion:
;; @(foo-worker)
(def task
(sokka/create-task! taskq
{:task-id (u/rand-id)
:task-description "say 'Hello Foo'"
:topic "foo"
:data {:s "Hello Foo"}}))
;; you will notice that Hello Foo is printed with a banner
;; in the REPL.
(sokka/task taskq (:task-id task))
;; list tasks since 1 day ago.
(u/scroll
(partial sokka/list-tasks taskq
{:from (-> 1 t/days t/ago tc/to-long)
:to (u/now)
:topic "foo"
:status :terminated
:sub-topic "default"})
{:limit 100})
For a list of all available functions to query tasks, see documentation for TaskStore.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close