Struct gitlab_runner::Runner
source · [−]pub struct Runner { /* private fields */ }
Expand description
Runner for gitlab
The runner is responsible for communicating with gitlab to request new job and spawn them.
Implementations
sourceimpl Runner
impl Runner
sourcepub fn new(server: Url, token: String, build_dir: PathBuf) -> Self
pub fn new(server: Url, token: String, build_dir: PathBuf) -> Self
Create a new Runner for the given server url and runner token, storing (temporary job files) in build_dir
The build_dir is used to store temporary files during a job run. This will also configure a
default tracing subscriber if that’s not wanted use Runner::new_with_layer
instead.
let dir = tempfile::tempdir().unwrap();
let runner = Runner::new(Url::parse("https://gitlab.com/").unwrap(),
"RunnerToken".to_string(),
dir.path().to_path_buf());
Panics
Panics if a default subscriber is already setup
sourcepub fn new_with_layer(
server: Url,
token: String,
build_dir: PathBuf
) -> (Self, GitlabLayer)
pub fn new_with_layer(
server: Url,
token: String,
build_dir: PathBuf
) -> (Self, GitlabLayer)
Creates a new runner as per Runner::new
and logging layer
The logging layer should attached to the current tracing subscriber while further runner calls are made otherwise job logging to gitlab will not work
let dir = tempfile::tempdir().unwrap();
let (runner, layer) = Runner::new_with_layer(Url::parse("https://gitlab.com/").unwrap(),
"RunnerToken".to_string(),
dir.path().to_path_buf());
let subscriber = Registry::default().with(layer).init();
sourcepub async fn request_job<F, J, Ret>(
&mut self,
process: F
) -> Result<bool, Error> where
F: FnOnce(Job) -> Ret + Sync + Send + 'static,
J: JobHandler + Send + 'static,
Ret: Future<Output = Result<J, ()>> + Send + 'static,
pub async fn request_job<F, J, Ret>(
&mut self,
process: F
) -> Result<bool, Error> where
F: FnOnce(Job) -> Ret + Sync + Send + 'static,
J: JobHandler + Send + 'static,
Ret: Future<Output = Result<J, ()>> + Send + 'static,
Try to request a single job from gitlab
This does a single poll of gitlab for a new job. If a new job received a new asynchronous
task is spawned for processing the job. The passed process
function is called to create a
the actual job handler. Returns whether or not a job was received or an error if polling
gitlab failed.
Note that this function is not cancel save. If the future gets cancelled gitlab might have provided a job for which processing didn’t start yet.
sourcepub async fn wait_for_space(&mut self, max: usize)
pub async fn wait_for_space(&mut self, max: usize)
Wait untill there are less then max jobs running
sourcepub async fn run<F, J, Ret>(
&mut self,
process: F,
maximum: usize
) -> Result<(), Error> where
F: Fn(Job) -> Ret + Sync + Send + 'static + Clone,
J: JobHandler + Send + 'static,
Ret: Future<Output = Result<J, ()>> + Send + 'static,
pub async fn run<F, J, Ret>(
&mut self,
process: F,
maximum: usize
) -> Result<(), Error> where
F: Fn(Job) -> Ret + Sync + Send + 'static + Clone,
J: JobHandler + Send + 'static,
Ret: Future<Output = Result<J, ()>> + Send + 'static,
Run continously, processing at most maximum
jobs concurrently
This essentially calls Runner::request_job
requesting jobs until at most maximum
jobs are
running in parallel.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Runner
impl Send for Runner
impl Sync for Runner
impl Unpin for Runner
impl !UnwindSafe for Runner
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more