예제 #1
0
        private JobStartInfo CreateJobStartInfo(IJobRun jobRun, JobRunContext jobContext)
        {
            var app       = jobContext.App;
            var startInfo = new JobStartInfo();
            var job       = jobRun.Job;

            startInfo.ThreadType    = job.ThreadType;
            startInfo.DeclaringType = ReflectionHelper.GetLoadedType(job.DeclaringType, throwIfNotFound: true); //it will throw if cannot find it
            var methName = job.MethodName;
            var argCount = job.MethodParameterCount;

            startInfo.Method = ReflectionHelper.FindMethod(startInfo.DeclaringType, job.MethodName, job.MethodParameterCount);
            // if Method is not static, it must be Module instance - this is a convention
            if (!startInfo.Method.IsStatic)
            {
                startInfo.Object = app.GetGlobalObject(startInfo.DeclaringType); //throws if not found.
            }
            //arguments
            var prms       = startInfo.Method.GetParameters();
            var serArgs    = job.Arguments;
            var arrStrArgs = serArgs.Split(new[] { JsonArgsDelimiter }, StringSplitOptions.None);

            Util.Check(prms.Length == arrStrArgs.Length, "Serialized arg count ({0}) in job entity " +
                       "does not match the number of target method parameters ({1}); target method: {2}.",
                       arrStrArgs.Length, prms.Length, startInfo.Method.Name);
            // Deserialize arguments
            startInfo.Arguments = new object[arrStrArgs.Length];
            for (int i = 0; i < arrStrArgs.Length; i++)
            {
                var paramType = prms[i].ParameterType;
                if (paramType == typeof(JobRunContext))
                {
                    startInfo.Arguments[i] = jobContext;
                }
                else
                {
                    startInfo.Arguments[i] = Deserialize(paramType, arrStrArgs[i]);
                }
            }
            return(startInfo);
        }
예제 #2
0
        private bool UnregisterJobRun(JobRunContext jobContext)
        {
            JobRunContext dummy;

            return(_runningJobs.TryRemove(jobContext.JobRunId, out dummy));
        }
예제 #3
0
 private bool RegisterJobRun(JobRunContext job)
 {
     return(_runningJobs.TryAdd(job.JobRunId, job));
 }