Problem/Motivation

I just had a strange behavior because a continuous job thought that he was finished.

Proposed resolution

Ensure that continuous jobs can not be anything else than unprocessed.

Actually, thinking about it, maybe we just want to introduce two new job states continuous and continuous_inactive. Then we force those jobs to be in continuous unless explicitly set the the only other allowed state (continuous_inactive).

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

berdir’s picture

miro_dietiker’s picture

Removing recursive parent reference... Dunno what was the proper target intended.

mbovan’s picture

Assigned: Unassigned » mbovan
mbovan’s picture

Status: Active » Needs review
StatusFileSize
new10.01 KB
new3.88 KB

Added 2 new job states: Continuous and Continuous inactive.
Icons are from #2678332: Merge normal and continuous job overviews

Default state is "Continuous", while "Continuous inactive" is not in use yet. Should we automatically change to "Continuous inactive" when there are no entity types selected (for example)?

Also, do you happen now what steps I need to follow to change a continuous job to state "Finished"? Through user interface of course.

Screenshot:
Continuous

Status: Needs review » Needs work

The last submitted patch, 5: ignore_status_changes-2682771-5.patch, failed testing.

berdir’s picture

I'm not sure what I did. I might have accepted a job item.

so create a continuous job, create content, accept the translation for the job item. If it is the only one (or all are accepted), the job might currently switch to finished.

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new4.36 KB
new495 bytes

Yes, it appears to happen on "auto-accept" of job items where we change all jobs to finished. This patch should make it available only for non-continuous jobs.

Status: Needs review » Needs work

The last submitted patch, 8: ignore_status_changes-2682771-8.patch, failed testing.

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new6.38 KB
new2.29 KB

This should fix the tests.

Do we need continuous($message = NULL, $variables = array(), $type = 'status') and continuous_inactive($message = NULL, $variables = array(), $type = 'status') on JobInterface for now?

mbovan’s picture

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/JobInterface.php
    @@ -65,6 +65,20 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    +   * A continuous translation job.
    +   *
    +   * A default state for all continuous jobs.
    +   */
    +  const STATE_CONTINUOUS = 6;
    

    We should make sure that the open_jobs filter includes this state too.

  2. +++ b/tmgmt.module
    @@ -253,6 +253,7 @@ function tmgmt_job_match_item($source_language, $target_language, $account = NUL
       return !\Drupal::entityQuery('tmgmt_job_item')
         ->condition('tjid', $tjid)
    +    ->condition('tjid.entity.job_type', JobInterface::TYPE_NORMAL)
    

    I'm not sure that this does what you think it does. Now it will simply never find unfinished jobs for continuous jobs, which means it will always try to finish them? Wouldn't you have to check this in \Drupal\tmgmt\Entity\JobItem::accepted?

    My idea was to actually enforce this state in Job::preSave(). If continuous, and status is not continuous_inactive, force it to continuous.

    Also, I think we want an update function for this, or filters might not work correctly on this.

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new8.2 KB
new4.06 KB

Re #12.2:

Ha, didn't see ! at the beginning of the method. Moved to JobItem::accepted().

Put the code for changing the state in Job::preSave(). I added a check if original job is not already in continuous state as it could lead to an infinite loop.

Status: Needs review » Needs work

The last submitted patch, 13: ignore_status_changes-2682771-13.patch, failed testing.

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new8.33 KB
new1.45 KB

Directly setting the state to prevent double-saving. Double-save fix for job items too.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/JobItem.php
    @@ -481,8 +481,9 @@ class JobItem extends ContentEntityBase implements JobItemInterface {
    +    $job = $this->getJob();
    +    if (tmgmt_job_check_finished($this->getJobId()) && $job && !$job->isContinuous()) {
    +      // Mark the job as finished in case it is a normal job.
    

    Try reversing the conditions, if ($job && !$job->isContinuous() && ...check_finished()).

    Then you avoid a query for continuous jobs.

  2. +++ b/src/Plugin/views/filter/JobState.php
    @@ -40,6 +40,8 @@ class JobState extends ManyToOne {
           '2' => 'Rejected',
           '4' => 'Aborted',
           '5' => 'Finished',
    +      '6' => 'Continuous',
    +      '7' => 'Continuous inactive',
    

    looks like we forgot to make these labels translatable() in the previous issue?

    Lets not make inactive visible in the UI when it's not used anywhere yet. So just add continuous.

+++ b/tmgmt.install
@@ -97,6 +97,7 @@ function tmgmt_update_8007() {
-    $continuous_job->setState(Job::STATE_CONTINUOUS);
+    $continuous_job->state = Job::STATE_CONTINUOUS;
+    $continuous_job->save();

I actually liked setState() here because then it only saves if necessary.

mbovan’s picture

Status: Needs work » Needs review
StatusFileSize
new8.74 KB
new2.12 KB

Fixed the points above.

  • Berdir committed d3672cd on 8.x-1.x authored by mbovan
    Issue #2682771 by mbovan: Ignore status changes for continuous jobs
    
berdir’s picture

Status: Needs review » Fixed

Ok, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.