Skip to content

Update DefaultWorkflowState.php #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MuhammedAlkhudiry
Copy link

@MuhammedAlkhudiry MuhammedAlkhudiry commented Apr 10, 2025

I have an issue where a workflow is failing because many jobs are finishing at the same time (around 10 jobs), causing a deadlock exception.

This should fix it

@MuhammedAlkhudiry
Copy link
Author

Hello, @ksassnowski @stevebauman, Can you please merge this if it's ok?

Thank you for this package.

@MuhammedAlkhudiry
Copy link
Author

the fix fixes when there is like 10 jobs, but when I increased it to 50 jobs, there is this issue

PDOException 
/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php in PDO::beginTransaction
There is already an active transaction

I have tried

        retry(3, function() {
            DB::transaction(function () use ($job): void {
                /** @var Workflow $workflow */
                $workflow = $this->workflow
                    ->newQuery()
                    ->lockForUpdate()
                    ->findOrFail($this->workflow->getKey(), ['finished_jobs', 'jobs_processed']);

                $this->workflow->update([
                    'finished_jobs' => \array_merge(
                        $workflow->finished_jobs,
                        [$job->getJobId()],
                    ),
                    'jobs_processed' => $workflow->jobs_processed + 1,
                ]);

                $job->step()?->markAsFinished();
            }, 5);
        }, 250);

still having the same issue. I'm not sure what to do.

This is the workflow model (6 jobs are finished but not recorded)

 +"id": 48,
        +"name": "-----",
        +"job_count": 165,
        +"jobs_processed": 159,
        +"jobs_failed": 0,
        +"finished_jobs": "["parts_2", "parts_1", "parts_4", "parts_3", "parts_5", "parts_8", "parts_10", "parts_9", "parts_12", "parts_7", "parts_13", "parts_15", "parts_14", "parts_16", "parts_18", "parts_17", "parts_19", "parts_20", "parts_21", "parts_22", "parts_23", "parts_24", "parts_26", "parts_25", "parts_27", "parts_28", "parts_30", "parts_29", "parts_31", "parts_32", "parts_33", "parts_34", "parts_35", "parts_36", "parts_37", "parts_38", "parts_39", "parts_40", "parts_42", "parts_41", "parts_43", "parts_44", "parts_45", "parts_46", "parts_47", "parts_48", "parts_49", "parts_50", "parts_51", "parts_52", "parts_53", "parts_54", "parts_55", "parts_56", "parts_57", "parts_58", "parts_60", "parts_59", "parts_61", "parts_64", "parts_65", "parts_63", "parts_66", "parts_67", "parts_68", "parts_70", "parts_71", "parts_72", "parts_73", "parts_74", "parts_75", "parts_77", "parts_76", "parts_78", "parts_79", "parts_80", "parts_82", "parts_81", "parts_85", "parts_83", "parts_84", "parts_86", "parts_88", "parts_87", "parts_89", "parts_90", "parts_91", "parts_92", "parts_93", "parts_95", "parts_94", "parts_96", "parts_97", "parts_98", "parts_99", "parts_100", "parts_101", "parts_102", "parts_103", "parts_104", "parts_105", "parts_107", "parts_108", "parts_110", "parts_109", "parts_111", "parts_113", "parts_112", "parts_114", "parts_115", "parts_116", "parts_118", "parts_117", "parts_120", "parts_121", "parts_119", "parts_122", "parts_123", "parts_124", "parts_125", "parts_126", "parts_127", "parts_128", "parts_129", "parts_130", "parts_131", "parts_132", "parts_133", "parts_134", "parts_135", "parts_136", "parts_137", "parts_140", "parts_141", "parts_138", "parts_139", "parts_142", "parts_144", "parts_143", "parts_145", "parts_146", "parts_147", "parts_148", "parts_149", "parts_150", "parts_152", "parts_151", "parts_153", "parts_154", "parts_155", "parts_156", "parts_157", "parts_158", "parts_159", "parts_161", "parts_163", "parts_162", "parts_160", "parts_164"]",
        +"workflowable_type": null,
        +"workflowable_id": null,
        +"then_callback": null,
        +"finished_at": null,
        +"cancelled_at": null,
        +"catch_callback": null,
        +"created_at": "2025-04-13 12:08:37",
        +"updated_at": "2025-04-13 12:09:45",
      },

@MuhammedAlkhudiry
Copy link
Author

Kindly see the latest changes. Redis::funnel fixes it, but I'm unsure if depending on redis is the right way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant