Jobs in Enqueue state, most never run

Yea - I am lost. In the weeds.

If I follow the (very slim) example correctly: I create a service class that will execute the actual concrete object for me. However, the concrete job is decorated with which queue I want to send it to, the Service class is not. Therefore, every single job I queue up is done so in the DEFAULT queue only.

My approach:

interface IJob defines a single method ==> Execute(string payload)
interface IJobPayload defines a minimum set of properties (UserId, JobName, Id, JobType, Cron)

[Queue("critical")] class Job1 : IJob {...}
[Queue("doors")] class Job2 : IJob {...}
[Queue("doors")] class Job3 : IJob {...}
[Queue("lights")] class Job4 : IJob {...}
[Queue("lights")] class Job5 : IJob {...}
[Queue("adhoc")] class Job6 : IJob {...}
...
[Queue("critical")] class JobN : IJob {...}

All of these jobs are registered with Unity. Each concrete Job has a Payload sub class that inherits from IJobPayload and defines additional data for the job if needed. Now, I created a Service object that will be enqueued:

    public class JobService
    {
        private readonly IUnityContainer _container = UnityConfig.GetConfiguredContainer();

        public bool Execute(string payload)
        {
            var command = JsonConvert.DeserializeObject<PayloadStub>(payload);
            var job = _container.Resolve<IJob>(command.JobName);
            return job.Execute(payload);
        }

        // ReSharper disable once ClassNeverInstantiated.Local
        private class PayloadStub : IJobPayload
        {
            public string UserId { get; set; }
            public string JobName { get; set; }
            public string JobQueueName { get; set; }
            public int Id { get; set; }
            public JobType JobType { get; set; }
            public CronExpression Cron { get; set; }
        }
    }

Now, when a POST call comes to my ApiController I am doing this:

[HttpPost]
public string Post()
{
    var json = Request.Content.ReadAsStringAsync().Result;
    var queue = new QueueHandler();
    return queue.Load(json);
}

The controller calls the QueueHandler and Enqueues the job via the JobService object:

public class QueueHandler
{
    public string Load(string payload)
    {
        var command = JsonConvert.DeserializeObject<PayloadStub>(payload);
        string id;

        switch (command.JobType)
        {
            case JobType.AdHoc:
                id = BackgroundJob.Enqueue<JobService>(x => x.Execute(payload));
                break;
            ...
        }
        return id;
    }
}

Still getting the same results and have the added drawback of losing the target Queue.

How would you do this?

Through all of this, the only job that SUCCEEDS is the job setup the way you said don’t do this!

// Don't do this at home
var job = new Job();
BackgroundJob.Enqueue(() => job.Execute());