Comments (4)
I think we can achieve this by adding ctx
as the first parameter for method Run()
of Processor
.
Something like this
type Processor interface {
Run(ctx context.Context, j *Job) error
}
Is this what you mean? If yes, I can help with the issue
from goblero.
I thought maybe we could find a way to make ctx optional/ implicit, similarly to how its done in the http std library https://golang.org/pkg/net/http/#Request.Context ?
then make ctx a field on the Job,
ctx context.Context
any thoughts ?
from goblero.
I thought maybe we could find a way to make ctx optional/ implicit, similarly to how its done in the http std library https://golang.org/pkg/net/http/#Request.Context ? then make ctx a field on the Job, ctx context.Context
any thoughts ?
Sure, that works too. Probably it's better to provide another method to *Blero
to enqueue a job with Context, similar to how std lib provides http.NewRequest
and http.NewRequestWithContext
// uses a default context.Background()
func (bl *Blero) EnqueueJob(name string, data []byte) (uint64, error) {
jID, err := bl.queue.enqueueJob(context.Background(), name, data)
}
// use the provided context
func (bl *Blero) EnqueueJobWithContext(ctx context.Context, name string, data []byte) (uint64, error) {
jID, err := bl.queue.enqueueJob(ctx, name, data)
}
Job context can be used like this in dispatcher
func (d *dispatcher) runJob(q *queue, pID int, p Processor, j *Job) {
defer d.processorDone(pID)
select {
case <-j.ctx.Done():
err := q.markJobDone(j.ID, jobFailed)
if err != nil {
fmt.Printf("markJobDone -> %v jobFailed failed: %v\n", j.ID, err)
}
default:
// run the job
}
}
from goblero.
thanks @xamenyap for the input, I'm closing this issue for now, it does not seem to be a priority at the moment
from goblero.
Related Issues (11)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goblero.