Pulls out all of the stream definitions from the database, and populates the channels with stream references

def update_channels(self):
        """
        Pulls out all of the stream definitions from the database, and populates the channels with stream references
        """
        logging.info("Updating channels")
        with switch_db(StreamDefinitionModel, 'hyperstream'):
            for s in StreamDefinitionModel.objects():
                try:
                    stream_id = StreamId(name=s.stream_id.name, meta_data=s.stream_id.meta_data)
                except AttributeError as e:
                    raise e
                logging.debug("Processing {}".format(stream_id))

                try:
                    # This can fail if a plugin has been defined by a different instantiation of HyperStream on the same
                    # database.
                    channel = self.get_channel(s.channel_id)
                except ChannelNotFoundError as e:
                    logging.warn(e)
                    continue

                # calculated_intervals = TimeIntervals(map(lambda x: (x.start, x.end), s.calculated_intervals))
                last_accessed = utcnow()
                last_updated = s.last_updated if s.last_updated else utcnow()

                if stream_id in channel.streams:
                    if isinstance(channel, (AssetsChannel, AssetsFileChannel)):
                        continue
                    raise StreamAlreadyExistsError(stream_id)

                from . import MemoryChannel, DatabaseChannel
                if isinstance(channel, MemoryChannel):
                    channel.create_stream(stream_id)
                elif isinstance(channel, DatabaseChannel):
                    if channel == self.assets:
                        stream_type = AssetStream
                    else:
                        stream_type = DatabaseStream

                    channel.streams[stream_id] = stream_type(
                        channel=channel,
                        stream_id=stream_id,
                        calculated_intervals=None,  # Not required since it's initialised from mongo_model in __init__
                        last_accessed=last_accessed,
                        last_updated=last_updated,
                        sandbox=s.sandbox,
                        mongo_model=s
                    )
                else:
                    logging.warn("Unable to parse stream {}".format(stream_id))