-
-
Notifications
You must be signed in to change notification settings - Fork 814
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/core#1304) Queues - Define schema for runner, run_count, lease_time, et al #22812
Conversation
…_time, retry_count, batch_limit, etc) (5.48)
(Standard links)
|
/** | ||
* Maximum number of items in a batch. Tip: If you expand batch_limit, then also consider expanding lease_time. | ||
* | ||
* @var int|string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outside the scope of this PR - but batch_limit is NOT int|string - it is int and " Note that values will be retrieved from the database as a string" is not true - this is coming from gencode from the looks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is confusing.
FWIW, I modeled the XML for this field after Event.xml
's max_participants
(which seemed analogous). The max_participants
has the same issue (ie it lists string
as a type even though it's really only for numeric data).
'title' => ts('Enable Autorun'), | ||
'description' => ts('Should the standard background attempt to autorun tasks in this queue?'), | ||
'where' => 'civicrm_queue.is_autorun', | ||
'runner' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's not required but it feels like we could have a callback to get the list of registered options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that too...
If sysadmins were using a GUI to define new queues, then it would be important to have that list. But I don't personally see the use-case for it right now. AFAICS, the use-cases are developer-driven ("Copy-paste 8-line snippet from dev-docs.")
The flip-side is that adding any pseudoconstant
for runner
would mean it becomes an affirmative obligation to register new values (otherwise validation will fail). So any custom runner requires 2x registrations. Compare: Registering a queue with custom runner. Should it require 1x records (Queue
) or 2x records (Queue
+OptionValue
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@totten yeah - it does mean it becomes harder to add later - but I am ok with leaving for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note I don't really see having to do 2 registrations as a downside
@totten most of my comments are superficial - but from my pre-r-run understanding of this PR the handling for the civicrm_queue table seems pretty consistent across definition/ upgrade but I'm not sure the queue_item table is..... |
OK - my show create on queue_item after upgrade - I'll do a fresh install & compare
|
fresh install
|
So the above looks right - it's just this bit I don't understand.... civicrm-core/sql/civicrm_queue_item.mysql Lines 11 to 33 in cf97aee
|
@eileenmcnaughton I removed the
|
3e536d1
to
af38636
Compare
OK - I think getting rid of that file is the right answer. I think when we do version removals it might be good to suggest the specific release when upgrading stopped working as "the LTS may be a good choice" is pretty meaningless now. It seems 4.7 is our lowest supported version |
991e266
to
f029797
Compare
Failures are unrelated. |
Overview
Expand the schema for
civicrm_queue
(et al). By configuring properties oncivicrm_queue
(et al), you can tell a generic queue-agent how to handle items from this queue.Each
civicrm_queue
(general metadata; matches$queueSpec
) may specifyrunner
,lease_time
,batch_limit
,retry_limit
,retry_interval
.Each
civicrm_queue_item
(data-storage forSql
/SqlParallel
queues) may track the number of execution attempts (run_count
). This facilitates implementation ofretry_limit
.This PR only defines the schema so that these options may be passed around. For fuller implementations (with test-coverage), see #22762.
ping @eileenmcnaughton @artfulrobot
Cross-Reference
Before
The
civicrm_queue
and$queueSpec
support the following option:bool $is_autorun
: Enable or disable automatic task-execution for this queue. This option was defined in the schema in a recent revision, but it has not been used in stable-public code. It has only been used by drafts+alphas.After
The
civicrm_queue
and$queueSpec
support several options:?string $runner
: Specify how the queue should execute tasks. This replaces the theis_autorun
flag. Some example values:null
(default/status quo): Do not automatically run tasks.is_autorun=FALSE
.)'task'
: The queue storesTask
records (egnew CRM_Queue_Task('my_callback', ['my_data'])
. This is the same as Civi's existing queue APIs. In effect, the generic queue-agent will runcall_user_func_array('my_callback', ['my_data'])
.is_autorun=TRUE
.)hook_civicrm_queueRun_{$runner}
to define how to evaluate queued tasks. (Pros+cons are later.)int $lease_time
(eg3600
sec): When a single worker looks to claim a new task, how long should the task be reserved to that worker? (If the lease expires without action by the worker, then it is assumed that the worker failed)int $batch_limit
(eg1
): When a single worker looks to claim new tasks, what is the highest number of tasks they may take??int retry_limit
(eg3
): If a task fails, it may be tried again later. What is the maximum number of times to retry??int retry_interval
(eg1200
sec): If a task fails, how long should you wait before trying to execute it again?Technical Details: General declarations
Following on recent work, there are a few ways to define a queue (eg
Civi::queue
orhook_managed
). Here are a few examples using the new options:Technical Details:
runner
declarationsThis PR only defines the schema elements. However, it may help to describe where the
runner
element is going.As with Civi's existing queue APIs, you may fill a queue with executable tasks. Set
runner=>task
to execute them automatically.This has some pros/cons. It has the benefit of consistency/precedent. You can enqueue many qualitatively different tasks (with different callbacks). It requires minimal boilerplate for each task. However, only trusted parties (ie local PHP code) may write to a task-queue. If you have 10 related items come into the queue at the same time, these will be executed separately (probably by different worker-threads).
Instead of using open-ended/executable tasks, you may alternatively define your own
runner=>mygreeting
.This variant supports batched-queuing (eg you can receive
batch_limit=>20
items at a time). It does not accept arbitrary callbacks -- queues which userunner=>foobar
may be amenable to accepting work from outside sources. However, batched-queuing requires more thoughtfulness about error-detection and error-handling.(For this PR, I don't want to dig too far into the implementation of different runners - that'll be another PR. I'm just trying to demonstrate the kind of choice is offered by the
runner
option.).There is no direct test-coverage for declaring the schema. However, the functionality in #22762 uses this schema and introduces test-coverage.