Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/scheduler/scheduler.cpp
Show First 20 Lines • Show All 1531 Lines • ▼ Show 20 Line(s) | 1350 | #endif | |||
---|---|---|---|---|---|
1532 | * We select the first job that has to be run, per schedule. | 1532 | * We select the first job that has to be run, per schedule. | ||
1533 | */ | 1533 | */ | ||
1534 | 1534 | | |||
1535 | // Sort again by schedule, sooner first, as some jobs may have shifted during the last step | 1535 | // Sort again by schedule, sooner first, as some jobs may have shifted during the last step | ||
1536 | qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::increasingStartupTimeOrder); | 1536 | qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::increasingStartupTimeOrder); | ||
1537 | 1537 | | |||
1538 | setCurrentJob(sortedJobs.first()); | 1538 | setCurrentJob(sortedJobs.first()); | ||
1539 | 1539 | | |||
1540 | int nextObservationTime = now.secsTo(currentJob->getStartupTime()); | | |||
1541 | | ||||
1542 | /* Check if job can be processed right now */ | 1540 | /* Check if job can be processed right now */ | ||
1543 | if (currentJob->getFileStartupCondition() == SchedulerJob::START_ASAP) | 1541 | if (currentJob->getFileStartupCondition() == SchedulerJob::START_ASAP) | ||
1544 | if( 0 < calculateJobScore(currentJob, now)) | 1542 | if( 0 < calculateJobScore(currentJob, now)) | ||
1545 | nextObservationTime = 0; | 1543 | currentJob->setStartupTime(now); | ||
1544 | | ||||
1545 | int const nextObservationTime = now.secsTo(currentJob->getStartupTime()); | ||||
1546 | 1546 | | |||
1547 | appendLogText(i18n("Job '%1' is selected for next observation with priority #%2 and score %3.", | 1547 | appendLogText(i18n("Job '%1' is selected for next observation with priority #%2 and score %3.", | ||
1548 | currentJob->getName(), currentJob->getPriority(), currentJob->getScore())); | 1548 | currentJob->getName(), currentJob->getPriority(), currentJob->getScore())); | ||
1549 | 1549 | | |||
1550 | // If mount was previously parked awaiting job activation, we unpark it. | 1550 | // If mount was previously parked awaiting job activation, we unpark it. | ||
1551 | if (parkWaitState == PARKWAIT_PARKED) | 1551 | if (parkWaitState == PARKWAIT_PARKED) | ||
1552 | { | 1552 | { | ||
1553 | parkWaitState = PARKWAIT_UNPARK; | 1553 | parkWaitState = PARKWAIT_UNPARK; | ||
▲ Show 20 Lines • Show All 581 Lines • ▼ Show 20 Line(s) | 2126 | { | |||
2135 | 2135 | | |||
2136 | setCurrentJob(job); | 2136 | setCurrentJob(job); | ||
2137 | 2137 | | |||
2138 | qCInfo(KSTARS_EKOS_SCHEDULER) << "Executing Job " << currentJob->getName(); | 2138 | qCInfo(KSTARS_EKOS_SCHEDULER) << "Executing Job " << currentJob->getName(); | ||
2139 | 2139 | | |||
2140 | KNotification::event(QLatin1String("EkosSchedulerJobStart"), | 2140 | KNotification::event(QLatin1String("EkosSchedulerJobStart"), | ||
2141 | i18n("Ekos job started (%1)", currentJob->getName())); | 2141 | i18n("Ekos job started (%1)", currentJob->getName())); | ||
2142 | 2142 | | |||
2143 | /* If job schedule allows it, start the job right now */ | ||||
2144 | if (KStarsData::Instance()->lt().secsTo(currentJob->getStartupTime()) <= 0) | ||||
2143 | currentJob->setState(SchedulerJob::JOB_BUSY); | 2145 | currentJob->setState(SchedulerJob::JOB_BUSY); | ||
2144 | 2146 | | |||
2145 | updatePreDawn(); | 2147 | updatePreDawn(); | ||
2146 | 2148 | | |||
2147 | // No need to continue evaluating jobs as we already have one. | 2149 | // No need to continue evaluating jobs as we already have one. | ||
2148 | 2150 | | |||
2149 | schedulerTimer.stop(); | 2151 | schedulerTimer.stop(); | ||
2150 | jobTimer.start(); | 2152 | jobTimer.start(); | ||
▲ Show 20 Lines • Show All 642 Lines • ▼ Show 20 Line(s) | 2706 | { | |||
2793 | } | 2795 | } | ||
2794 | } | 2796 | } | ||
2795 | 2797 | | |||
2796 | void Scheduler::checkJobStage() | 2798 | void Scheduler::checkJobStage() | ||
2797 | { | 2799 | { | ||
2798 | if (state == SCHEDULER_PAUSED) | 2800 | if (state == SCHEDULER_PAUSED) | ||
2799 | return; | 2801 | return; | ||
2800 | 2802 | | |||
2801 | Q_ASSERT(currentJob != nullptr); | 2803 | Q_ASSERT_X(currentJob, __FUNCTION__, "Actual current job is required to check job stage"); | ||
2804 | if (!currentJob) | ||||
2805 | return; | ||||
2806 | | ||||
2807 | QDateTime const now = KStarsData::Instance()->lt(); | ||||
2808 | | ||||
2809 | /* Refresh the score of the current job */ | ||||
2810 | /* currentJob->setScore(calculateJobScore(currentJob, now)); */ | ||||
2811 | | ||||
2812 | /* If current job is scheduled and has not started yet, wait */ | ||||
2813 | if (SchedulerJob::JOB_SCHEDULED == currentJob->getState()) | ||||
2814 | if (now < currentJob->getStartupTime()) | ||||
2815 | return; | ||||
2802 | 2816 | | |||
2803 | // #1 Check if we need to stop at some point | 2817 | // #1 Check if we need to stop at some point | ||
2804 | if (currentJob->getCompletionCondition() == SchedulerJob::FINISH_AT && | 2818 | if (currentJob->getCompletionCondition() == SchedulerJob::FINISH_AT && | ||
2805 | currentJob->getState() == SchedulerJob::JOB_BUSY) | 2819 | currentJob->getState() == SchedulerJob::JOB_BUSY) | ||
2806 | { | 2820 | { | ||
2807 | // If the job reached it COMPLETION time, we stop it. | 2821 | // If the job reached it COMPLETION time, we stop it. | ||
2808 | if (KStarsData::Instance()->lt().secsTo(currentJob->getCompletionTime()) <= 0) | 2822 | if (now.secsTo(currentJob->getCompletionTime()) <= 0) | ||
2809 | { | 2823 | { | ||
2810 | appendLogText(i18n("Job '%1' reached completion time %2, stopping.", currentJob->getName(), | 2824 | appendLogText(i18n("Job '%1' reached completion time %2, stopping.", currentJob->getName(), | ||
2811 | currentJob->getCompletionTime().toString(currentJob->getDateTimeDisplayFormat()))); | 2825 | currentJob->getCompletionTime().toString(currentJob->getDateTimeDisplayFormat()))); | ||
2812 | findNextJob(); | 2826 | findNextJob(); | ||
2813 | return; | 2827 | return; | ||
2814 | } | 2828 | } | ||
2815 | } | 2829 | } | ||
2816 | 2830 | | |||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 2869 | { | |||
2862 | stopGuiding(); | 2876 | stopGuiding(); | ||
2863 | findNextJob(); | 2877 | findNextJob(); | ||
2864 | return; | 2878 | return; | ||
2865 | } | 2879 | } | ||
2866 | } | 2880 | } | ||
2867 | } | 2881 | } | ||
2868 | 2882 | | |||
2869 | // #4 Check if we're not at dawn | 2883 | // #4 Check if we're not at dawn | ||
2870 | if (currentJob->getEnforceTwilight() && KStarsData::Instance()->lt() > KStarsDateTime(preDawnDateTime)) | 2884 | if (currentJob->getEnforceTwilight() && now > KStarsDateTime(preDawnDateTime)) | ||
2871 | { | 2885 | { | ||
2872 | // If either mount or dome are not parked, we shutdown if we approach dawn | 2886 | // If either mount or dome are not parked, we shutdown if we approach dawn | ||
2873 | if (isMountParked() == false || (parkDomeCheck->isEnabled() && isDomeParked() == false)) | 2887 | if (isMountParked() == false || (parkDomeCheck->isEnabled() && isDomeParked() == false)) | ||
2874 | { | 2888 | { | ||
2875 | // Minute is a DOUBLE value, do not use i18np | 2889 | // Minute is a DOUBLE value, do not use i18np | ||
2876 | appendLogText(i18n( | 2890 | appendLogText(i18n( | ||
2877 | "Job '%3' is now approaching astronomical twilight rise limit at %1 (%2 minutes safety margin), marking aborted.", | 2891 | "Job '%3' is now approaching astronomical twilight rise limit at %1 (%2 minutes safety margin), marking aborted.", | ||
2878 | preDawnDateTime.toString(), Options::preDawnTime(), currentJob->getName())); | 2892 | preDawnDateTime.toString(), Options::preDawnTime(), currentJob->getName())); | ||
▲ Show 20 Lines • Show All 1065 Lines • ▼ Show 20 Line(s) | 3956 | appendLogText(i18np("Job '%1' is complete after #%2 batch.", | |||
3944 | currentJob->getName(), currentJob->getRepeatsRequired())); | 3958 | currentJob->getName(), currentJob->getRepeatsRequired())); | ||
3945 | setCurrentJob(nullptr); | 3959 | setCurrentJob(nullptr); | ||
3946 | schedulerTimer.start(); | 3960 | schedulerTimer.start(); | ||
3947 | } | 3961 | } | ||
3948 | else | 3962 | else | ||
3949 | { | 3963 | { | ||
3950 | /* FIXME: raise priority to allow other jobs to schedule in-between */ | 3964 | /* FIXME: raise priority to allow other jobs to schedule in-between */ | ||
3951 | 3965 | | |||
3952 | currentJob->setState(SchedulerJob::JOB_BUSY); | | |||
3953 | | ||||
3954 | /* If we are guiding, continue capturing */ | 3966 | /* If we are guiding, continue capturing */ | ||
3955 | if (currentJob->getStepPipeline() & SchedulerJob::USE_GUIDE) | 3967 | if (currentJob->getStepPipeline() & SchedulerJob::USE_GUIDE) | ||
3956 | { | 3968 | { | ||
3957 | currentJob->setStage(SchedulerJob::STAGE_CAPTURING); | 3969 | currentJob->setStage(SchedulerJob::STAGE_CAPTURING); | ||
3958 | startCapture(); | 3970 | startCapture(); | ||
3959 | } | 3971 | } | ||
3960 | /* If we are using alignment, realign */ | 3972 | /* If we are using alignment, realign */ | ||
3961 | else if (currentJob->getStepPipeline() & SchedulerJob::USE_ALIGN) | 3973 | else if (currentJob->getStepPipeline() & SchedulerJob::USE_ALIGN) | ||
Show All 12 Lines | 3985 | appendLogText(i18np("Job '%1' is repeating, #%2 batch remaining.", | |||
3974 | "Job '%1' is repeating, #%2 batches remaining.", | 3986 | "Job '%1' is repeating, #%2 batches remaining.", | ||
3975 | currentJob->getName(), currentJob->getRepeatsRemaining())); | 3987 | currentJob->getName(), currentJob->getRepeatsRemaining())); | ||
3976 | /* currentJob remains the same */ | 3988 | /* currentJob remains the same */ | ||
3977 | jobTimer.start(); | 3989 | jobTimer.start(); | ||
3978 | } | 3990 | } | ||
3979 | } | 3991 | } | ||
3980 | else if (currentJob->getCompletionCondition() == SchedulerJob::FINISH_LOOP) | 3992 | else if (currentJob->getCompletionCondition() == SchedulerJob::FINISH_LOOP) | ||
3981 | { | 3993 | { | ||
3982 | currentJob->setState(SchedulerJob::JOB_BUSY); | | |||
3983 | currentJob->setStage(SchedulerJob::STAGE_CAPTURING); | 3994 | currentJob->setStage(SchedulerJob::STAGE_CAPTURING); | ||
3984 | captureBatch++; | 3995 | captureBatch++; | ||
3985 | startCapture(); | 3996 | startCapture(); | ||
3986 | 3997 | | |||
3987 | appendLogText(i18n("Job '%1' is repeating, looping indefinitely.", currentJob->getName())); | 3998 | appendLogText(i18n("Job '%1' is repeating, looping indefinitely.", currentJob->getName())); | ||
3988 | /* currentJob remains the same */ | 3999 | /* currentJob remains the same */ | ||
3989 | jobTimer.start(); | 4000 | jobTimer.start(); | ||
3990 | } | 4001 | } | ||
Show All 12 Lines | 4005 | { | |||
4003 | appendLogText(i18np("Job '%1' stopping, reached completion time with #%2 batch done.", | 4014 | appendLogText(i18np("Job '%1' stopping, reached completion time with #%2 batch done.", | ||
4004 | "Job '%1' stopping, reached completion time with #%2 batches done.", | 4015 | "Job '%1' stopping, reached completion time with #%2 batches done.", | ||
4005 | currentJob->getName(), captureBatch + 1)); | 4016 | currentJob->getName(), captureBatch + 1)); | ||
4006 | setCurrentJob(nullptr); | 4017 | setCurrentJob(nullptr); | ||
4007 | schedulerTimer.start(); | 4018 | schedulerTimer.start(); | ||
4008 | } | 4019 | } | ||
4009 | else | 4020 | else | ||
4010 | { | 4021 | { | ||
4011 | currentJob->setState(SchedulerJob::JOB_BUSY); | | |||
4012 | currentJob->setStage(SchedulerJob::STAGE_CAPTURING); | 4022 | currentJob->setStage(SchedulerJob::STAGE_CAPTURING); | ||
4013 | captureBatch++; | 4023 | captureBatch++; | ||
4014 | startCapture(); | 4024 | startCapture(); | ||
4015 | 4025 | | |||
4016 | appendLogText(i18np("Job '%1' completed #%2 batch before completion time, restarted.", | 4026 | appendLogText(i18np("Job '%1' completed #%2 batch before completion time, restarted.", | ||
4017 | "Job '%1' completed #%2 batches before completion time, restarted.", | 4027 | "Job '%1' completed #%2 batches before completion time, restarted.", | ||
4018 | currentJob->getName(), captureBatch)); | 4028 | currentJob->getName(), captureBatch)); | ||
4019 | /* currentJob remains the same */ | 4029 | /* currentJob remains the same */ | ||
▲ Show 20 Lines • Show All 1480 Lines • Show Last 20 Lines |