Skip to content
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

Dev - Fix job creation with full transaction for jobs and job_grades tables #1404

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

Mesrine67
Copy link
Contributor

This patch improves the job creation process by using a complete SQL transaction to ensure that insertions into both the jobs and job_grades tables are atomic. The use of INSERT IGNORE INTO jobs has been corrected to avoid inconsistencies in retrieving the job ID, and all insertion steps are now part of a transaction to ensure that the job and its grades are created reliably.

image

lib.callback.register('advanced_management:staff:creator', function(source, type, data)
    if type == 'job' then
        local name = data.name
        local label = data.label
        local grades = data.grades
        local success = ESX.CreateJob(name, label, grades)
        -- Wait(500)
        if not success then
            return false
        end
        local jobs = ESX.GetJobs()
        if jobs[name] then
            lib.notify(source, {title = 'Success', description = 'The job was successfully created.', type = 'success'})
            return true
        else
            lib.notify(source, {title = 'Error', description = 'Job creation failed.', type = 'error'})
            return false
        end
    end
    return false
end)

…bles

This patch improves the job creation process by using a complete SQL transaction to ensure that insertions into both the `jobs` and `job_grades` tables are atomic. The use of `INSERT IGNORE INTO jobs` has been corrected to avoid inconsistencies in retrieving the job ID, and all insertion steps are now part of a transaction to ensure that the job and its grades are created reliably.
@Gellipapa Gellipapa changed the base branch from main to dev September 27, 2024 08:18
Copy link
Contributor

@Gellipapa Gellipapa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for cleanup, and refactor this code block.

@Gellipapa Gellipapa merged commit 88b8774 into esx-framework:dev Sep 27, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants