Commit graph

34 commits

Author SHA1 Message Date
Rafael Caricio e1a8eeb7de
Use Queue type directly 2023-03-14 15:06:22 +01:00
Rafael Caricio aa1144e54f
Allow definition of custom error type 2023-03-13 17:46:59 +01:00
Rafael Caricio 64e2315999
Review Queue signature 2023-03-13 14:11:19 +01:00
Rafael Caricio c99486eaa6
Make TaskStore trait object safe 2023-03-13 13:08:54 +01:00
Rafael Caricio 716eeae4b1
Handle tasks that panic 2023-03-12 18:33:00 +01:00
Rafael Caricio 10e01390b8
Allow customization of the pulling interval per queue 2023-03-12 17:15:40 +01:00
Rafael Caricio 0f0a9c2238
Tasks are let run until completion 2023-03-12 15:52:13 +01:00
Rafael Caricio 2964dc2b88
Wait all workers to stop gracefully 2023-03-12 00:18:15 +01:00
Rafael Caricio 4895400d33
Update readme 2023-03-11 22:22:25 +01:00
Rafael Caricio 0fbc67052a
Don't generate default task unique hashes 2023-03-11 18:13:48 +01:00
Rafael Caricio 894f928c01
Support generic backend to store tasks 2023-03-11 17:49:23 +01:00
Rafael Caricio fd92b25190
Make queues configurable 2023-03-11 16:38:32 +01:00
Rafael Caricio aac0b44c7f
Make possible to provide app state to tasks 2023-03-10 23:41:34 +01:00
Rafael Caricio 61e566ed9f
Supports graceful shutdown 2023-03-09 16:59:45 +01:00
Rafael Caricio 6ed9513baf
Update readme with backie info 2023-03-07 17:52:26 +01:00
Rafael Caricio c1fcc87885
Revamp project using newtype and rework tasks table 2023-03-07 16:41:20 +01:00
Rafael Caricio 18303be796
Make workers go brrrr... 2023-03-04 20:46:09 +01:00
Rafael Caricio 0be173ef02
Support only async 2023-03-04 19:07:17 +01:00
Ayrat Badykov b1fbe8c5af
create sync mod 2022-07-17 09:10:32 +03:00
Ayrat Badykov a74d943896
fix shutdown test and add changelog entry 2021-12-05 08:43:17 +02:00
J 0473978460
Support graceful shutdown of worker (#14)
* Include shared state to allow graceful shutdown

Graceful shutdown of executors allows the current task to finish before
exiting. This prevents half completed tasks in the general case: when
workers are being scaled down.

To accomplish this a shared state (using an `Arc<RwLock<WorkerState>>`)
is created in a WorkerPool on instantiation. This shared state is then
passed to each thread (spawned with `WorkerThread::spawn_in_pool`), and
finally passed to the `Executor` instantiated by the `WorkerThread`.
This allows the infinit loop in the executor to receive signals from the
`WorkerPool`, and exit gracefully when requested.

* Add basic error handling

Add `FangError` enum derived from `thiserror::Error`. This should be the
default the error type for the Fang library, all errors returned by Fang
should be a value in this enum.

Use FangError for errors returned by start and shutdown, remove unwraps.

* Include instructions for running tests locally

* Track handles of panic'd worker threads

Allows the Drop trait impl of ThreadWorker to access the
`thread_join_handles` of WorkerPool so it can update the thread handle
when the previous thread unexpectedly exited and a new one is being
started. This is done in a way that prevents data leaks (by using a
Hashmap keyed off the name of the worker thread). It also ensures that
threads started from the Drop impl are properly joined on shutdown.

* Fix WorkerThread drop implementation

WorkerThread can not have `Clone` derived on it, as each cloned copy
will try to restart the thread when it's dropped, leading to an infinite
number of thread spawns till stack overflow. Oops

* Remove Option from SharedState type declaration

Instead of having an Option wrapping an enum, have the option codified
as a state in the enum.

* Bump version to 0.5.0

* Add integration test for shutdown

* Update simple_worker example to include signal monitoring and shutdown

* Update readme to mention using signal-hook to gracefully shutdown worker
2021-12-05 08:19:08 +02:00
Ayrat Badykov 4bf654c9b5
Do not use env logger, call log instead directly (#11)
* Do not use env logger, call log instead directly

* update example
2021-08-22 21:25:49 +03:00
Ayrat Badykov 93e7e57d9a
Add simple example (#9)
* Add simple example

* fix env_logger
2021-07-31 09:47:53 +03:00
Ayrat Badykov 824e32f17b
pass PgConnection into run function (#8)
* pass PgConnection into run function

Changes:

- rename Postgres into Queue
- pass PgConnection into run function

* remove all tasks of specific type

* add pgconnection

* pass connection to every queue function

* add connection pool

* reuse connection in test

* update readme
2021-07-25 15:20:16 +03:00
Ayrat Badykov 45eb336b8a
Periodic tasks (#5)
* Periodic tasks

* schedule next execution

* add scheduler

* ignore test

* fix clippy

* make start public

* check if the period task already exists

* do not insert task if it's already in the queue

* fix tests
2021-07-18 22:09:30 +03:00
Ayrat Badykov b9e05213d9
fix workflow 2021-07-11 13:44:28 +03:00
Ayrat Badykov 12f6944e59
add github actions (#4)
* add github actions

* fix clippy

* skip check

* get rid of collect

* fix tests

* run ignored tests
2021-07-11 13:17:02 +03:00
Ayrat Badykov 4f50385c96
simplify usage by re-exporting serde traits (#3)
* simplify usage by re-exporting serde traits

* improve readme formatting

* use typetag

* try different approach

* reexport through macro

* fix re-exporting

* add CHANGELOG entry

* use typetag::serde in README
2021-07-11 10:26:20 +03:00
Ayrat Badykov 0cb3b7301b
remove finished tasks (#2)
* execute different types of task in separate workers

* add more tests

* remove finished tasks

* add retention_mode

* make db url optional

* Add worker params

* Add CHANGELOG entry
2021-07-03 15:18:41 +03:00
Ayrat Badykov 4b1f537d19
execute different types of tasks in separate workers (#1)
* execute different types of task in separate workers

* add more tests

* pass reference

* add CHANGELOG
2021-07-03 07:23:05 +03:00
Ayrat Badykov 75a0de365e
make worker pool public 2021-06-24 08:23:02 +03:00
Ayrat Badykov e009747dd0
remove unused file 2021-06-23 14:32:21 +03:00
Ayrat Badykov b92af896d4
fix clippy warnings 2021-06-23 14:30:19 +03:00
Ayrat Badykov d293e31ac8
run tasks in threads 2021-06-23 13:48:03 +03:00