proxy.golang.org : github.com/DoNewsCode/core-queue
Package queue provides a deferrableDecorator queue implementation that supports reflectionJob retires and deferred dispatch. It is recommended to read documentation on the core package before getting started on the queue package. Queues in go is not as prominent as in some other languages, since go excels at handling concurrency. However, the deferrableDecorator queue can still offer some benefit missing from the native mechanism, say go channels. The queued reflectionJob won't be lost even if the system shutdown. In other words, it means jobs can be retried until success. Plus, it is also possible to queue the execution of a particular reflectionJob until a lengthy period of time. Useful when you need to implement "send email after 30 days" type of Job handler. First and foremost we should create a reflectionJob, waiting the queue to dispatch. A reflectionJob can be any struct that implements the Job interface. Although the object that implements the reflectionJob interface can be dispatched immediately, it only minimally describes the reflectionJob's property . We can tune the properties with the Adjust helper. For example, we want to run the reflectionJob after 3 minutes with maximum 5 retries: Like the Job package, you don't have to use this helper. Manually create a queueable Job by implementing this interface on top of the normal Job interface: The PersistentJob passed to the Decorate method contains the tunable configuration such as maximum retries. No matter how you create a persisted Job, to fire it, send it though a dispatcher. The normal dispatcher in the Jobs package won't work, as a queue implementation is required. Luckily, it is deadly simple to convert a standard dispatcher to a queue.JobDispatcher. As you can see, how the queue persist the Jobs is subject to the underlying driver. The default driver bundled in this package is the redis driver. Once the persisted Job are stored in the external storage, a goroutine should consume them and pipe the reconstructed Job to the listeners. This is done by calling the Consume method JobFrom queue.JobDispatcher Note if a Job is retryable, it is your responsibility to ensure the idempotency. Also, be aware if a persisted Job have many listeners, the Job is up to retry when any of the listeners fail. The queue package exports configuration in this format: While manually constructing the queue.JobDispatcher is absolutely feasible, users can use the bundled dependency provider without breaking a sweat. Using this approach, the life cycle of consumer goroutine will be managed automatically by the core. A module is also bundled, providing the queue command (for reloading and flushing). Sometimes there are valid reasons to use more than one queue. Each dispatcher however is bounded to only one queue. To use multiple queues, multiple dispatchers are required. Inject queue.DispatcherMaker to factory a dispatcher with a specific name. When an attempt to execute the Job handler failed, two kinds of special eventDispatcher-based Job will be fired. If the failed Job can be retried, "queue.RetryingJob" will be fired. If not, "queue.AbortedJob" will be fired. To gain visibility on how the length of the queue, inject a gauge into the core and alias it to queue.Gauge. The queue length of the all internal queues will be periodically reported to metrics collector (Presumably Prometheus).
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/%21do%21news%21code/core-queue
License: MIT
Latest release: over 3 years ago
First release: almost 4 years ago
Namespace: github.com/DoNewsCode
Stars: 1 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 4 days ago