z_pivot_rsc (zotonic_core v1.0.0-rc.17)
Pivoting server for the rsc table. Takes care of full text indices. Polls the pivot queue for any changed resources.
Summary
Functions
Convert process state when code is changed
Let a module define a custom pivot. The custom pivot table is created or changed to reflect the given columns. Per default an index is created for each column. Be careful when adding columns that are not nullable, if the table contains data then adding those columns will fail.
Handling all non call/cast messages
Initiates the server.
Insert a rsc_id in the pivot queue
Insert a rsc_id in the pivot queue for a certain date
Insert a slow running pivot task. For example syncing category numbers after an category update.
Insert a slow running pivot task. Use the UniqueKey to prevent double queued tasks for the same module:function.
Insert a slow running pivot task with unique key and arguments. The key is unique for the module:function.
Insert a slow running pivot task with unique key and arguments that should start after Seconds seconds. Always delete any existing transaction, to prevent race conditions when the task is running during this insert. The UniqueKey is used to have multiple entries per module/function. If only a single module/function should be queued, then set the UniqueKey to <<>>.
Lookup a custom pivot; give back the Id based on a column. Will always return the first Id found.
An immediate pivot request for a resource
Delay the next pivot, useful when performing big updates
Signal from pivot job that processing is done.
Ping from pivot process to keep alive and report progress
Return a modified property list with fields that need immediate pivoting on an update.
Poll the pivot queue for the database in the context
Rebuild the search index by queueing all resources for pivot.
Return the length of the pivot queue.
Return the number of pivot queue items scheduled for direct pivot.
Starts the server
Return the language used for stemming the full text index. We use a single stemming to prevent having seperate indexes per language.
Signal from task process that job is finished.
Ping from task process to keep alive and report progress
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
Types
-type task_delay() :: non_neg_integer() | calendar:datetime() | undefined.
-type task_return() :: ok | {delay, task_delay()} | {delay, task_delay(), NewArgs :: list()} | any().
Functions
Convert process state when code is changed
-spec define_custom_pivot(Module, Columns, Context) -> ok when Module :: atom(), Columns :: [Column], Column :: #column_def{name :: atom(), type :: string() | binary(), length :: non_neg_integer() | undefined, is_nullable :: boolean(), is_array :: boolean(), default :: term(), primary_key :: boolean(), unique :: boolean()} | {#column_def{name :: atom(), type :: string() | binary(), length :: non_neg_integer() | undefined, is_nullable :: boolean(), is_array :: boolean(), default :: term(), primary_key :: boolean(), unique :: boolean()}, Options} | {Colname, Colspec} | {Colname, Colspec, Options}, Colname :: string() | binary() | atom(), Colspec :: string() | binary(), Options :: [Option], Option :: noindex, Context :: z:context().
Let a module define a custom pivot. The custom pivot table is created or changed to reflect the given columns. Per default an index is created for each column. Be careful when adding columns that are not nullable, if the table contains data then adding those columns will fail.
-spec delete_task(module(), atom(), z:context()) -> non_neg_integer().
-spec delete_task(module(), atom(), task_key(), z:context()) -> non_neg_integer().
-spec delete_tasks(z:context()) -> non_neg_integer().
-spec get_pivot_title(m_rsc:resource_id(), z:context()) -> binary().
Handling all non call/cast messages
Initiates the server.
-spec insert_queue(IdOrIds, Context) -> ok when IdOrIds :: m_rsc:resource_id() | [m_rsc:resource_id()], Context :: z:context().
Insert a rsc_id in the pivot queue
-spec insert_queue(IdOrIds, DueDate, Context) -> ok when IdOrIds :: m_rsc:resource_id() | [m_rsc:resource_id()], DueDate :: calendar:datetime(), Context :: z:context().
Insert a rsc_id in the pivot queue for a certain date
-spec insert_task(Module, Function, Context) -> {ok, TaskId} | {error, term()} when Module :: atom(), Function :: atom(), Context :: z:context(), TaskId :: integer().
Insert a slow running pivot task. For example syncing category numbers after an category update.
-spec insert_task(Module, Function, UniqueKey, Context) -> {ok, TaskId} | {error, term()} when Module :: atom(), Function :: atom(), UniqueKey :: task_key(), Context :: z:context(), TaskId :: integer().
Insert a slow running pivot task. Use the UniqueKey to prevent double queued tasks for the same module:function.
-spec insert_task(Module, Function, UniqueKey, Args, Context) -> {ok, TaskId} | {error, term()} when Module :: atom(), Function :: atom(), UniqueKey :: task_key(), Args :: list() | fun((OldDue :: undefined | calendar:datetime(), OldArgs :: undefined | list(), NewDue :: calendar:datetime(), z:context()) -> {ok, {calendar:datetime(), list()}} | {error, term()}), Context :: z:context(), TaskId :: integer().
Insert a slow running pivot task with unique key and arguments. The key is unique for the module:function.
-spec insert_task_after(Delay, Module, Function, UniqueKey, Args, Context) -> {ok, TaskId} | {error, term()} when Delay :: task_delay(), Module :: atom(), Function :: atom(), UniqueKey :: task_key(), Args :: list() | fun((OldDue :: undefined | calendar:datetime(), OldArgs :: undefined | list(), NewDue :: calendar:datetime(), z:context()) -> {ok, {calendar:datetime(), list()}} | {error, term()}), Context :: z:context(), TaskId :: integer().
Insert a slow running pivot task with unique key and arguments that should start after Seconds seconds. Always delete any existing transaction, to prevent race conditions when the task is running during this insert. The UniqueKey is used to have multiple entries per module/function. If only a single module/function should be queued, then set the UniqueKey to <<>>.
Lookup a custom pivot; give back the Id based on a column. Will always return the first Id found.
-spec pivot(Id, Context) -> ok when Id :: m_rsc:resource_id(), Context :: z:context().
An immediate pivot request for a resource
-spec pivot_delay(z:context()) -> ok.
Delay the next pivot, useful when performing big updates
-spec pivot_job_done(IdsOrError, Context) -> ok when IdsOrError :: [m_rsc:resource_id()] | error, Context :: z:context().
Signal from pivot job that processing is done.
-spec pivot_job_ping(m_rsc:resource_id(), z:context()) -> ok.
Ping from pivot process to keep alive and report progress
-spec pivot_resource_update(Id, UpdateProps, RawProps, Context) -> UpdateProps1 when Id :: m_rsc:resource_id(), UpdateProps :: m_rsc:props(), RawProps :: m_rsc:props(), Context :: z:context(), UpdateProps1 :: m_rsc:props().
Return a modified property list with fields that need immediate pivoting on an update.
-spec poll(z:context()) -> ok.
Poll the pivot queue for the database in the context
-spec queue_all(Context) -> ok when Context :: z:context().
Rebuild the search index by queueing all resources for pivot.
-spec queue_count(Context) -> QueueLength when Context :: z:context(), QueueLength :: non_neg_integer().
Return the length of the pivot queue.
-spec queue_count_backlog(Context) -> BacklogLength when Context :: z:context(), BacklogLength :: non_neg_integer().
Return the number of pivot queue items scheduled for direct pivot.
Starts the server
Return the language used for stemming the full text index. We use a single stemming to prevent having seperate indexes per language.
Signal from task process that job is finished.
Ping from task process to keep alive and report progress
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.