using Infrastructure;
using Newtonsoft.Json;
using Quartz;

namespace OpenAuth.App.ServiceApp;

public class FlyTaskJob : IJob
{
    private readonly ManageApp _manageApp;
    private readonly OpenJobApp _openJobApp;

    public FlyTaskJob(ManageApp manageApp, OpenJobApp openJobApp)
    {
        _manageApp = manageApp;
        _openJobApp = openJobApp;
    }

    public Task Execute(IJobExecutionContext context)
    {
        var jobId = context.MergedJobDataMap.GetString(Define.JOBMAPKEY);
        var job = _openJobApp.Get(jobId);
        if (job == null) return Task.CompletedTask;
        var param = JsonConvert.DeserializeObject<dynamic>(job.JobCallParams);
        var taskId = param.taskId;
        _manageApp.ExecuteFlyTask(taskId);
        return Task.CompletedTask;
    }
}