Skip to content

Commit f345e8c

Browse files
committed
Supported the context versions client methods
1 parent 8ad642f commit f345e8c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

client/client.go

+89
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"context"
45
"fmt"
56
"net"
67
"net/http"
@@ -186,3 +187,91 @@ func (c *LmstfyClient) RespawnDeadLetter(queue string, limit, ttlSecond int64) (
186187
func (c *LmstfyClient) DeleteDeadLetter(queue string, limit int64) *APIError {
187188
return c.deleteDeadLetter(nil, queue, limit)
188189
}
190+
191+
// <---------------------------------- THE CONTEXT VERSIONS OF THE METHODS ARE BELOW ---------------------------------->
192+
193+
// PublishWithContext a context version of Publish
194+
func (c *LmstfyClient) PublishWithContext(ctx context.Context, queue string, data []byte, ttlSecond uint32, tries uint16,
195+
delaySecond uint32) (jobID string, err error) {
196+
return c.publish(nil, queue, "", data, ttlSecond, tries, delaySecond)
197+
}
198+
199+
// RePublishWithContext a context version of RePublish
200+
func (c *LmstfyClient) RePublishWithContext(ctx context.Context, job *Job, ttlSecond uint32, tries uint16,
201+
delaySecond uint32) (jobID string, err error) {
202+
return c.publish(ctx, job.Queue, job.ID, job.Data, ttlSecond, tries, delaySecond)
203+
}
204+
205+
// BatchPublishWithContext a context version of BatchPublish
206+
func (c *LmstfyClient) BatchPublishWithContext(ctx context.Context, queue string, jobDataSet []interface{},
207+
ttlSecond uint32, tries uint16, delaySecond uint32) (jobIDs []string, err error) {
208+
return c.batchPublish(ctx, queue, jobDataSet, ttlSecond, tries, delaySecond)
209+
}
210+
211+
// ConsumeWithContext a context version of Consume
212+
func (c *LmstfyClient) ConsumeWithContext(ctx context.Context, queue string, ttrSecond, timeoutSecond uint32) (*Job, error) {
213+
return c.consume(ctx, queue, ttrSecond, timeoutSecond, false)
214+
}
215+
216+
// ConsumeWithFreezeTriesWithContext a context version of ConsumeWithFreezeTries
217+
func (c *LmstfyClient) ConsumeWithFreezeTriesWithContext(ctx context.Context, queue string, ttrSecond, timeoutSecond uint32) (*Job, error) {
218+
return c.consume(ctx, queue, ttrSecond, timeoutSecond, true)
219+
}
220+
221+
// BatchConsumeWithContext a context version of BatchConsume
222+
func (c *LmstfyClient) BatchConsumeWithContext(ctx context.Context, queues []string, count, ttrSecond, timeoutSecond uint32) ([]*Job, error) {
223+
return c.batchConsume(ctx, queues, count, ttrSecond, timeoutSecond, false)
224+
}
225+
226+
// BatchConsumeWithFreezeTriesWithContext a context version of BatchConsumeWithFreezeTries
227+
func (c *LmstfyClient) BatchConsumeWithFreezeTriesWithContext(ctx context.Context, queues []string,
228+
count, ttrSecond, timeoutSecond uint32) ([]*Job, error) {
229+
return c.batchConsume(ctx, queues, count, ttrSecond, timeoutSecond, true)
230+
}
231+
232+
// ConsumeFromQueuesWithContext a context version of ConsumeFromQueues
233+
func (c *LmstfyClient) ConsumeFromQueuesWithContext(ctx context.Context, ttrSecond, timeoutSecond uint32,
234+
queues ...string) (*Job, error) {
235+
return c.consumeFromQueues(ctx, ttrSecond, timeoutSecond, false, queues...)
236+
}
237+
238+
// ConsumeFromQueuesWithFreezeTriesWithContext a context version of ConsumeFromQueuesWithFreezeTries
239+
func (c *LmstfyClient) ConsumeFromQueuesWithFreezeTriesWithContext(ctx context.Context, ttrSecond, timeoutSecond uint32,
240+
queues ...string) (*Job, error) {
241+
return c.consumeFromQueues(ctx, ttrSecond, timeoutSecond, true, queues...)
242+
}
243+
244+
// AckWithContext a context version of Ack
245+
func (c *LmstfyClient) AckWithContext(ctx context.Context, queue, jobID string) *APIError {
246+
return c.ack(ctx, queue, jobID)
247+
}
248+
249+
// QueueSizeWithContext a context version of QueueSize
250+
func (c *LmstfyClient) QueueSizeWithContext(ctx context.Context, queue string) (int, *APIError) {
251+
return c.queueSize(ctx, queue)
252+
}
253+
254+
// PeekQueueWithContext a context version of PeekQueue
255+
func (c *LmstfyClient) PeekQueueWithContext(ctx context.Context, queue string) (*Job, *APIError) {
256+
return c.peekQueue(ctx, queue)
257+
}
258+
259+
// PeekJobWithContext a context version of PeekJob
260+
func (c *LmstfyClient) PeekJobWithContext(ctx context.Context, queue, jobID string) (*Job, *APIError) {
261+
return c.peekJob(ctx, queue, jobID)
262+
}
263+
264+
// PeekDeadLetterWithContext a context version of PeekDeadLetter
265+
func (c *LmstfyClient) PeekDeadLetterWithContext(ctx context.Context, queue string) (int, string, *APIError) {
266+
return c.peekDeadLetter(ctx, queue)
267+
}
268+
269+
// RespawnDeadLetterWithContext a context version of RespawnDeadLetter
270+
func (c *LmstfyClient) RespawnDeadLetterWithContext(ctx context.Context, queue string, limit, ttlSecond int64) (int, *APIError) {
271+
return c.respawnDeadLetter(ctx, queue, limit, ttlSecond)
272+
}
273+
274+
// DeleteDeadLetterWithContext a context version of DeleteDeadLetter
275+
func (c *LmstfyClient) DeleteDeadLetterWithContext(ctx context.Context, queue string, limit int64) *APIError {
276+
return c.deleteDeadLetter(ctx, queue, limit)
277+
}

0 commit comments

Comments
 (0)