3

I am working on an audio software that uses The EchoNest web service to identify and retrieve metadata about audio songs and I would like to have some advice on implementing a background processing chain.

(to get the full picture, I'll show you what I did already)

I've implemented the following chain that is mandatory before querying the service about a song's details:

enter image description here

Not much to say except that before being able to query song data, we need its fingerprint and a song ID returned by the Identify sub-process. Of all these steps, they all happen locally but the last one (Identify).

Now about the part of the system I'm seeking for advices:

enter image description here

Above are the different types of queries that can be requested for a song, they are not inter-dependent as we already have the only thing needed, the song ID (diagram 1). Note that I've only put a few but there are nearly 30 of them (see here).

Requirements/architecture:

  1. user can drop files at any time, they are queued for identification
  2. queries can run in parallel with step 1 and optionally concurrently

Ideally, the system should be:

  • easily extensible when for instance, I implement a new type of query.
  • easy to use, I just enqueue a query to the chain and wait for a response

Environment:

I am using C# with Dataflow (Task Parallel Library), currently I've had some good success implementing diagram 1 using this approach.

My question:

Is there a particular/well-known pattern to tackle this problem ?

aybe
  • 727
  • 6
  • 16
  • I read your post twice, and I don't see the "problem". As soon as you used the word "chain", and mentioned asynchronous processing, I assumed you had considered a finite state machine. Does that address the issue? – Frank Hileman Nov 04 '14 at 18:32
  • Well, now that you're saying this, it seems so obvious ! Feel free to post an answer and I'll accept it. – aybe Nov 04 '14 at 22:38

1 Answers1

3

Use a finite state machine for the "chain," where each step in the chain is a sub-state. For example, the states may be:

  • Start
  • Initial processing
  • Adding to collection
  • Fingerprinting
  • Querying
  • Ready

Finite state machines are good for coordinating asynchronous operations. I would also add tracing or logging to indicate when a state transition occurs.

Frank Hileman
  • 3,922
  • 16
  • 18