How to find if is there job queue already there for current record if not then only add new job queue

Dear ALL,

How to find if is there job queue already there for current record if not then only add new job queue, as many entries are created every time record saves.

Means before adding new job queue I want to check if it's already there and running.

I am following below link:

support.sugarcrm.com/.../

Thanks,

Shreya 

Parents
  • You could query the job_queue table. Basing it on the example you linked, it would be something like:

    select status from job_queue 
    where 
    name = "Account Alert Job - {$bean->id}"
    and resolution = 'queued'

    Note that I changed the name to use the record id instead of the name, it's more precise.

    So when you define the job:

    $job->name = "Account Alert Job - {$bean->id}";

    You may find the status is "running" which means the scheduler has already kicked off but is not completed, that may require you to re-run, depending on your scenario. If the status and resolution are both "queued" then it is queued but has not started running yet.

    For reference, the table structure for job_queue looks like:

    Field Type Null Key Default Extra
    assigned_user_id char(36) YES MUL NULL
    id char(36) NO PRI NULL
    name varchar(255) YES NULL
    deleted tinyint(1) YES 0
    date_entered datetime YES NULL
    date_modified datetime YES NULL
    scheduler_id char(36) YES NULL
    execute_time datetime YES NULL
    status varchar(20) YES MUL NULL
    resolution varchar(20) YES MUL NULL
    message text YES NULL
    target varchar(255) YES MUL NULL
    data longtext YES NULL
    requeue tinyint(1) YES 0
    retry_count tinyint YES NULL
    failure_count tinyint YES NULL
    job_delay int YES NULL
    client varchar(255) YES NULL
    percent_complete int YES NULL
    job_group varchar(255) YES MUL NULL
    module varchar(255) YES NULL
    fallible tinyint(1) YES 0
    rerun tinyint(1) YES 0
    interface tinyint(1) YES 0

    FrancescaS

  • Appreciated FrancescaS, the suggested solution working for me thanks..

    Thanks,

    Shreya

  • That's great, glad it helped.

    If you mark the answer as correct on the club then others can see that the question has been answered correctly when searching for similar issues. :)

Reply Children
No Data