Loop the work items in the consumer robot

You decide to start by implementing a simple consumer that gets the work items produced by the producer robot but does not do anything with them yet.

You already have your task defined, now time to add some logic to it:

Small steps!

@task def consume_traffic_data(): """ Inhuman Insurance, Inc. Artificial Intelligence System robot. Consumes traffic data work items. """ process_traffic_data() def process_traffic_data(): for item in workitems.inputs: traffic_data = item.payload
  • You write a for loop to iterate through all the available work item inputs you got from the producer
  • You save the payload in a variable, traffic_data as you will surely need it in the very near future

This time you run the consumer task and select one of the outputs generated by the producer robot as an input for this consumer robot.

The log shows each work item payload:

traffic_data = {'traffic_data': {'country': 'VCT', 'year': 2011, 'rate': 3.69293}}

The sales system API expects only the data currently contained inside the traffic_data property. You get the relevant data out of the payload:

@task def consume_traffic_data(): """ Inhuman Insurance, Inc. Artificial Intelligence System robot. Consumes traffic data work items. """ process_traffic_data() def process_traffic_data(): for item in workitems.inputs: traffic_data = item.payload["traffic_data"]

Now you have the traffic data in a format that the sales system API should accept:

traffic_data = {'country': 'VCT', 'year': 2011, 'rate': 3.69293}