add github actions (#4)

* add github actions

* fix clippy

* skip check

* get rid of collect

* fix tests

* run ignored tests
This commit is contained in:
Ayrat Badykov 2021-07-11 13:17:02 +03:00 committed by GitHub
parent 4f50385c96
commit 12f6944e59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 159 additions and 32 deletions

View file

@ -8,3 +8,10 @@ updates:
time: "03:37" # UTC
commit-message:
prefix: "chore(cargo):"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "ci(actions):"

93
.github/workflows/rust.yml vendored Normal file
View file

@ -0,0 +1,93 @@
name: Test and Build Rust
on:
push:
pull_request:
schedule:
# Check if it works with current dependencies (weekly on Wednesday 2:32 UTC)
- cron: '32 2 * * 3'
jobs:
test:
name: Test
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
# Set health checks to wait until postgres has started
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
components: clippy
override: true
profile: minimal
toolchain: nightly
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --verbose --all-targets --all-features -- -D warnings
- name: Install diesel-cli
uses: actions-rs/cargo@v1
with:
command: install
args: diesel_cli --no-default-features --features "postgres"
- name: Setup db
run: diesel setup
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --all-features
- name: Run dirty tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --all-features --ignored
release:
name: Release x86_64-unknown-linux-gnu
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
override: true
profile: minimal
target: x86_64-unknown-linux-gnu
toolchain: nightly
- name: Build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release --verbose --all-features --target x86_64-unknown-linux-gnu

26
.github/workflows/style.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: Rust Code Formatting
on:
push:
pull_request:
jobs:
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: rustfmt
- name: Check format
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check --verbose

View file

@ -2,7 +2,7 @@
## Unreleased
- Simplify usage by re-exporting serde traits - [#3](https://github.com/ayrat555/fang/pull/2)
- Simplify usage by re-exporting serde traits - [#3](https://github.com/ayrat555/fang/pull/3)
## 0.3.0 (2021-07-04)

View file

@ -152,25 +152,19 @@ impl Executor {
Ok(task) => self.storage.finish_task(&task).unwrap(),
Err((task, error)) => self.storage.fail_task(&task, error).unwrap(),
};
()
}
RetentionMode::RemoveAll => {
match result {
Ok(task) => self.storage.remove_task(task.id).unwrap(),
Err((task, _error)) => self.storage.remove_task(task.id).unwrap(),
};
()
}
RetentionMode::RemoveFinished => match result {
Ok(task) => {
self.storage.remove_task(task.id).unwrap();
()
}
Err((task, error)) => {
self.storage.fail_task(&task, error).unwrap();
()
}
},
}
@ -395,10 +389,10 @@ mod executor_tests {
let found_task = executor.storage.find_task_by_id(task.id).unwrap();
assert_eq!(FangTaskState::Failed, found_task.state);
assert_eq!(
"panicked during task execution Any".to_string(),
found_task.error_message.unwrap()
);
assert!(found_task
.error_message
.unwrap()
.contains("panicked during task execution Any"));
Ok(())
});

View file

@ -1,3 +1,5 @@
#![allow(clippy::nonstandard_macro_braces)]
#[macro_use]
extern crate diesel;

View file

@ -32,6 +32,12 @@ pub struct Postgres {
pub connection: PgConnection,
}
impl Default for Postgres {
fn default() -> Self {
Self::new()
}
}
impl Postgres {
pub fn new() -> Self {
let connection = Self::pg_connection(None);
@ -155,7 +161,7 @@ impl Postgres {
.ok()
}
fn fetch_task_of_type(&self, task_type: &String) -> Option<Task> {
fn fetch_task_of_type(&self, task_type: &str) -> Option<Task> {
fang_tasks::table
.order(fang_tasks::created_at.asc())
.limit(1)

View file

@ -22,6 +22,12 @@ pub struct WorkerParams {
pub task_type: Option<String>,
}
impl Default for WorkerParams {
fn default() -> Self {
Self::new()
}
}
impl WorkerParams {
pub fn new() -> Self {
Self {
@ -67,7 +73,7 @@ impl WorkerPool {
.worker_params
.task_type
.clone()
.unwrap_or("".to_string());
.unwrap_or_else(|| "".to_string());
let name = format!("worker_{}{}", worker_type, idx);
WorkerThread::spawn_in_pool(self.worker_params.clone(), name, 0)
}
@ -200,26 +206,19 @@ mod job_pool_tests {
assert!(tasks.len() > 40);
let test_worker1_jobs: Vec<Task> = tasks
.clone()
.into_iter()
.filter(|job| {
serde_json::to_string(&job.metadata)
.unwrap()
.contains("worker_1")
})
.collect();
let test_worker1_jobs = tasks.clone().into_iter().filter(|job| {
serde_json::to_string(&job.metadata)
.unwrap()
.contains("worker_1")
});
let test_worker2_jobs: Vec<Task> = tasks
.into_iter()
.filter(|job| {
serde_json::to_string(&job.metadata)
.unwrap()
.contains("worker_2")
})
.collect();
let test_worker2_jobs = tasks.into_iter().filter(|job| {
serde_json::to_string(&job.metadata)
.unwrap()
.contains("worker_2")
});
assert!(test_worker1_jobs.len() > 20);
assert!(test_worker2_jobs.len() > 20);
assert!(test_worker1_jobs.count() > 20);
assert!(test_worker2_jobs.count() > 20);
}
}