Skip to content

Commit

Permalink
Merge pull request #3 from yral-dapp/periodic-update-ml-feed
Browse files Browse the repository at this point in the history
Periodic update ml feed
  • Loading branch information
komal-sai-yral authored Dec 13, 2024
2 parents 82a08e1 + f9872bb commit 9853e76
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-workers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
worker: [yral-ml-feed-cache] # add more workers here
worker: [global-feed-cache-job] # add more workers here
defaults:
run:
working-directory: workers/${{ matrix.worker }}
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [ "workers/sample-worker", "workers/yral-ml-feed-cache","workers/yral-onchain-backend"]
members = [ "workers/global-feed-cache-job", "workers/sample-worker", "workers/yral-ml-feed-cache","workers/yral-onchain-backend"]

[workspace.dependencies]
worker = { version = "0.4.2" }
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"test": "npm run test --workspaces",
"dev:sample-worker": "cd workers/sample-worker && npm run dev",
"deploy:sample-worker": "cd workers/sample-worker && npm run deploy",
"dev:yral-ml-feed-cache": "cd workers/yral-ml-feed-cache && npm run dev"
"dev:yral-ml-feed-cache": "cd workers/yral-ml-feed-cache && npm run dev",
"dev:global-feed-cache-job": "cd workers/global-feed-cache-job && npm run dev"
},
"devDependencies": {
"wrangler": "^3.93.0"
Expand Down
23 changes: 23 additions & 0 deletions workers/global-feed-cache-job/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "global-feed-cache-job"
version = "0.1.0"
edition = "2021"

[package.metadata.wasm-pack.profile.release]
wasm-opt = false

[lib]
crate-type = ["cdylib"]

[dependencies]
worker.workspace = true
serde.workspace = true
serde_json.workspace = true
cfg-if = "0.1.2"
console_error_panic_hook.workspace = true


[profile.release]
lto = true
strip = true
codegen-units = 1
10 changes: 10 additions & 0 deletions workers/global-feed-cache-job/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "global-feed-cache-job",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "wrangler dev --local --test-scheduled",
"dev:remote": "wrangler dev --remote",
"deploy": "wrangler deploy"
}
}
26 changes: 26 additions & 0 deletions workers/global-feed-cache-job/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pub use console_error_panic_hook::set_once as set_panic_hook;
use worker::*;

#[event(scheduled)]
pub async fn scheduled_event(_event: ScheduledEvent, env: Env, _ctx: ScheduleContext) {
console_log!("Hello from a scheduled event!");
set_panic_hook();

// Create a new request
let req = Request::new(
"https://icp-off-chain-agent.fly.dev/update-global-ml-feed-cache",
Method::Get,
)
.unwrap();

// Make the HTTP request using Fetch API
match Fetch::Request(req).send().await {
Ok(resp) => {
// Log the response status
console_log!("Request completed with status: {}", resp.status_code());
}
Err(e) => {
console_error!("Request failed: {}", e);
}
}
}
16 changes: 16 additions & 0 deletions workers/global-feed-cache-job/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name = "global-feed-cache-job"
main = "build/worker/shim.mjs"
compatibility_date = "2024-01-01"

[build]
command = "cargo install -q worker-build && worker-build --release"

[vars]
ENVIRONMENT = "production"

[env.development]
vars = { ENVIRONMENT = "development" }


[triggers]
crons = ["0 * * * *"]

0 comments on commit 9853e76

Please sign in to comment.