MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / dispatch

Method dispatch

chirpstack/src/applayer/fuota/flow.rs:44–103  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

42 }
43
44 async fn dispatch(&mut self) -> Result<()> {
45 let resp = match self.job.job {
46 FuotaJob::CreateMcGroup => self.create_mc_group().await,
47 FuotaJob::AddDevsToMcGroup => self.add_devices_to_multicast_group().await,
48 FuotaJob::AddGwsToMcGroup => self.add_gateways_to_multicast_group().await,
49 FuotaJob::McGroupSetup => self.multicast_group_setup().await,
50 FuotaJob::FragSessionSetup => self.fragmentation_session_setup().await,
51 FuotaJob::McSession => self.multicast_session_setup().await,
52 FuotaJob::Enqueue => self.enqueue().await,
53 FuotaJob::FragStatus => self.fragmentation_status().await,
54 FuotaJob::DeleteMcGroup => self.delete_mc_group().await,
55 FuotaJob::Complete => self.complete().await,
56 };
57
58 match resp {
59 Ok(Some((next_job, scheduler_run_after))) => {
60 if self.job.job == next_job {
61 // Re-run the same job in the future.
62 let mut job = self.job.clone();
63 job.scheduler_run_after = scheduler_run_after;
64 let _ = fuota::update_job(job).await?;
65 } else {
66 // Update the current job (to increment the attempt count).
67 let job = self.job.clone();
68 let _ = fuota::update_job(job).await?;
69
70 // Create the next job (which automatically sets the current job to completed).
71 let _ = fuota::create_job(fuota::FuotaDeploymentJob {
72 fuota_deployment_id: self.job.fuota_deployment_id,
73 job: next_job,
74 max_retry_count: match next_job {
75 FuotaJob::McGroupSetup
76 | FuotaJob::FragSessionSetup
77 | FuotaJob::McSession => self.fuota_deployment.unicast_max_retry_count,
78 _ => 0,
79 },
80 scheduler_run_after,
81 ..Default::default()
82 })
83 .await?;
84 }
85 }
86 Ok(None) => {
87 // No further jobs to execute, set the current job to completed.
88 let mut job = self.job.clone();
89 job.completed_at = Some(Utc::now());
90 let _ = fuota::update_job(job).await?;
91 }
92 Err(e) => {
93 // Re-run the same job in the future.
94 let mut job = self.job.clone();
95 job.scheduler_run_after = Utc::now() + self.scheduler_interval;
96 job.error_msg = format!("Error: {}", e);
97 let _ = fuota::update_job(job).await?;
98 return Err(e);
99 }
100 }
101

Callers 1

handle_jobMethod · 0.80

Calls 12

update_jobFunction · 0.85
create_jobFunction · 0.85
create_mc_groupMethod · 0.80
multicast_group_setupMethod · 0.80
fragmentation_statusMethod · 0.80
delete_mc_groupMethod · 0.80
completeMethod · 0.80
enqueueMethod · 0.45

Tested by

no test coverage detected