public async Task ExecuteAsync(ProcessDocumentMessage processDocumentMessage)
        {
            Guard.ArgumentNotNull(processDocumentMessage, "processDocumentMessage");
            if (processDocumentMessage.DocumentMetadata == null)
            {
                throw new ArgumentException("The process document message should not have null metadata.");
            }

            Document document = await _documentStore.GetDocumentAsync(processDocumentMessage.DocumentMetadata.DocumentId, processDocumentMessage.DocumentMetadata.Id);

            if (document == null)
            {
                _eventSource.OnCompletedProcessDocumentJobDueToMissingDocument(processDocumentMessage);
                return;
            }

            IEnumerable <MovieReleasedEvent> movieReleasedEvents = _deserializer.Extract(document.Content);
        }
        public async Task <Page <T> > SearchMovieReleaseEventsAsync(string query, PageOffset pageOffset)
        {
            // check for a recent search
            DocumentId documentId = _externalDocumentClient.SearchMovies(query, pageOffset);
            IEnumerable <DocumentMetadata> documentMetadataList = await _documentStore.ListDocumentMetadataAsync(documentId, DateTimeOffset.UtcNow.Subtract(_documentCacheDuration));

            DocumentMetadata[] documentMetadataArray = documentMetadataList.ToArray();

            // get the document from the cache or from the external source
            Document document;

            if (documentMetadataArray.Any())
            {
                // get the latest document from the cache
                DocumentMetadata documentMetadata = documentMetadataArray.OrderByDescending(m => m.Created).First();
                document = await _documentStore.GetDocumentAsync(documentId, documentMetadata.Id);
            }
            else
            {
                // query Rotten Tomatoes API
                document = await _externalDocumentClient.GetDocumentAsync(documentId);

                // persist the document
                DocumentMetadata documentMetadata = await _documentStore.SaveDocumentAsync(document);

                // enqueue the process queue message if the document is new
                if (!documentMetadata.Duplicate)
                {
                    await _queue.AddMessageAsync(new ProcessDocumentMessage { DocumentMetadata = documentMetadata }, TimeSpan.Zero);
                }
            }

            // extract the events
            T[] entries = _eventExtractor.Extract(document.Content).ToArray();

            return(new Page <T>
            {
                Offset = pageOffset,
                Entries = entries,
                HasNextPage = entries.Length >= pageOffset.Size
            });
        }