(Migrated) How to call SimpleIO/Plain Http service from scheduler?

(This message has been automatically imported from the retired mailing list)

I’ve set up a service that takes a request payload based on the SIO “Input
Required” tutorial example and it works great from curl or a browser url
rest-style call.

curl localhost:11223/splintertest -d ‘{“item_report”: “new”}’

{“response”: {“is_success”: true}}

However, when I try to call it from the scheduler, I’ve tried every format
can think of to put the request payload in the Extra Data section
(json/dict, str=str, quotes, one param on each line, etc) and it always
gives an error. It seems I’m just missing something simple or I just don’t
get it.

2015-04-29 00:06:00,776 - ERROR - 1286:Dummy-355 - zato.server.base:22 -
Could not handle brokeu’100004’, cid=u’K07HCSNRPN5139PTJSHH9Z16PAJJ’,
job_type=u’interval_based’, msg_type=u’0001’, n, payload=u’{u"item_report" :
u"new"}’, service=u’splintertest.my-splinter’)], e:[Traceback (t):

.

Exception: Caught an exception, param:item_report,
params_to_visit:('item_report',), has_si, e:Traceback (most recent call
last):

Any thoughts?

Thanks!

On 29/04/15 13:49, Alex Everitt wrote:

Exception: Caught an exception, param:item_report,
params_to_visit:('item_report',), has_si, e:Traceback (most recent
call last):

Any thoughts?

Hi Alex,

it won’t work that way - a service invoked from the scheduler will
receive its input under self.request.raw_request …

https://zato.io/docs/progguide/examples/scheduler.html#invoking-services-at-predefined-intervals

… i.e. the request won’t be parsed automatically.

You need an adapter such as here and it is the adapter that is plugged
into scheduler rather than the target service:

from zato.server.service import Service

class MyService(Service):
name = ‘hello1.my-service’

class SimpleIO:
    input_required = ('hello',)

def handle(self):
    self.logger.info(self.request.input.hello)

class Adapter(Service):
def handle(self):
self.invoke(‘hello1.my-service’, self.request.bunchified())

The automatic conversion according to a data format defined in a
scheduler’s job simply has not been implemented yet.