GithubHelp home page GithubHelp logo

Add ctx to job processing about goblero HOT 4 CLOSED

didil avatar didil commented on August 11, 2024
Add ctx to job processing

from goblero.

Comments (4)

xamenyap avatar xamenyap commented on August 11, 2024

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.

didil avatar didil commented on August 11, 2024

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.

xamenyap avatar xamenyap commented on August 11, 2024

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.

didil avatar didil commented on August 11, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.