If you dont mind you can use just a Curve.

**Shape**
- add Curve Circle, in edit mode Rotate 45, Duplicate and move 2.8 on X axis
- select all vertices switch handles to Free <kbd>V</kbd> and delete from both circles the center segment
- select end points and press <kbd>F</kbd> to connect

To get even distribution of colors you need even distribution of curve's control points (that is not right now), you can add another curve object, subdivide several times and deform this curve by previously shaped curve.
- Add some stickness to curve (tube) - go to *Properties editor > Object Data > Geometry >  Bevel >* **Depth**
- It is better to keep curve in type *Shape* *> 2D* and *Fill > None*
- Add Curve modifier (ensure origins both objects are at the same place)
- Moving along X axis will move along shape

**2.8x Material**
- Plug **UV** *Texture Coordinate* socket into *Separate XYZ* node  
and use X socket to lug into *ColorRamp*
- Enable under *Properties editor > Object Data > Texture Space >* **Use UV for mapping**. 

To see material switch to Rendered type view mode.

[![enter image description here][1]][1]

[![enter image description here][2]][2]

[<img src="https://blend-exchange.giantcowfilms.com/embedImage.png?bid=kW2Y3Lxs" />](https://blend-exchange.giantcowfilms.com/b/kW2Y3Lxs/)

**2.9x Material**  
is like [here][3], you don't have to worry about UV in curve properties, it is set by default.

---

Changing *X Location* will move gradient along curve.
[![enter image description here][4]][4]

Changing *X Scale* in Mapping node will change gradient scale.
[![enter image description here][5]][5]


  [1]: https://i.sstatic.net/6lVZj.png
  [2]: https://i.sstatic.net/Yk2dD.png
  [3]: https://blender.stackexchange.com/a/201466/2214
  [4]: https://i.sstatic.net/WZENC.gif
  [5]: https://i.sstatic.net/JXYeF.gif