Exemple #1
0
func (h *HttpTransport) RemoteJobFor(locator transport.Locator, j interface{}) (job jobs.Job, err error) {
	baseUrl, errl := urlForLocator(locator)
	if errl != nil {
		err = errors.New("The provided host is not valid '" + locator.String() + "': " + errl.Error())
		return
	}
	httpJob, errh := HttpJobFor(j)
	if errh == jobs.ErrNoJobForRequest {
		err = transport.ErrNotTransportable
		return
	}
	if errh != nil {
		err = errh
		return
	}
	if serverAware, ok := httpJob.(ServerAware); ok {
		serverAware.SetServer(baseUrl.Host)
	}

	job = jobs.JobFunction(func(res jobs.Response) {
		if err := h.ExecuteRemote(baseUrl, httpJob, res); err != nil {
			res.Failure(err)
		}
	})
	return
}
Exemple #2
0
func (t *testTransport) RemoteJobFor(locator transport.Locator, job jobs.Job) (jobs.Job, error) {
	if t.Translated == nil {
		t.Translated = make(map[string]jobs.Job)
		t.Invoked = make(map[string]jobs.Response)
	}
	t.Translated[locator.String()] = job
	invoked := func(res jobs.Response) {
		if _, found := t.Invoked[locator.String()]; found {
			panic(fmt.Sprintf("Same job %+v invoked twice under %s", job, locator.String()))
		}
		t.Invoked[locator.String()] = res
		res.Success(jobs.ResponseOk)
	}
	return jobs.JobFunction(invoked), nil
}
Exemple #3
0
func (h *HttpTransport) RemoteJobFor(locator transport.Locator, j jobs.Job) (job jobs.Job, err error) {
	if locator == transport.Local {
		job = j
		return
	}
	baseUrl, errl := urlForLocator(locator)
	if errl != nil {
		err = errors.New("The provided host is not valid '" + locator.String() + "': " + errl.Error())
		return
	}
	httpJob, errh := HttpJobFor(j)
	if errh != nil {
		err = errh
		return
	}

	job = jobs.JobFunction(func(res jobs.Response) {
		if err := h.ExecuteRemote(baseUrl, httpJob, res); err != nil {
			res.Failure(err)
		}
	})
	return
}