#[repr(C)]pub struct PicoContext {
pub plugin_name: FfiSafeStr,
pub service_name: FfiSafeStr,
pub plugin_version: FfiSafeStr,
/* private fields */
}
Expand description
Context of current instance. Produced by picodata.
Fields§
§plugin_name: FfiSafeStr
§service_name: FfiSafeStr
§plugin_version: FfiSafeStr
Implementations§
Source§impl PicoContext
impl PicoContext
pub fn new(is_master: bool) -> PicoContext
Sourcepub unsafe fn clone(&self) -> Self
pub unsafe fn clone(&self) -> Self
§Safety
Note: this is for internal use only. Plugin developers should never be copying pico context.
Sourcepub fn worker_manager(&self) -> ServiceWorkerManager
👎Deprecated: use register_job
, register_tagged_job
or cancel_background_jobs_by_tag
directly instead
pub fn worker_manager(&self) -> ServiceWorkerManager
register_job
, register_tagged_job
or cancel_background_jobs_by_tag
directly insteadReturn ServiceWorkerManager
for current service.
pub fn register_metrics_callback( &self, callback: impl Fn() -> String, ) -> Result<(), BoxError>
Sourcepub fn register_job<F>(&self, job: F) -> Result<(), BoxError>where
F: FnOnce(CancellationToken) + 'static,
pub fn register_job<F>(&self, job: F) -> Result<(), BoxError>where
F: FnOnce(CancellationToken) + 'static,
Add a new job to the execution. Job work life cycle will be tied to the service life cycle; this means that job will be canceled just before service is stopped.
§Arguments
job
: callback that will be executed in separated fiber. Note that it is your responsibility to organize job graceful shutdown, see abackground::CancellationToken
for details.
§Examples
use std::time::Duration;
use picodata_plugin::background::CancellationToken;
// this job will print "hello" every second,
// and print "bye" after being canceled
fn hello_printer(cancel: CancellationToken) {
while cancel.wait_timeout(Duration::from_secs(1)).is_err() {
println!("hello!");
}
println!("job cancelled, bye!")
}
context.register_job(hello_printer).unwrap();
Sourcepub fn register_tagged_job<F>(&self, job: F, tag: &str) -> Result<(), BoxError>where
F: FnOnce(CancellationToken) + 'static,
pub fn register_tagged_job<F>(&self, job: F, tag: &str) -> Result<(), BoxError>where
F: FnOnce(CancellationToken) + 'static,
Same as Self::register_job
but caller may provide a special tag.
This tag may be used for manual job cancellation using Self::cancel_tagged_jobs
.
§Arguments
job
: callback that will be executed in separated fibertag
: tag, that will be related to a job, single tag may be related to the multiple jobs
Sourcepub fn cancel_tagged_jobs(
&self,
tag: &str,
timeout: Duration,
) -> Result<(), BoxError>
pub fn cancel_tagged_jobs( &self, tag: &str, timeout: Duration, ) -> Result<(), BoxError>
Cancel all jobs related to the given tag
.
This function return after all related jobs will be gracefully shutdown or
after timeout
duration.
Returns error with code TarantoolErrorCode::Timeout
in case some
jobs didn’t finish within timeout
.
May also theoretically return error with code ErrorCode::NoSuchService
in case the service doesn’t exist anymore (highly unlikely).
See also Self::register_tagged_job
.
Sourcepub fn set_jobs_shutdown_timeout(&self, timeout: Duration)
pub fn set_jobs_shutdown_timeout(&self, timeout: Duration)
In case when jobs were canceled by picodata
use this function for determine
a shutdown timeout - time duration that picodata
uses to ensure that all
jobs gracefully end.
By default, 5-second timeout are used.
pub fn make_service_id(&self) -> ServiceId
pub fn plugin_name(&self) -> &str
pub fn service_name(&self) -> &str
pub fn plugin_version(&self) -> &str
Trait Implementations§
Source§impl Debug for PicoContext
impl Debug for PicoContext
Source§impl<'a> From<&'a PicoContext> for RouteBuilder<'a>
impl<'a> From<&'a PicoContext> for RouteBuilder<'a>
Source§fn from(context: &'a PicoContext) -> Self
fn from(context: &'a PicoContext) -> Self
Source§impl GetStaticEquivalent_ for PicoContext
impl GetStaticEquivalent_ for PicoContext
Source§type StaticEquivalent = _static_PicoContext
type StaticEquivalent = _static_PicoContext
'static
equivalent of Self
Source§impl StableAbi for PicoContext
impl StableAbi for PicoContext
Source§const LAYOUT: &'static TypeLayout
const LAYOUT: &'static TypeLayout
Source§type IsNonZeroType = False
type IsNonZeroType = False
Source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.Auto Trait Implementations§
impl Freeze for PicoContext
impl RefUnwindSafe for PicoContext
impl !Send for PicoContext
impl !Sync for PicoContext
impl Unpin for PicoContext
impl UnwindSafe for PicoContext
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more